This is a possible solution that exactly matches the query using the result of std :: string:
template <char ... chs> struct MyStruct { static string stringify() { return stringify(chs...); } template <typename ... cst> static string stringify() { return string(); } template <typename T, typename ... cst> static string stringify(T c, cst... cs) { return string() + c + stringify<cst...>(cs...); } }; template <typename ch1, typename ch2> struct Together { static string result() {return ch1::stringify() + ch2::stringify();} }; int main() { cout << Together<MyStruct<'a','b'>, MyStruct<'c','d'>>::result() << '\n'; return 0; }
Of course, it will work with more or less template parameters, for example:
Together<MyStruct<'a','b','c','d'>, MyStruct<'e','f','g'>>::result()
source share