Merge two variation patterns in one

I am trying to implement the Variadic shell of the loki directory template.

Merging two lists of types in the loki style is very simple, but I'm having trouble merging in the Variadic-template style.

This is my implementation (simplified, without push_back, index_of, ..., methods).

template<typename... Ts> struct dl32TypeList; template<typename HEAD , typename... TAIL> struct dl32TypeList<HEAD,TAIL...> { static const unsigned int size = sizeof...(TAIL) + 1; using value = dl32Loki_like_TypeList<HEAD, typename dl32TypeList<TAIL...>::value>; }; template<> struct dl32TypeList<> { using value = dl32NoType; static const unsignedint size = 0; }; 

I need something like:

 template<typename OTHER_TYPELIST> using merge = dl32TypeList<HEAD , TAIL... , typename OTHER_TYPELIST::???>; 

And this is the problem: we cannot store variable template templates as using / typedef, so I have an idea of ​​how I can do this. (Pay attention to OTHER_TYPELIST :: ???).

+4
source share
1 answer

I don’t know what Loki or DL32 is, and it’s not clear that you have to implement anything at all.

std::tuple is a general tool for type lists. It is designed as a storage container at runtime, but works as a compilation utility if the types are complete. Here is one way to bind tuples:

 template< typename ... t > struct tuple_cat { typedef decltype( std::tuple_cat( std::declval< t >() ... ) ) type; }; 

If you want to do this manually, try partial specialization:

 template< typename ... t > struct type_list {}; template< typename ta, typename tb > struct type_cat; template< typename ... a, typename ... b > struct type_cat< type_list< a ... >, type_list< b ... > > { typedef type_list< a ..., b ... > type; }; 

As for the size member, you can make a universal metafound to solve the problem once and for all.

 template< typename > struct count_types; template< template< typename ... > class t, typename ... a > struct count_types< t< a ... > > { static constexpr std::size_t value = sizeof ... a; }; 
+6
source

Source: https://habr.com/ru/post/1481741/


All Articles