refactoring to solve consistency problems uncovered by the tests
This commit is contained in:
parent
a92f633276
commit
db9ef808a5
3 changed files with 146 additions and 59 deletions
|
|
@ -191,7 +191,8 @@ namespace typelist{
|
|||
typedef Types<> Type;
|
||||
|
||||
typedef NullType ArgList;
|
||||
typedef Tuple<Type> ThisTuple;
|
||||
typedef Tuple<Type> TupleType;
|
||||
typedef Tuple<NullType> ThisType;
|
||||
typedef Tuple<NullType> Tail;
|
||||
enum { SIZE = 0 };
|
||||
|
||||
|
|
@ -200,6 +201,16 @@ namespace typelist{
|
|||
|
||||
Tuple (HeadType const&, Tail const&) { }
|
||||
Tuple () { }
|
||||
|
||||
template<uint> struct ShiftedTuple { typedef Tail Type;};
|
||||
template<uint> Tail& getShifted () { return *this; }
|
||||
template<uint> NullType& getAt () { return getHead(); }
|
||||
|
||||
TupleType&
|
||||
tupleCast ()
|
||||
{
|
||||
return reinterpret_cast<TupleType&> (*this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -212,20 +223,52 @@ namespace typelist{
|
|||
typedef typename Prepend<TY,TailType>::Tuple Type;
|
||||
|
||||
typedef Node<TY,TYPES> ArgList;
|
||||
typedef Tuple<Type> ThisTuple;
|
||||
typedef Tuple<Type> TupleType;
|
||||
typedef Tuple<ArgList> ThisType;
|
||||
typedef Tuple<TYPES> Tail;
|
||||
enum { SIZE = count<ArgList>::value };
|
||||
|
||||
Tuple ( TY a1 =TY()
|
||||
, Tail tail =Tail()
|
||||
)
|
||||
: Tuple<TYPES> (tail.getHead(), tail.getTail()),
|
||||
: Tail (tail.getHead(), tail.getTail()),
|
||||
val_(a1)
|
||||
{ }
|
||||
|
||||
TY & getHead() { return val_; }
|
||||
Tail& getTail() { return static_cast<Tail&> (*this); }
|
||||
|
||||
|
||||
template<uint i>
|
||||
class ShiftedTuple
|
||||
{
|
||||
typedef typename Tuple::Type OurType_;
|
||||
typedef typename Shifted<OurType_,i>::Type ShiftedTypes_;
|
||||
public:
|
||||
typedef Tuple<typename ShiftedTypes_::List> Type;
|
||||
};
|
||||
|
||||
template<uint i>
|
||||
typename ShiftedTuple<i>::Type&
|
||||
getShifted ()
|
||||
{
|
||||
typedef typename ShiftedTuple<i>::Type Tail_I;
|
||||
return static_cast<Tail_I&> (*this);
|
||||
}
|
||||
|
||||
TupleType&
|
||||
tupleCast () ///< note makes this List-style Tuple appear as plain-flat Tuple
|
||||
{
|
||||
return reinterpret_cast<TupleType&> (*this);
|
||||
}
|
||||
|
||||
template<uint i>
|
||||
typename Shifted<Type,i>::Head&
|
||||
getAt ()
|
||||
{
|
||||
return getShifted<i>().getHead();
|
||||
}
|
||||
|
||||
private:
|
||||
TY val_;
|
||||
};
|
||||
|
|
@ -249,7 +292,8 @@ namespace typelist{
|
|||
typedef Types<T1,T2,T3,T4,T5,T6,T7,T8,T9> Type;
|
||||
|
||||
typedef typename Type::List ArgList;
|
||||
typedef Tuple<Type> ThisTuple;
|
||||
typedef Tuple<Type> TupleType;
|
||||
typedef Tuple<Type> ThisType;
|
||||
typedef Tuple<TailType> Tail;
|
||||
enum { SIZE = count<ArgList>::value };
|
||||
|
||||
|
|
@ -274,30 +318,10 @@ namespace typelist{
|
|||
{ }
|
||||
|
||||
using Tuple<ArgList>::getHead;
|
||||
using Tuple<ArgList>::getTail;
|
||||
|
||||
template<uint i>
|
||||
class ShiftedTuple
|
||||
{
|
||||
typedef typename Tuple::Type OurType_;
|
||||
typedef typename Shifted<OurType_,i>::Type ShiftedTypes_;
|
||||
public:
|
||||
typedef Tuple<typename ShiftedTypes_::List> Type;
|
||||
};
|
||||
|
||||
template<uint i>
|
||||
typename ShiftedTuple<i>::Type&
|
||||
getShifted ()
|
||||
Tail& getTail() ///< note makes the Tail appear as plain-flat shifted tuple
|
||||
{
|
||||
typedef typename ShiftedTuple<i>::Type Tail_I;
|
||||
return static_cast<Tail_I&> (*this);
|
||||
}
|
||||
|
||||
template<uint i>
|
||||
typename Shifted<Type,i>::Head&
|
||||
getAt ()
|
||||
{
|
||||
return getShifted<i>().getHead();
|
||||
return Tuple<ArgList>::getTail().tupleCast();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -307,7 +331,10 @@ namespace typelist{
|
|||
: Tuple<NullType>
|
||||
{
|
||||
enum { SIZE = 0 };
|
||||
typedef Tuple<NullType> TupleNull;
|
||||
typedef Tuple<NullType> TupNilList;
|
||||
typedef Tuple<Types<> > ThisType;
|
||||
typedef ThisType Tail;
|
||||
|
||||
|
||||
Tuple ( NullType =NullType()
|
||||
, NullType =NullType()
|
||||
|
|
@ -323,14 +350,8 @@ namespace typelist{
|
|||
|
||||
/** shortcut: allow copy construction from a tuple
|
||||
* which is rather defined by a list type */
|
||||
Tuple (Tuple<NullType> const&)
|
||||
Tuple (TupNilList const&)
|
||||
{ }
|
||||
|
||||
|
||||
template<uint> struct ShiftedTuple { typedef TupleNull Type; };
|
||||
|
||||
template<uint> TupleNull& getShifted () { return static_cast<TupleNull&> (*this); }
|
||||
template<uint> NullType& getAt () { return getHead(); }
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -342,12 +363,14 @@ namespace typelist{
|
|||
{
|
||||
typedef typename Shifted<TYPES,i>::Type Type;
|
||||
typedef typename Shifted<TYPES,i>::Head Head;
|
||||
typedef Tuple<Type> TupleType;
|
||||
};
|
||||
template<class TYPES>
|
||||
struct Shifted<Tuple<TYPES>, 0>
|
||||
{
|
||||
typedef typename Tuple<TYPES>::Type Type;
|
||||
typedef typename Tuple<TYPES>::HeadType Head;
|
||||
typedef Tuple<Type> TupleType;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ This code is heavily inspired by
|
|||
namespace lumiera {
|
||||
namespace typelist{
|
||||
|
||||
class NullType
|
||||
struct NullType
|
||||
{
|
||||
typedef NullType List;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ namespace test {
|
|||
typedef Types1::List L1; // starting from an existing Typelist...
|
||||
|
||||
typedef Tuple<L1> T_L1; // ListType based tuple type
|
||||
typedef Tuple<L1>::ThisTuple T1; // corresponding plain tuple type
|
||||
typedef Tuple<L1>::TupleType T1; // corresponding plain tuple type
|
||||
typedef Tuple<L1>::Type Type1; // extract the underlying type sequence
|
||||
|
||||
DISPLAY (Type1);
|
||||
|
|
@ -156,7 +156,7 @@ namespace test {
|
|||
void
|
||||
check_sub_tuple_types()
|
||||
{
|
||||
cout << "\t:\n\t: ---Head-and-Tail---\n";
|
||||
cout << "\t:\n\t: ---Sub-Tuple-Types----\n";
|
||||
|
||||
typedef Append<Types2::List, Types1::List>::List L2;
|
||||
|
||||
|
|
@ -167,12 +167,44 @@ namespace test {
|
|||
DISPLAY (Head);
|
||||
DISPLAY (Tail);
|
||||
|
||||
typedef T_L2::ThisTuple T2;
|
||||
typedef T_L2::TupleType T2;
|
||||
typedef Types<T2::HeadType> Head2;
|
||||
typedef T2::TailType Tail2;
|
||||
DISPLAY (T2);
|
||||
DISPLAY (Head2);
|
||||
DISPLAY (Tail2);
|
||||
|
||||
typedef Tuple<Types<> > NulT;
|
||||
typedef Tuple<NullType> NulL;
|
||||
|
||||
DISPLAY (T2::Type);
|
||||
DISPLAY (T2::TailType);
|
||||
DISPLAY (T2::TupleType);
|
||||
DISPLAY (T2::ThisType);
|
||||
DISPLAY (T2::Tail);
|
||||
DISPLAY (T2::ArgList);
|
||||
|
||||
DISPLAY (T_L2::Type);
|
||||
DISPLAY (T_L2::TailType);
|
||||
DISPLAY (T_L2::TupleType);
|
||||
DISPLAY (T_L2::ThisType);
|
||||
DISPLAY (T_L2::Tail);
|
||||
DISPLAY (T_L2::ArgList);
|
||||
|
||||
DISPLAY (NulT::Type);
|
||||
DISPLAY (NulT::TailType);
|
||||
DISPLAY (NulT::TupleType);
|
||||
DISPLAY (NulT::ThisType);
|
||||
DISPLAY (NulT::Tail);
|
||||
DISPLAY (NulT::ArgList);
|
||||
|
||||
DISPLAY (NulL::Type);
|
||||
DISPLAY (NulL::TailType);
|
||||
DISPLAY (NulL::TupleType);
|
||||
DISPLAY (NulL::ThisType);
|
||||
DISPLAY (NulL::Tail);
|
||||
DISPLAY (NulL::ArgList);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -209,32 +241,52 @@ namespace test {
|
|||
void
|
||||
check_tuple_creation()
|
||||
{
|
||||
Tuple<Types1> tup11 (Num<1>() );
|
||||
Tuple<Types1> tup12 (Num<1>(11), Num<3>() );
|
||||
cout << "\t:\n\t: ---creating-Tuples---\n";
|
||||
|
||||
Tuple<Types1> tup1 ;
|
||||
Tuple<Types1> tup11 (Num<1>(11) );
|
||||
Tuple<Types1> tup12 (Num<1>(), Num<3>(33) );
|
||||
Tuple<Types1> tup13 (Num<1>(11), Num<3>(33), Num<5>() );
|
||||
DUMPVAL (tup1);
|
||||
DUMPVAL (tup11);
|
||||
DUMPVAL (tup12);
|
||||
DUMPVAL (tup13);
|
||||
|
||||
Tuple<Types<int,int,Num<11> > > tup2 = tuple::make(41,42, Num<11>(43));
|
||||
DISPLAY (tup2::ThisType);
|
||||
typedef Tuple<Types<int,int,Num<11> > > Tup2;
|
||||
Tup2 tup2 = tuple::make(41,42, Num<11>(43));
|
||||
DISPLAY (Tup2);
|
||||
DUMPVAL (tup2);
|
||||
|
||||
tup2::TailType tup22 = tup2.getTail();
|
||||
DISPLAY (tup22);
|
||||
typedef Tup2::Tail Tup22;
|
||||
Tup22 tup22 = tup2.getTail();
|
||||
DISPLAY (Tup22);
|
||||
DUMPVAL (tup22);
|
||||
|
||||
tup22::TailType tup222 = tup22.getTail();
|
||||
DISPLAY (tup222);
|
||||
typedef Tup2::Tail::Tail Tup222;
|
||||
Tup222 tup222 = tup22.getTail();
|
||||
DISPLAY (Tup222);
|
||||
DUMPVAL (tup222);
|
||||
|
||||
Tuple<NullType> nullT = tuple::makeNullTuple();
|
||||
typedef Tuple<Types<> > T0T;
|
||||
typedef Tuple<NullType> T0L;
|
||||
T0T nullT = tuple::makeNullTuple();
|
||||
T0L nullL = tuple::makeNullTuple();
|
||||
T0T nulTcpy (nullL);
|
||||
T0T& nulTref (nullL.tupleCast());
|
||||
DISPLAY (T0T);
|
||||
DISPLAY (T0L);
|
||||
DUMPVAL (nullT);
|
||||
DUMPVAL (nullL);
|
||||
DUMPVAL (nulTcpy);
|
||||
DUMPVAL (nulTref);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
check_tuple_copy()
|
||||
{
|
||||
cout << "\t:\n\t: ---copy-operations---\n";
|
||||
|
||||
Tuple<Types1> tup1 (Num<1>(11), Num<3>(33), Num<5>() );
|
||||
|
||||
Tuple<Types1> tup11 (tup1);
|
||||
|
|
@ -255,33 +307,45 @@ namespace test {
|
|||
void
|
||||
check_value_access()
|
||||
{
|
||||
cout << "\t:\n\t: ---value-access---\n";
|
||||
|
||||
typedef Append<Types2::List, Types2::List>::List T2424;
|
||||
Tuple<T2424> tupX;
|
||||
DISPLAY (tupX);
|
||||
typedef Tuple<T2424> TupX;
|
||||
TupX tupX;
|
||||
DISPLAY (TupX);
|
||||
DUMPVAL (tupX);
|
||||
|
||||
Tuple<Types2> tu2;
|
||||
DUMPVAL (tu2);
|
||||
tuple::element<1>(tu2).o_ = 55;
|
||||
tu2.getHead() = Num<2>(55);
|
||||
tuple::element<1>(tu2).o_ = 5;
|
||||
tu2.getHead() = Num<2> (tu2.getAt<1>().o_);
|
||||
DUMPVAL (tu2);
|
||||
|
||||
|
||||
tupX.getShifted<2>() = tu2;
|
||||
DUMPVAL (tupX);
|
||||
|
||||
typedef Shifted<tupX::ThisTuple,2> T4;
|
||||
typedef Shifted<TupX::TupleType,2>::TupleType T4;
|
||||
T4 t4 (tupX.getShifted<2>());
|
||||
DISPLAY (T4);
|
||||
DUMPVAL (t4);
|
||||
|
||||
DISPLAY (tupX::Type)
|
||||
DISPLAY (tupX::TailType)
|
||||
DISPLAY (tupX::ThisTuple)
|
||||
DISPLAY (TupX::Type)
|
||||
DISPLAY (TupX::TailType)
|
||||
DISPLAY (TupX::ThisType)
|
||||
DISPLAY (TupX::TupleType)
|
||||
|
||||
typedef tupX::ThisTuple T2424T;
|
||||
DISPLAY (T2424T::Type)
|
||||
DISPLAY (T2424T::TailType)
|
||||
DISPLAY (T2424T::ThisTuple)
|
||||
typedef TupX::TupleType TupT;
|
||||
DISPLAY (TupT::Type)
|
||||
DISPLAY (TupT::TailType)
|
||||
DISPLAY (TupT::ThisType)
|
||||
DISPLAY (TupT::TupleType)
|
||||
|
||||
TupT tupXcopy (tupX);
|
||||
DUMPVAL (tupXcopy);
|
||||
|
||||
TupT& tupXcast (tupX.tupleCast());
|
||||
DUMPVAL (tupXcast);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue