Main Page | Modules | Namespace List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

tag::T_list< C, D > Struct Template Reference
[Tuple types of arbitrary length]

#include <tuple.h>

Collaboration diagram for tag::T_list< C, D >:

[legend]
List of all members.

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.

Detailed Description

template<class C, class D>
struct tag::T_list< C, D >

Tuple/ typelist class. Passed by const reference.

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)
or more convieniently with a macro:
    make_tuple("hello", 2.2f, 1)
Note that the order is reversed between how the type is written and how a list is written using 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>();
and by type:
    some_tuples_type::index_type<0>::type a_value = some_tuple.index<0>();
The length of the list is a static member, so the last element can be eccessed by:
        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


Member Typedef Documentation

template<class C, class D>
typedef D tag::T_list< C, D >::next_type
 

The type of the rest of the list.

template<class C, class D>
typedef C tag::T_list< C, D >::val_type
 

The type of the current element.


Member Enumeration Documentation

template<class C, class D>
anonymous enum
 

Enumeration values:
elements  The number of elements in the list.


Constructor & Destructor Documentation

template<class C, class D>
tag::T_list< C, D >::T_list const C &  c,
const D &  d
[inline]
 

Construct a typelist.

Parameters:
c The value of the end of the list
d The rest of the list


Member Function Documentation

template<class C, class D>
template<int i>
const Internal::T_index_forward<C,D,i>::val_type& tag::T_list< C, D >::index  )  const [inline]
 

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)

template<class C, class D>
template<class X>
T_list<X, T_list<C, D> > tag::T_list< C, D >::operator, const X &  c  )  const [inline]
 

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> > >
containing 1, 2.0 and 3.3 can be built up by:
           TupleHead, 1, 2.0, 3.3
Though it is important to note that the list is built in reverse, so that 3.3 is the most accessible element.
Parameters:
c List to which an element should be appended.


Member Data Documentation

template<class C, class D>
const D& tag::T_list< C, D >::next
 

The rest of the list.

template<class C, class D>
const C& tag::T_list< C, D >::val
 

The value of the current element (the end of the list).


The documentation for this struct was generated from the following file:
Generated on Wed Aug 8 14:30:36 2007 for TooN Algorithm Library - tag by  doxygen 1.3.9.1