C++ template string concatenation

后端 未结 5 896
天涯浪人
天涯浪人 2020-12-16 02:50

I\'m trying to define some variadic template like that:

typedef const char CCTYPE[];
template struct StringConcat { ... };
         


        
5条回答
  •  旧巷少年郎
    2020-12-16 03:06

    #include 
    #include 
    #include 
    #include 
    
    using namespace boost;
    
    template < typename Str1, typename Str2 >
    struct concat : mpl::insert_range::type, Str2> {};
    
    int main()
    {
      typedef mpl::string<'hell', 'o'> str1;
      typedef mpl::string<' wor', 'ld!'> str2;
    
      typedef concat::type str;
    
      std::cout << mpl::c_str::value << std::endl;
    
      std::cin.get();
    }
    

    Using that construct you should be able to implement your FizzBuzz in pure metaprogramming. Nice exercise BTW.

提交回复
热议问题