I know how to do this in other languages, but not C++, which I am forced to use here.
I have a Set of Strings that I\'m printing to out in a list, and they need a co
If the values are std::string
s you can write this nicely in a declarative style with range-v3
#include
#include
#include
#include
int main()
{
using namespace ranges;
std::vector const vv = { "a","b","c" };
auto joined = vv | view::join(',');
std::cout << to_(joined) << std::endl;
}
For other types which have to be converted to string you can just add a transformation calling to_string
.
#include
#include
#include
#include
int main()
{
using namespace ranges;
std::vector const vv = { 1,2,3 };
auto joined = vv | view::transform([](int x) {return std::to_string(x);})
| view::join(',');
std::cout << to_(joined) << std::endl;
}