C ++: can we collect types?

I wonder if we can do something like

a.pushType<int> a.pushType<std::string> a.pushType<char> 

so we can name

 std::map<a.T1, a.T3> mymap; std::map<a.T1, a.T2> mymap; someClass<a.T1, a.T2, a.T3> 

And I need this not at runtime , but at compile time (to provide it in my header library only).

Is this possible with C ++ 03 and Boost?

+2
source share
2 answers

This mechanism is called TypeLists; as far as I know, this was first proposed by Andrei Alexandrescu in Modern C ++ Design. There, an implementation of TypeLists is implemented in the library of Alexandrescu, Loki . I also think that Boost.MPL has a similar construction: vector .

+7
source
 typedef std::pair<int, std::string> a; std::map<a::first_type, a::second_type> mymap; 

Types must be known at compile time. There are around, but they are very complex.

0
source

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


All Articles