basic tuple creation and outline of the remainder of the test

This commit is contained in:
Fischlurch 2009-06-21 02:03:22 +02:00
parent 30ac23fb28
commit 231834d2e9
4 changed files with 189 additions and 6 deletions

View file

@ -253,6 +253,7 @@ namespace typelist{
typedef Tuple<TailType> Tail;
enum { SIZE = count<ArgList>::value };
/** standard ctor: create from values */
Tuple ( T1 a1 =T1()
, T2 a2 =T2()
, T3 a3 =T3()
@ -266,6 +267,12 @@ namespace typelist{
: Tuple<ArgList>(a1, Tuple<TailType>(a2,a3,a4,a5,a6,a7,a8,a9))
{ }
/** shortcut: allow copy construction from a tuple
* which is rather defined by a list type */
Tuple (Tuple<ArgList> const& listTuple)
: Tuple<ArgList> (listTuple)
{ }
using Tuple<ArgList>::getHead;
using Tuple<ArgList>::getTail;
@ -455,6 +462,64 @@ namespace typelist{
public:
static const bool value = (sizeof(Yes_t)==sizeof(typename Check<TUP>::It));
};
/** Trait template detecting especially tuples
* built directly on top of a Typelist */
template<typename TUP>
class is_TupleListType
{
template<class X>
struct Check
{
enum{ result = sizeof(No_t)};
};
template<class N>
struct Check<Tuple<N> >
{
template<class H, class T>
Yes_t static check(Node<H,T>*);
Yes_t static check(NullType*);
No_t static check(...);
enum{ result = sizeof(check( (N*)0)) };
};
public:
static const bool value = (sizeof(Yes_t)== Check<TUP>::result);
};
/** Trait template to discern plain tuples and list-type tuples */
template<typename TUP>
struct is_TuplePlain
{
static const bool value = is_Tuple<TUP>::value
&& !is_TupleListType<TUP>::value;
};
/** Trait template detecting an empty tuple type */
template<typename TUP>
class is_NullTuple
{
template<class X>
struct Check
{
enum{ result = sizeof(No_t)};
};
template<class TY>
struct Check<Tuple<TY> >
{
Yes_t check(Types<>*);
Yes_t check(NullType*);
No_t check(...);
enum{ result = sizeof(check( (TY*)0)) };
};
public:
static const bool value = (sizeof(Yes_t)== Check<TUP>::result);
};
/**

View file

@ -40,6 +40,7 @@
#include "lib/meta/tuple.hpp"
#include <boost/utility/enable_if.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/format.hpp>
#include <string>
@ -47,6 +48,7 @@ using std::string;
using boost::str;
using boost::format;
using boost::enable_if;
using boost::lexical_cast;
using util::unConst;
@ -69,6 +71,12 @@ namespace test {
return str ( (o.o_==i? constElm:changedElm) % int(o.o_));
}
string
showTupElement(int i)
{
return lexical_cast<string>(i);
}
template<typename T>
string
showTupElement(T x)
@ -135,7 +143,8 @@ namespace test {
/* ===== printing Tuple types and contents ===== */
template<typename TYPES>
string
typename enable_if< is_TuplePlain<Tuple<TYPES> >,
string >::type
showDump (Tuple<TYPES> const& tuple)
{
typedef BuildTupleAccessor<TYPES,TupleElementDisplayer> BuildAccessor;
@ -144,8 +153,22 @@ namespace test {
return "...Tuple" + Displayer(tuple).dump();
}
template<typename TYPES>
typename enable_if< is_TupleListType<Tuple<TYPES> >,
string >::type
showDump (Tuple<TYPES> const& tuple)
{
typedef typename Tuple<TYPES>::Type TypeSeq;
Tuple<TypeSeq> plainTuple (tuple);
typedef BuildTupleAccessor<TypeSeq, TupleElementDisplayer> BuildAccessor;
typedef typename BuildAccessor::Accessor Displayer;
return "...Tuple" + Displayer(plainTuple).dump();
}
template<typename TUP>
typename enable_if< is_Tuple<TUP>,
typename enable_if< is_TuplePlain<TUP>,
string >::type
showType ()
{
@ -154,6 +177,16 @@ namespace test {
+ DumpPrinter::print();
}
template<typename TUP>
typename enable_if< is_TupleListType<TUP>,
string >::type
showType ()
{
typedef InstantiateChained<typename TUP::ArgList, Printer, NullP> DumpPrinter;
return "TYPES-[]"
+ DumpPrinter::print();
}
// see the macros DISPLAY and DUMPVAL defined in typelist-diagnostics.hpp

View file

@ -77,8 +77,17 @@ namespace test {
/*************************************************************************
* @test //////////////////////////////////////////
* - building combinations and permutations
* @test Cover various aspects of the type tuple.
* Check the metaprogramming behaviour...
* - build a tuple type from an existing typelist
* - create sub tuple types and types with shifted parameters
* Additionally, check the behaviour when creating tuple instances
* at runtime. Effectively, these are simple record types, which are
* synthesised by recursion over the related typelist.
* - create tuples from a list of values
* - copy and copy construct
* - access the "head" and access values by numeric index
* - create a tuple with shifted values
*/
class TypeTuple_test : public Test
{
@ -86,8 +95,12 @@ namespace test {
run (Arg)
{
check_diagnostics();
UNIMPLEMENTED ("verify type tuples");
check_tuple_from_Typelist();
check_sub_tuple_types();
check_shiftedTuple();
check_tuple_creation();
check_tuple_copy();
check_value_access();
}
@ -113,6 +126,71 @@ namespace test {
DUMPVAL (Tup1()); // prints the contents
DUMPVAL (tup1x);
}
void
check_tuple_from_Typelist()
{
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>::Type Type1; // extract the underlying type sequence
DISPLAY (Type1);
DISPLAY (T_L1);
DISPLAY (T1);
T_L1 tup1 (Num<1>(8)); // both flavours can be created at runtime
T1 tup2 (Num<1>(9)); // (and we provide an explicit value for the 1st element)
DUMPVAL (tup1);
DUMPVAL (tup2);
typedef Tuple<Node<int, L1> > Prepend;
DISPLAY (Prepend); // another ListType based tuple created by prepending
Prepend prepend (22, tup2); // but note: the ListType based tuple has an "(head,tail)" style ctor
DUMPVAL (prepend); // ... and in construction, tup2 has been copied and coerced to ListType style
}
void
check_sub_tuple_types()
{
UNIMPLEMENTED ("verify head and tail type");
}
void
check_shiftedTuple()
{
UNIMPLEMENTED ("verify shifted type tuple");
}
void
check_tuple_creation()
{
UNIMPLEMENTED ("verify tuple creation");
}
void
check_tuple_copy()
{
UNIMPLEMENTED ("verify tuple copying and assignment");
}
void
check_value_access()
{
UNIMPLEMENTED ("verify tuple value access");
}
};

View file

@ -133,6 +133,13 @@ namespace typelist{
static string print () { return str( fmt % uint(Fl) % BASE::print()); }
};
template<class BASE>
struct Printer<int, BASE> ///< display the presence of a plain int in the typelist
: BASE
{
static string print () { return str( fmt % 'i' % BASE::print()); }
};
/** call the debug-print for a typelist