When writing template in template

Posted by on in Programming

It is possible to write template in template.
In that case, you can pass the "geho_<std :: vector>" class template directly to the template.

namespace my_
{
    template <class T1, typename T2> struct hoge_{};

    template<
      template<typename, typename> class T,
      typename T1, typename T2>
    struct geho_
    {
      T<T1, T2> t_;
    };
};

I put hoge_ in class geho_. It is typed in T template in geho_.
So you can pass it like the following.

    my_::geho_<my_::hoge_, TObject, TObject> geho_hoge_;

Replace hoge_ with vector.
Since vector is "<class T, class Allocator = allocator <T > >"

    my_::geho_<std::vector, char, std::allocator<char>> geho_vector;

It is possible to write like the above.

"My_::geho_<std::vector, char, std::allocator<char> >" I hate putting "char" 2 times in this

    template<
      template<typename,typename> class T,
      typename T1, template<typename> class T2>
    struct gehox_
    {
      T<T1, T2<T1> > t_;
    };

I will do as above.

    my_::gehox_<std::vector, char, std::allocator> geho_vector;

It is possible to write it smartly.

 



About
Gold User, No rank,
Delphi / C++Builder blogger

Comments

Check out more tips and tricks in this development video: