//////////////////////////////////////////////////////////////////////////////// // 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. // Code covered by the MIT License // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_HIERARCHYGENERATORS_INC_ #define LOKI_HIERARCHYGENERATORS_INC_ // $Id$ #include #include #include 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