//////////////////////////////////////////////////////////////////////////////// // The Loki Library // Copyright (c) 2001 by Andrei Alexandrescu // This code accompanies the book: // Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design // Patterns Applied". Copyright (c) 2001. Addison-Wesley. // Permission to use, copy, modify, distribute and sell this software for any // purpose is hereby granted without fee, provided that the above copyright // notice appear in all copies and that both that copyright notice and this // permission notice appear in supporting documentation. // The author or Addison-Wesley Longman make no representations about the // suitability of this software for any purpose. It is provided "as is" // without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// // $Header: #ifndef LOKI_HIERARCHYGENERATORS_INC_ #define LOKI_HIERARCHYGENERATORS_INC_ #include "Typelist.h" #include "TypeTraits.h" #include "EmptyType.h" namespace Loki { #if defined(_MSC_VER) && _MSC_VER >= 1300 #pragma warning( push ) // 'class1' : base-class 'class2' is already a base-class of 'class3' #pragma warning( disable : 4584 ) #endif // _MSC_VER //////////////////////////////////////////////////////////////////////////////// // class template GenScatterHierarchy // Generates a scattered hierarchy starting from a typelist and a template // Invocation (TList is a typelist, Unit is a template of one arg): // GenScatterHierarchy // The generated class inherits all classes generated by instantiating the // template 'Unit' with the types contained in TList //////////////////////////////////////////////////////////////////////////////// namespace Private { // The following type helps to overcome subtle flaw in the original // implementation of GenScatterHierarchy. // The flaw is revealed when the input type list of GenScatterHierarchy // contains more then one element of the same type (e.g. LOKI_TYPELIST_2(int, int)). // In this case GenScatterHierarchy will contain multiple bases of the same // type and some of them will not be reachable (per 10.3). // For example before the fix the first element of Tuple // is not reachable in any way! template struct ScatterHierarchyTag; } template class Unit> class GenScatterHierarchy; template class Unit> class GenScatterHierarchy, Unit> : public GenScatterHierarchy, Unit> , public GenScatterHierarchy { public: typedef Typelist TList; // Insure that LeftBase is unique and therefore reachable typedef GenScatterHierarchy, Unit> LeftBase; typedef GenScatterHierarchy RightBase; template struct Rebind { typedef Unit Result; }; }; // In the middle *unique* class that resolve possible ambiguity template class Unit> class GenScatterHierarchy, Unit> : public GenScatterHierarchy { }; template class Unit> class GenScatterHierarchy : public Unit { typedef Unit LeftBase; template struct Rebind { typedef Unit Result; }; }; template