I'd like to create std::string that contains first elements of std::map<std::string, std::string> separate by some delimiter (it can be from STL or Boost).
Is there any better solution (one line) than loop? Like boost::algorithm::join for std::vector<std::string>.
This can be done elegantly using Boost.Range's map_keys and Boost.StringAlgo's join:
std::string get_keys(const std::map<std::string, std::string>& map) {
return boost::algorithm::join(
map | boost::adaptors::map_keys,
", ");
}
http://www.boost.org/doc/libs/1_61_0/boost/algorithm/string/join.hpp
http://www.boost.org/doc/libs/1_61_0/libs/range/doc/html/range/reference/adaptors/reference/map_keys.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With