1 ////////////////////////////////////////////////////////////////////////////////
3 // Data Generator by Shannon Barber
4 // This code DOES NOT accompany the book:
5 // Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
6 // Patterns Applied". Copyright (c) 2001. Addison-Wesley.
8 // Code covered by the MIT License
9 // The author makes no representations about the suitability of this software
10 // for any purpose. It is provided "as is" without express or implied warranty.
11 ////////////////////////////////////////////////////////////////////////////////
12 #ifndef LOKI_DATAGENERATORS_INC_
13 #define LOKI_DATAGENERATORS_INC_
15 // $Id: DataGenerators.h 751 2006-10-17 19:50:37Z syntheticpp $
22 /************************************************************************************
23 // class template GenData
24 // Iteratates a Typelist, and invokes the functor GenFunc<T>
25 // for each type in the list, passing a functor along the way.
26 // The functor is designed to be an insertion iterator which GenFunc<T>
27 // can use to output information about the types in the list.
33 struct ExtractDataType
35 some_type operator()()
37 return create_value_from_type<T>;
41 Loki::IterateTypes<parameter_tl, ExtractDataType> gendata;
42 std::vector<some_type> stuff;
43 gendata(std::back_inserter(stuff));
44 *******************************************************************************/
52 const char *operator()()
54 return typeid(T).name();
65 template <class TList, template <class> class GenFunc>
68 template <class T1, class T2, template <class> class GenFunc>
69 struct IterateTypes<Typelist<T1, T2>, GenFunc>
71 typedef IterateTypes<T1, GenFunc> head_t;
73 typedef IterateTypes<T2, GenFunc> tail_t;
76 void operator()(II ii)
83 template <class AtomicType, template <class> class GenFunc>
87 void operator()(II ii)
89 GenFunc<AtomicType> genfunc;
91 ++ii; //Is this even needed?
95 template <template <class> class GenFunc>
96 struct IterateTypes<NullType, GenFunc>
99 void operator()(II ii)
103 template<typename Types, template <class> class UnitFunc, typename II>
104 void iterate_types(II ii)
106 Loki::TL::IterateTypes<Types, UnitFunc> it;
112 #endif // end file guardian