#include <tuple.h>
Collaboration diagram for tag::T_list< C, D >:
Public Types | |
| typedef C | val_type |
| The type of the current element. | |
| typedef D | next_type |
| The type of the rest of the list. | |
| enum | { elements = (Internal::length<C,D>::len) } |
Public Member Functions | |
| T_list (const C &c, const D &d) | |
| template<class X> | |
| T_list< X, T_list< C, D > > | operator, (const X &c) const |
| template<int i> | |
| const Internal::T_index_forward< C, D, i >::val_type & | index () const |
Public Attributes | |
| const C & | val |
| The value of the current element (the end of the list). | |
| const D & | next |
| The rest of the list. | |
A typelist containing an int, float and char* represented by the class:
T_list<int, T_list<float, T_list< char*, T_ListEnd> > >
Typelists can be conviniently be built through use of the , operator. The following code will have the type given above:
(TupleHead, "hello", 2.2f, 1)
make_tuple("hello", 2.2f, 1)
operator,(). The lists can be statically indexed, and the indexing matches the order written using ,. That is index 0 will refer to (char*) "hello". Indexing can be performed by value: char* ptr = some_tuple.index<0>();
some_tuples_type::index_type<0>::type a_value = some_tuple.index<0>();
some_tuple.index<some_tuples_type::elements-1>()
The following code gives a simple example of the usage. The code simply prints out a list of values.
#include <tag/tuple.h> #include <iostream> using namespace tag; using namespace std; template<class C, int i, int max> struct dump_list { static void dump(const C& l) { cout << l.template index<i>()<< endl; dump_list<C, i+1, max>::dump(l); } }; template<class C, int max> struct dump_list<C, max, max> { static void dump(const C&) {} }; template<class C, class D> void print_typelist(const T_list<C, D>& l) { dump_list<T_list<C,D>,0,T_list<C,D>::elements>::dump(l); } #define print(...) print_typelist((TupleHead,##__VA_ARGS__)) int main() { print(1, "hello", 3.3, (void*)"aa", "world", cin.rdbuf(), 99.9); }
This will print
1
hello
3.3
0xdeadbeefwhatever
world
<whatever the user types here>
99.0
|
|||||
|
The type of the rest of the list.
|
|
|||||
|
The type of the current element.
|
|
|||||
|
|
|
||||||||||||||||
|
Construct a typelist.
|
|
|||||||||||||
|
Index the list in logical order and return the value. Index 0 is the first element added to the list (the one closest to T_ListEnd) |
|
||||||||||||||
|
This operator can be used to build a typelist from values in code The list: T_list<int, T_list<float, T_list< char*, T_ListEnd> > > TupleHead, 1, 2.0, 3.3
|
|
|||||
|
The rest of the list.
|
|
|||||
|
The value of the current element (the end of the list).
|
1.3.9.1