cleanup/refactor simple type seq handling, fix broken Split template

This commit is contained in:
Fischlurch 2009-06-30 04:54:50 +02:00
parent 320f984270
commit ca807205f9
13 changed files with 261 additions and 139 deletions

View file

@ -379,7 +379,7 @@ namespace typelist{
typedef typename PlaceholderTuple<TailSeq, i+1>::PlaceholderSeq TailPlaceholderSeq;
public:
typedef typename Prepend<_Placeholder<i>, TailPlaceholderSeq>::Tuple PlaceholderSeq;
typedef typename Prepend<_Placeholder<i>, TailPlaceholderSeq>::Seq PlaceholderSeq;
typedef Tuple<PlaceholderSeq> Type;
};

View file

@ -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<class T, class TYPES>
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<T01, Types< T02,T03,T04,T05
, T06,T07,T08,T09,T10
, T11,T12,T13,T14,T15
, T16,T17,T18,T19,T20
, IGN
> >
{
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<class TYPES>
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<Types< T01,T02,T03,T04,T05
, T06,T07,T08,T09,T10
, T11,T12,T13,T14,T15
, T16,T17,T18,T19,T20
> >
{
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 TYPES, uint i=1>
class Shifted
{
typedef typename Split<TYPES>::Tail Tail;
public:
typedef typename Shifted<Tail,i-1>::Type Type;
typedef typename Split<Type>::Head Head;
};
template<class TYPES>
struct Shifted<TYPES,0>
{
typedef TYPES Type;
typedef typename Split<Type>::Head Head;
};
/**
* simple generic Tuple datatype.
* Usable both for metaprogramming and as a generic record.
@ -233,9 +117,9 @@ namespace typelist{
struct Tuple<Node<TY,TYPES> >
: Tuple<TYPES>
{
typedef TY HeadType;
typedef typename Tuple<TYPES>::Type TailType;
typedef typename Prepend<TY,TailType>::Tuple Type;
typedef TY HeadType;
typedef typename Tuple<TYPES>::Type TailType;
typedef typename Prepend<TY,TailType>::Seq Type;
typedef Node<TY,TYPES> ArgList;
typedef Tuple<Type> TupleType;

View file

@ -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 <Ichthyostega@web.de>
@ -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<class TYPES>
struct Dissect;
template<class T, class TYPES>
struct Dissect<Node<T,TYPES> >
{
typedef Node<T,TYPES> List;
typedef T Head;
typedef Node<T,NullType> First;
typedef TYPES Tail;
typedef typename SplitLast<List>::List Prefix;
typedef typename SplitLast<List>::Type End;
typedef Node<End,NullType> Last;
};
template<>
struct Dissect<NullType>
{
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

View file

@ -112,6 +112,7 @@ namespace typelist{
struct Types<>
{
typedef NullType List;
typedef Types<> Seq;
};

View file

@ -0,0 +1,207 @@
/*
TYPESEQ-UTIL.hpp - basic metaprogramming utilities for type sequences
Copyright (C) Lumiera.org
2009, Hermann Vosseler <Ichthyostega@web.de>
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<T1,T2,...> 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<class T, class TYPES>
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<T01, Types< T02,T03,T04,T05
, T06,T07,T08,T09,T10
, T11,T12,T13,T14,T15
, T16,T17,T18,T19,T20
, IGN
> >
{
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<class H, class T>
struct Types< Node<H,T> >
{
typedef Node<H,T> List;
typedef typename Prepend< H
, typename Types<T>::Seq
>::Seq Seq;
};
/** Helper: separate parts of a type sequence */
template<class TYPES>
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<Types< T01,T02,T03,T04,T05
, T06,T07,T08,T09,T10
, T11,T12,T13,T14,T15
, T16,T17,T18,T19,T20
> >
{
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>::List PrefixList;
typedef typename Tail::List TailList;
typedef typename Types<PrefixList>::Seq Prefix;
typedef typename SplitLast<List>::Type End;
typedef Types<End> Last;
};
/**
* Helper: generate a type sequence left shifted
* by i steps, filling in NullType at the end
*/
template<class TYPES, uint i=1>
class Shifted
{
typedef typename Split<TYPES>::Tail Tail;
public:
typedef typename Shifted<Tail,i-1>::Type Type;
typedef typename Split<Type>::Head Head;
};
template<class TYPES>
struct Shifted<TYPES,0>
{
typedef TYPES Type;
typedef typename Split<Type>::Head Head;
};
}} // namespace lumiera::typelist
#endif

View file

@ -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 <boost/noncopyable.hpp>

View file

@ -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 <tr1/memory>

View file

@ -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 <tr1/memory>

View file

@ -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 {

View file

@ -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"

View file

@ -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"

View file

@ -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<function<someFunc> >::Args Args;
DISPLAY (Args);
typedef Prepend<Num<1>, Args>::Tuple NewArgs; // manipulate the argument type(s)
typedef Prepend<Num<1>, Args>::Seq NewArgs; // manipulate the argument type(s)
DISPLAY (NewArgs);
typedef FunctionTypedef<RetType,NewArgs>::Sig NewSig; // re-build a new function signature

View file

@ -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"