diff --git a/src/lib/meta/function-closure.hpp b/src/lib/meta/function-closure.hpp index 4c354f751..77ff9145a 100644 --- a/src/lib/meta/function-closure.hpp +++ b/src/lib/meta/function-closure.hpp @@ -379,7 +379,7 @@ namespace typelist{ typedef typename PlaceholderTuple::PlaceholderSeq TailPlaceholderSeq; public: - typedef typename Prepend<_Placeholder, TailPlaceholderSeq>::Tuple PlaceholderSeq; + typedef typename Prepend<_Placeholder, TailPlaceholderSeq>::Seq PlaceholderSeq; typedef Tuple Type; }; diff --git a/src/lib/meta/tuple.hpp b/src/lib/meta/tuple.hpp index cb7309765..ff03cfff6 100644 --- a/src/lib/meta/tuple.hpp +++ b/src/lib/meta/tuple.hpp @@ -24,9 +24,9 @@ /** @file tuple.hpp ** Metaprogramming with tuples-of-types and a simple Tuple (record) datatype. ** The metaprogramming part of this header complements typelist.hpp and allows - ** to re-build a new tuple-of-types from an existing typelist. Such a finite - ** sequence or tuple of types can at times be more handy than a typelist, - ** especially when capturing specific types to use as template parameter. + ** some additional manipulations on type sequences. Such a finite sequence or + ** tuple of types can at times be more handy than a typelist, especially when + ** capturing specific types to use as template parameter. ** ** Additionally, this header augments the Tuple template into a simple Tuple ** (run time) datatype. This isn't meant as competing with std::tr1::tuple, which is @@ -48,7 +48,8 @@ #define LUMIERA_META_TUPLE_H #include "lib/meta/typelist.hpp" -#include "lib/meta/typelistutil.hpp" +#include "lib/meta/typelist-util.hpp" +#include "lib/meta/typeseq-util.hpp" #include "lib/meta/util.hpp" @@ -58,123 +59,6 @@ namespace typelist{ - /** - * Helper: prepend a type to an existing type sequence, - * thus shifting all elements within the sequence - * to the right, eventually dropping the last element - */ - template - struct Prepend; - - template< typename T01 - , typename T02 - , typename T03 - , typename T04 - , typename T05 - , typename T06 - , typename T07 - , typename T08 - , typename T09 - , typename T10 - , typename T11 - , typename T12 - , typename T13 - , typename T14 - , typename T15 - , typename T16 - , typename T17 - , typename T18 - , typename T19 - , typename T20 - , typename IGN - > - struct Prepend > - { - typedef Types< T01,T02,T03,T04,T05 - , T06,T07,T08,T09,T10 - , T11,T12,T13,T14,T15 - , T16,T17,T18,T19,T20 > Tuple; - - typedef typename Tuple::List List; - }; - - - - - /** Helper: separate parts of a type sequence */ - template - struct Split; - - template< typename T01 - , typename T02 - , typename T03 - , typename T04 - , typename T05 - , typename T06 - , typename T07 - , typename T08 - , typename T09 - , typename T10 - , typename T11 - , typename T12 - , typename T13 - , typename T14 - , typename T15 - , typename T16 - , typename T17 - , typename T18 - , typename T19 - , typename T20 - > - struct Split > - { - typedef T01 Head; - typedef Types< T01 > First; - typedef Types< T01,T02,T03,T04,T05 - , T06,T07,T08,T09,T10 - , T11,T12,T13,T14,T15 - , T16,T17,T18,T19 > Prefix; - typedef Types< T02,T03,T04,T05 - , T06,T07,T08,T09,T10 - , T11,T12,T13,T14,T15 - , T16,T17,T18,T19,T20 > Tail; - typedef Types< T20 > Last; - typedef T20 End; - }; - - - - - /** - * Helper: generate a type sequence left shifted - * by i steps, filling in NullType at the end - */ - template - class Shifted - { - typedef typename Split::Tail Tail; - public: - typedef typename Shifted::Type Type; - typedef typename Split::Head Head; - }; - - template - struct Shifted - { - typedef TYPES Type; - typedef typename Split::Head Head; - }; - - /** * simple generic Tuple datatype. * Usable both for metaprogramming and as a generic record. @@ -233,9 +117,9 @@ namespace typelist{ struct Tuple > : Tuple { - typedef TY HeadType; - typedef typename Tuple::Type TailType; - typedef typename Prepend::Tuple Type; + typedef TY HeadType; + typedef typename Tuple::Type TailType; + typedef typename Prepend::Seq Type; typedef Node ArgList; typedef Tuple TupleType; diff --git a/src/lib/meta/typelistutil.hpp b/src/lib/meta/typelist-util.hpp similarity index 89% rename from src/lib/meta/typelistutil.hpp rename to src/lib/meta/typelist-util.hpp index 5fcded832..7e6c02a42 100644 --- a/src/lib/meta/typelistutil.hpp +++ b/src/lib/meta/typelist-util.hpp @@ -1,5 +1,5 @@ /* - TYPELISTUTIL.hpp - Utils for working with lists-of-types + TYPELIST-UTIL.hpp - Utils for working with lists-of-types Copyright (C) Lumiera.org 2008, Hermann Vosseler @@ -21,15 +21,15 @@ */ -#ifndef LUMIERA_META_TYPELISTUTIL_H -#define LUMIERA_META_TYPELISTUTIL_H +#ifndef LUMIERA_META_TYPELIST_UTIL_H +#define LUMIERA_META_TYPELIST_UTIL_H #include "lib/meta/typelist.hpp" namespace lumiera { -namespace typelist { +namespace typelist{ /** @@ -188,6 +188,36 @@ namespace typelist { + template + struct Dissect; + + template + struct Dissect > + { + typedef Node List; + typedef T Head; + typedef Node First; + typedef TYPES Tail; + typedef typename SplitLast::List Prefix; + typedef typename SplitLast::Type End; + typedef Node Last; + }; + + template<> + struct Dissect + { + typedef NullType List; + typedef NullType Head; + typedef NullType First; + typedef NullType Tail; + typedef NullType Prefix; + typedef NullType End; + typedef NullType Last; + }; + + + + /** * prefix each of the elements, * yielding a list-of lists-of-types diff --git a/src/lib/meta/typelist.hpp b/src/lib/meta/typelist.hpp index 96c70c480..b3e44138d 100644 --- a/src/lib/meta/typelist.hpp +++ b/src/lib/meta/typelist.hpp @@ -112,6 +112,7 @@ namespace typelist{ struct Types<> { typedef NullType List; + typedef Types<> Seq; }; diff --git a/src/lib/meta/typeseq-util.hpp b/src/lib/meta/typeseq-util.hpp new file mode 100644 index 000000000..23ffbdc77 --- /dev/null +++ b/src/lib/meta/typeseq-util.hpp @@ -0,0 +1,207 @@ +/* + TYPESEQ-UTIL.hpp - basic metaprogramming utilities for type sequences + + Copyright (C) Lumiera.org + 2009, Hermann Vosseler + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + + +/** @file typeseq-util.hpp + ** Some basic facilities for manipulating type sequences. + ** While typelist.hpp provides the foundation of metaprogramming with typelists, + ** manipulating the type sequences themselves (i.e. Types instances) + ** requires some additional helper templates supplemented here. + ** - prepending to a type sequence + ** - dissecting a type sequence + ** - shifting a type sequence + ** - re-generating a type sequence from a typelist. + ** + ** @see typeseq-manip-test.cpp + ** @see typelist.hpp + ** @see typelist-util.hpp + ** @see function.hpp + ** @see generator.hpp + ** @see tuple.hpp + ** + */ + + +#ifndef LUMIERA_META_TYPESEQ_UTIL_H +#define LUMIERA_META_TYPESEQ_UTIL_H + +#include "lib/meta/typelist.hpp" +#include "lib/meta/typelist-util.hpp" +#include "lib/meta/util.hpp" + + + +namespace lumiera { +namespace typelist{ + + + + /** + * Helper: prepend a type to an existing type sequence, + * thus shifting all elements within the sequence + * to the right, eventually dropping the last element + */ + template + struct Prepend; + + template< typename T01 + , typename T02 + , typename T03 + , typename T04 + , typename T05 + , typename T06 + , typename T07 + , typename T08 + , typename T09 + , typename T10 + , typename T11 + , typename T12 + , typename T13 + , typename T14 + , typename T15 + , typename T16 + , typename T17 + , typename T18 + , typename T19 + , typename T20 + , typename IGN + > + struct Prepend > + { + typedef Types< T01,T02,T03,T04,T05 + , T06,T07,T08,T09,T10 + , T11,T12,T13,T14,T15 + , T16,T17,T18,T19,T20 > Seq; + + typedef typename Seq::List List; + }; + + + + /** + * Additional specialisation of the basic type sequence type, + * allowing to re-create a (flat) type sequence from a typelist. + */ + template + struct Types< Node > + { + typedef Node List; + + typedef typename Prepend< H + , typename Types::Seq + >::Seq Seq; + }; + + + + + + + /** Helper: separate parts of a type sequence */ + template + struct Split; + + template< typename T01 + , typename T02 + , typename T03 + , typename T04 + , typename T05 + , typename T06 + , typename T07 + , typename T08 + , typename T09 + , typename T10 + , typename T11 + , typename T12 + , typename T13 + , typename T14 + , typename T15 + , typename T16 + , typename T17 + , typename T18 + , typename T19 + , typename T20 + > + struct Split > + { + typedef typename + Types< T01,T02,T03,T04,T05 + , T06,T07,T08,T09,T10 + , T11,T12,T13,T14,T15 + , T16,T17,T18,T19,T20 + >::List List; + + typedef T01 Head; + typedef Types< T01 > First; + typedef Types< T02,T03,T04,T05 + , T06,T07,T08,T09,T10 + , T11,T12,T13,T14,T15 + , T16,T17,T18,T19,T20 > Tail; + + // for finding the end we need the help of typelist-util.hpp + + typedef typename SplitLast::List PrefixList; + typedef typename Tail::List TailList; + + typedef typename Types::Seq Prefix; + typedef typename SplitLast::Type End; + typedef Types Last; + }; + + + + + /** + * Helper: generate a type sequence left shifted + * by i steps, filling in NullType at the end + */ + template + class Shifted + { + typedef typename Split::Tail Tail; + public: + typedef typename Shifted::Type Type; + typedef typename Split::Head Head; + }; + + template + struct Shifted + { + typedef TYPES Type; + typedef typename Split::Head Head; + }; + + + + + +}} // namespace lumiera::typelist +#endif diff --git a/src/lib/variant.hpp b/src/lib/variant.hpp index 3f9cea028..ebaac670a 100644 --- a/src/lib/variant.hpp +++ b/src/lib/variant.hpp @@ -41,7 +41,7 @@ #define LUMIERA_VARIANT_H -#include "lib/meta/typelistutil.hpp" +#include "lib/meta/typelist-util.hpp" #include "lib/meta/generator.hpp" #include diff --git a/src/proc/control/command-def.hpp b/src/proc/control/command-def.hpp index ebfc7906b..acd3d71ce 100644 --- a/src/proc/control/command-def.hpp +++ b/src/proc/control/command-def.hpp @@ -55,7 +55,7 @@ #include "proc/control/command-closure.hpp" #include "lib/meta/function.hpp" #include "lib/meta/typelist.hpp" -#include "lib/meta/typelistutil.hpp" +#include "lib/meta/typelist-util.hpp" #include "lib/meta/tuple.hpp" //#include diff --git a/src/proc/control/command-signature.hpp b/src/proc/control/command-signature.hpp index 503a212f2..0def46d01 100644 --- a/src/proc/control/command-signature.hpp +++ b/src/proc/control/command-signature.hpp @@ -50,7 +50,7 @@ //#include "include/symbol.hpp" #include "lib/meta/function.hpp" #include "lib/meta/typelist.hpp" -#include "lib/meta/typelistutil.hpp" +#include "lib/meta/typelist-util.hpp" #include "lib/meta/tuple.hpp" //#include diff --git a/src/proc/engine/nodewiring.cpp b/src/proc/engine/nodewiring.cpp index e6449f755..8dab297b7 100644 --- a/src/proc/engine/nodewiring.cpp +++ b/src/proc/engine/nodewiring.cpp @@ -26,7 +26,7 @@ #include "proc/engine/nodeoperation.hpp" #include "proc/engine/nodewiringconfig.hpp" -#include "lib/meta/typelistutil.hpp" +#include "lib/meta/typelist-util.hpp" namespace engine { diff --git a/tests/components/proc/control/command-basic-test.cpp b/tests/components/proc/control/command-basic-test.cpp index 76ccc20a1..accd9d3db 100644 --- a/tests/components/proc/control/command-basic-test.cpp +++ b/tests/components/proc/control/command-basic-test.cpp @@ -37,7 +37,7 @@ //#include "lib/util.hpp" #include "lib/meta/typelist.hpp" -#include "lib/meta/typelistutil.hpp" +#include "lib/meta/typelist-util.hpp" #include "lib/meta/generator.hpp" diff --git a/tests/lib/meta/config-flags-test.cpp b/tests/lib/meta/config-flags-test.cpp index 995ddef56..fd1e085ed 100644 --- a/tests/lib/meta/config-flags-test.cpp +++ b/tests/lib/meta/config-flags-test.cpp @@ -40,7 +40,7 @@ #include "lib/test/run.hpp" #include "lib/meta/util.hpp" #include "lib/meta/generator.hpp" -#include "lib/meta/typelistutil.hpp" +#include "lib/meta/typelist-util.hpp" #include "lib/meta/configflags.hpp" #include "meta/typelist-diagnostics.hpp" #include "proc/engine/nodewiringconfig.hpp" diff --git a/tests/lib/meta/function-closure-test.cpp b/tests/lib/meta/function-closure-test.cpp index 0a0cce750..2def0fde4 100644 --- a/tests/lib/meta/function-closure-test.cpp +++ b/tests/lib/meta/function-closure-test.cpp @@ -38,7 +38,7 @@ #include "lib/test/run.hpp" #include "lib/test/test-helper.hpp" #include "lib/meta/typelist.hpp" -#include "lib/meta/typelistutil.hpp" +#include "lib/meta/typelist-util.hpp" #include "lib/meta/function.hpp" #include "lib/meta/function-closure.hpp" #include "meta/typelist-diagnostics.hpp" @@ -141,7 +141,7 @@ namespace test { typedef FunctionSignature >::Args Args; DISPLAY (Args); - typedef Prepend, Args>::Tuple NewArgs; // manipulate the argument type(s) + typedef Prepend, Args>::Seq NewArgs; // manipulate the argument type(s) DISPLAY (NewArgs); typedef FunctionTypedef::Sig NewSig; // re-build a new function signature diff --git a/tests/lib/meta/typelist-manip-test.cpp b/tests/lib/meta/typelist-manip-test.cpp index 9c86a2e34..9fa1a73f8 100644 --- a/tests/lib/meta/typelist-manip-test.cpp +++ b/tests/lib/meta/typelist-manip-test.cpp @@ -32,7 +32,7 @@ ** if various lists of such constant-wrapper types were manipulated as expected. ** ** @see typelist-test.cpp - ** @see typelistutil.hpp + ** @see typelist-util.hpp ** @see nodewiringconfig.hpp real world usage example ** */ @@ -40,7 +40,7 @@ #include "lib/test/run.hpp" #include "lib/meta/generator.hpp" -#include "lib/meta/typelistutil.hpp" +#include "lib/meta/typelist-util.hpp" #include "meta/typelist-diagnostics.hpp" //#include "lib/util.hpp"