Compilation "string" compilation:
#include <iostream> #include <string> template <char ... CTail> struct MetaString { static std::string string() { return std::string{CTail...}; } }; template <class L, class R> struct Concatenate; template <char ... LC, char ... RC> struct Concatenate<MetaString<LC ... >, MetaString<RC ... >> { typedef MetaString<LC ..., RC ... > Result; }; int main() { typedef MetaString<'f', 'o', 'o'> Foo; typedef MetaString<'b', 'a', 'r'> Bar; typedef typename Concatenate<Foo, Bar>::Result FooBar; std::cout << Foo::string() << std::endl; // foo std::cout << Bar::string() << std::endl; // bar std::cout << FooBar::string() << std::endl; // foobar }
Denis kreshikhin
source share