//////////////////////////////////////////////////////////////////////////////// // The Loki Library // Data Generator by Shannon Barber // This code DOES NOT accompany the book: // Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design // Patterns Applied". Copyright (c) 2001. Addison-Wesley. // // Code covered by the MIT License // The author makes no representations about the suitability of this software // for any purpose. It is provided "as is" without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// // Last update: Oct 10, 2002 #ifndef DATAGENERATORS_H #define DATAGENERATORS_H #include "Typelist.h" //Reference version /************************************************************************************ // class template GenData // Iteratates a Typelist, and invokes the functor GenFunc // for each type in the list, passing a functor along the way. // The functor is designed to be an insertion iterator which GenFunc // can use to output information about the types in the list. // Example Use template struct ExtractDataType { some_type operator()() { return create_value_from_type; } }; Loki::IterateTypes gendata; std::vector stuff; gendata(std::back_inserter(stuff)); *******************************************************************************/ namespace Loki { namespace TL { template struct nameof_type { const char* operator()() { return typeid(T).name(); } }; template struct sizeof_type { size_t operator()() { return sizeof(T); } }; template class GenFunc> struct IterateTypes; template class GenFunc> struct IterateTypes, GenFunc> { typedef IterateTypes head_t; head_t head; typedef IterateTypes tail_t; tail_t tail; template void operator()(II ii) { head.operator()(ii); tail.operator()(ii); } }; template class GenFunc> struct IterateTypes { template void operator()(II ii) { GenFunc genfunc; *ii = genfunc(); ++ii; //Is this even needed? } }; template