Building one specific boost :: tuple method using another

Given:

typedef boost :: tuple <T1, T2, T3, ..., Tn> Tuple_Tn

where all types T1, ... Tn are defined,

And given the type T_another, I would like to define a new type of tuple:

typedef boost :: tuple <T1, T2, T3, ..., Tn, T_another> Tuple_T_plus_1

But here is my problem: in the place where I want to define it, I have access only to the types Tuple_Tn and T_another.

In other words, is it possible to define Tuple_T_plus_1 in terms of Tuple_Tn and T_another only?

+4
source share
1 answer

I'm not sure if Boost.Tuple has such a feature, maybe Boost.Fusion will be more suitable for your needs.

However, if you have a compiler that supports C ++ 11 variable templates, you can switch to std::tuple and write a small replacement to add the type to the existing tuple:

 template <typename Container, typename T> struct push_back; template <template <typename...> class Container, typename T, typename... Args> struct push_back<Container<Args...>, T> { typedef Container<Args..., T> type; }; typedef std::tuple<int, double> myTuple; typedef push_back<myTuple, bool>::type myOtherTuple; myOtherTuple(1, 0.0, true); 

The same can be done for boost::tuple , but it would be a lot of tedious writing.

+3
source

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


All Articles