diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index 9277521de..f895638ce 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -49,6 +49,7 @@ test_lib_SOURCES = \ $(testlib_srcdir)/mainsuite.cpp \ $(testlib_srcdir)/meta/typelist-test.cpp \ $(testlib_srcdir)/meta/typelist-manip-test.cpp \ + $(testlib_srcdir)/meta/typeseq-manip-test.cpp \ $(testlib_srcdir)/meta/type-tuple-test.cpp \ $(testlib_srcdir)/meta/function-composition-test.cpp \ $(testlib_srcdir)/meta/function-closure-test.cpp \ diff --git a/tests/lib/meta/typelist-manip-test.cpp b/tests/lib/meta/typelist-manip-test.cpp index 9fa1a73f8..b015c000a 100644 --- a/tests/lib/meta/typelist-manip-test.cpp +++ b/tests/lib/meta/typelist-manip-test.cpp @@ -86,6 +86,7 @@ namespace test { * print them for debugging purpose. * - append lists, single elements and NullType * in various combinations + * - manipulations like splice, get end, dissect * - filtering out some types from a typelist by * using a "predicate template" (metafunction) * - building combinations and permutations @@ -99,6 +100,8 @@ namespace test { check_apply (); check_append (); check_splice (); + check_s_last (); + check_dissect(); check_filter (); check_prefix (); check_distribute(); @@ -222,6 +225,52 @@ namespace test { } + void + check_s_last() + { + typedef SplitLast::Type Elm; + typedef SplitLast::List Prefix; + + typedef Types::List ElmL; + + DISPLAY (Prefix); + DISPLAY (ElmL); + + typedef SplitLast::Type Elm1; + typedef SplitLast::List NPrefix; + + DISPLAY (NPrefix); + DISPLAY (Types); + + typedef SplitLast::Type Nil; + typedef SplitLast::List NList; + + DISPLAY (NList); + DISPLAY (Types); + } + + + void + check_dissect() + { + typedef Append::List LL; + DISPLAY (LL); + + typedef Dissect::List List; DISPLAY(List); + typedef Dissect::First First; DISPLAY(First); + typedef Dissect::Tail Tail; DISPLAY(Tail); + typedef Dissect::Prefix Prefix; DISPLAY(Prefix); + typedef Dissect::Last Last; DISPLAY(Last); + + typedef Dissect::Head Head; + typedef Dissect::End End; + + typedef Types HeadEnd; DISPLAY(HeadEnd); + } + + + + template struct AddConst2 { typedef X Type; }; template struct AddConst2 > { typedef Num Type; }; diff --git a/tests/lib/meta/typeseq-manip-test.cpp b/tests/lib/meta/typeseq-manip-test.cpp new file mode 100644 index 000000000..76fa87387 --- /dev/null +++ b/tests/lib/meta/typeseq-manip-test.cpp @@ -0,0 +1,177 @@ +/* + TypeSeqManip(Test) - simple manipulations on type sequences + + Copyright (C) Lumiera.org + 2008, 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-manip-test.cpp + ** verify the proper working of simple type sequence manipulations. + ** Here, "type sequence" denotes an instance of the template Types from + ** typelist.hpp . While this template is the entry point to type list metaprogramming, + ** in many cases it is useful on its own for specifying a fixed collection of types, e.g. + ** for building a tuple type. Thus, while more complicated manipulations typically rely + ** on typelists, sometimes we need simple manipulations working directly on type sequences. + ** These are covered here in a similar fashion as the typelist manipulators. + ** + ** @see typeseq-util.hpp + ** @see typelist-util.hpp + ** @see typelist-manip-test.cpp + ** + */ + + +#include "lib/test/run.hpp" +#include "lib/meta/typeseq-util.hpp" +#include "lib/meta/typelist-util.hpp" +#include "meta/typelist-diagnostics.hpp" +//#include "lib/util.hpp" + +#include +#include + +using ::test::Test; +using std::string; +using std::cout; + + +namespace lumiera { +namespace typelist{ +namespace test { + + + namespace { // test data + + + + typedef Types< Num<1> + , Num<2> + , Num<3> + > Types1; + typedef Types< Num<7> + , Num<8> + , Num<9> + > Types2; + + + // see also the CountDown template in typelist-diagnostics.hpp... + + } // (End) test data + + + + + + + /************************************************************************** + * @test check the basic utilities for manipulating (fixed) type sequences. + * - re-build an sequence from a type list + * - prepend a type to a given type sequence + * - create shifted sequences + * - dissect a sequence to extract head, tail, prefix, last element + */ + class TypeSeqManipl_test : public Test + { + virtual void + run (Arg) + { + check_buildSeq(); + check_prepend (); + check_shift (); + check_split (); + } + + + void + check_buildSeq () + { + typedef Append::List LL; + DISPLAY (LL); + + typedef Types::Seq Seq; + DISPLAY (Seq); + DISPLAY (Seq::List); + + typedef Types::Seq NulS; + DISPLAY (NulS); + } + + + void + check_prepend () + { + typedef Prepend, Types1> Prepend1; + DISPLAY(Prepend1); + + typedef Prepend Prepend2; + DISPLAY(Prepend2); + + typedef Prepend, Types<> > Prepend3; + DISPLAY(Prepend3); + + typedef Prepend > Prepend4; + DISPLAY(Prepend4); + } + + + void + check_shift () + { + typedef Append::List LL; + typedef Types::Seq Seq; + + typedef Shifted::Type Seq_0; DISPLAY (Seq_0); + typedef Shifted::Type Seq_1; DISPLAY (Seq_1); + typedef Shifted::Type Seq_2; DISPLAY (Seq_2); + typedef Shifted::Type Seq_3; DISPLAY (Seq_3); + typedef Shifted::Type Seq_4; DISPLAY (Seq_4); + + typedef Types::Head> Head_2; DISPLAY (Head_2); + } + + + void + check_split () + { + typedef Append::List LL; + typedef Types::Seq Seq; + DISPLAY (Seq); + + typedef Split::List List; DISPLAY(List); + typedef Split::First First; DISPLAY(First); + typedef Split::Tail Tail; DISPLAY(Tail); + typedef Split::Prefix Prefix; DISPLAY(Prefix); + typedef Split::Last Last; DISPLAY(Last); + + typedef Split::Head Head; + typedef Split::End End; + + typedef Types HeadEnd; DISPLAY(HeadEnd); + } + + + }; + + + /** Register this test class... */ + LAUNCHER (TypeSeqManipl_test, "unit common"); + + + +}}} // namespace lumiera::typelist::test