Sorry to chime in so late in the discussion.
What about a syntax similar to this?
int main()
{
auto s = join("Hello ", ", World.", " The hex for ", 58, " is ",
std::hex, 58);
std::cout << s << std::endl;
s = join(separator(" : "), "a", "b", std::hex, 200 , std::quoted("banana"));
std::cout << s << std::endl;
}
Which would produce the following output:
Hello , World. The hex for 58 is 3a
a : b : c8 : “banana"
sample implementation (io manipulators may be incomplete, some efficiency
gains could be mad):
#include <sstream>
#include <iostream>
#include <iomanip>
namespace detail {
template<class SepStr>
struct separator_object
{
template<class T>
std::ostream& operator ()(std::ostream& s, T&& t) const
{
return s << sep << t;
}
//
// other iomanp specialisations here
//
std::ostream& operator ()(std::ostream& s,
std::ios_base&(*t)(std::ios_base&)) const
{
t(s);
return s;
}
SepStr const& sep;
};
struct no_separator_object
{
template<class T>
std::ostream& operator ()(std::ostream& s, T&& t) const
{
return s << t;
}
};
template