00001 #ifndef GRAL_GB_HETEROGENEOUS_LIST_H
00002 #define GRAL_GB_HETEROGENEOUS_LIST_H
00003
00004
00005
00006
00026 namespace heterogeneous_list {
00027
00028 struct END {};
00031 struct BEGIN {};
00032
00037 template<class T, class TAIL>
00038 class List {
00039 public:
00040 typedef T value_type;
00041 typedef TAIL tail_type;
00042 private:
00043 T const* t_;
00044 TAIL tail_;
00045 public:
00046 List(T const& t, TAIL const& tail1) : t_(&t), tail_(tail1) {}
00047 T const& head() const { return *t_;}
00048 TAIL const& tail() const { return tail_;}
00049 };
00050
00051
00052
00053 template<class END>
00054 class List<END,END> {
00055 public:
00056 typedef END head_type;
00057 typedef END tail_type;
00058 END e;
00059 List() {}
00060 List(END,END) {}
00061 END head() { return e;}
00062 END tail() { return e;}
00063 };
00064
00065 template<class T, class T2, class TAIL>
00066 List<T,List<T2,TAIL> > operator,(List<T2,TAIL> tail, T const& t)
00067 { return List<T,List<T2,TAIL> >(t,tail);}
00068
00069 template<class T>
00070 List<T,List<END,END> > operator,(BEGIN b, T const& t)
00071 { return List<T,List<END,END> >(t,List<END,END>());}
00072
00073 }
00074 #endif
00075