From 47ce7ad96b0abcc7eee14c95b0ef62008ae1f179 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 28 Jan 2016 15:37:35 +0100 Subject: [PATCH] research finished: build a (compiletime) tuple from runtime sequence ...should document this by a unit-test --- research/try.cpp | 16 -- tests/12metaprogramming.tests | 5 + tests/library/meta/tuple-record-init-test.cpp | 156 ++++++++++++++++++ 3 files changed, 161 insertions(+), 16 deletions(-) create mode 100644 tests/library/meta/tuple-record-init-test.cpp diff --git a/research/try.cpp b/research/try.cpp index 21c4e95a7..2d42e76ff 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -71,21 +71,6 @@ using lib::time::Time; using std::string; using std::tuple; -////////////////////////TODO reworked for function-closure.hpp -template -struct SomeArgs - { - - template - using IdxSelector = typename lib::meta::func::PartiallyInitTuple::template IndexMapper; - - static Tuple - doIt (Tuple const& args) - { - return lib::meta::TupleConstructor (args); - } - }; -////////////////////////TODO reworked for function-closure.hpp @@ -145,7 +130,6 @@ main (int, char**) cout << buildTuple (args) < (urgs) <::doIt(std::make_tuple("hui", 88)) <-<2>-+ diff --git a/tests/library/meta/tuple-record-init-test.cpp b/tests/library/meta/tuple-record-init-test.cpp new file mode 100644 index 000000000..50232de36 --- /dev/null +++ b/tests/library/meta/tuple-record-init-test.cpp @@ -0,0 +1,156 @@ +/* + TupleRecordInit(Test) - to build a tuple from a GenNode sequence + + Copyright (C) Lumiera.org + 2016, 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 tuple-record-init-test.cpp + ** Metaprogramming: how to unload the contents of a runtime typed variant sequence + ** into ctor arguments of a (compile time typed) tuple. This involves two problems + ** - how to combine iteration, compile-time indexing and run-time access. + ** - how to overcome the runtime-to-compiletime barrier, using a pre-generated + ** double-dispatch (visitor). + ** + ** The concrete problem prompting this research is the necessity to receive + ** a command invocation parameter tuple from a Record + ** + */ + +typedef unsigned int uint; + +#include "lib/test/run.hpp" +#include "lib/symbol.hpp" +#include "lib/time/timevalue.hpp" +#include "lib/meta/tuple-record-init.hpp" +#include "lib/format-cout.hpp" +#include "lib/format-util.hpp" + +#include +#include + +using lib::Literal; +using lib::Variant; +using lib::idi::EntryID; +using lib::diff::Rec; +using lib::diff::MakeRec; +using lib::diff::GenNode; +using lib::meta::Types; +using lib::meta::Tuple; +using lib::meta::buildTuple; +using lib::time::TimeVar; +using lib::time::Time; + +using std::string; +using std::tuple; + +namespace lib { +namespace meta { +namespace test { + +////////////////////////TODO reworked for function-closure.hpp +template +struct SomeArgs + { + + template + using IdxSelector = typename lib::meta::func::PartiallyInitTuple::template IndexMapper; + + static Tuple + doIt (Tuple const& args) + { + return lib::meta::TupleConstructor (args); + } + }; +////////////////////////TODO reworked for function-closure.hpp + + + + +#define SHOW_TYPE(_TY_) \ + cout << "typeof( " << STRINGIFY(_TY_) << " )= " << lib::meta::typeStr<_TY_>() < ::value) + EVAL_PREDICATE(is_arithmetic ::value) + EVAL_PREDICATE(is_floating_point::value) + EVAL_PREDICATE(is_nonFloat ::value) + + EVAL_PREDICATE(GenNodeAccessor ::allow_Conversion ::value) + EVAL_PREDICATE(GenNodeAccessor::allow_Conversion::value) + EVAL_PREDICATE(GenNodeAccessor::allow_Conversion::value) + EVAL_PREDICATE(GenNodeAccessor::allow_Conversion ::value) + EVAL_PREDICATE(GenNodeAccessor::allow_Conversion ::value) + EVAL_PREDICATE(GenNodeAccessor::allow_Conversion::value) + EVAL_PREDICATE(GenNodeAccessor ::allow_Conversion ::value) + EVAL_PREDICATE(GenNodeAccessor ::allow_Conversion::value) + EVAL_PREDICATE(GenNodeAccessor::allow_Conversion::value) + EVAL_PREDICATE(GenNodeAccessor::allow_Conversion::value) + EVAL_PREDICATE(GenNodeAccessor ::allow_Conversion::value) + + cout <; + using UgglyTypes = Types, string, int, int64_t, double, TimeVar>; + + Rec args = MakeRec().scope("lalü", 42); + Rec urgs = MakeRec().scope("lalü", "lala", 12, 34, 5.6, Time(7,8,9)); + + cout << args < (args) < (urgs) <::doIt(std::make_tuple("hui", 88)) <