From 02b84cd6dc62c973a2f0b15b681d6fd6829bdb41 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 23 Jan 2016 17:30:43 +0100 Subject: [PATCH] research: solution skeleton, without type conversion working with those variadic index sequences is quite nasty! Seemingly you'd always need a 2-step type rebinding, tried several hours now to avoid that, sorry. What still needs to be settled is the actual problem of type conversions; we do not want to be confined just to the small selection of types allowed within GenNode, rather we want automatic type promotion when it comes to extracting values into ctor args! --- research/try.cpp | 100 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 93 insertions(+), 7 deletions(-) diff --git a/research/try.cpp b/research/try.cpp index 5d2c9f6d9..64085d3fd 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -54,24 +54,104 @@ typedef unsigned int uint; #include "lib/format-cout.hpp" #include "lib/format-util.hpp" -#include #include using lib::Literal; +using lib::diff::Rec; +using lib::diff::MakeRec; using lib::diff::GenNode; using lib::meta::Types; -//using lib::meta::NullType; using lib::meta::Tuple; +using lib::meta::IndexSeq; +using lib::meta::BuildIndexSeq; using lib::time::TimeVar; using lib::time::Time; -using util::stringify; -using util::join; -using std::function; using std::string; using std::tuple; +template +struct Pick; + +template +struct Pick, i> + { + using Type = typename lib::meta::Shifted, i>::Head; + }; + + + +template +struct ElementMapper; + +template +struct ElementMapper> + { + template + using TargetType = typename Pick, i>::Type; + + + template + struct Access + { + Rec const& values; + + operator TargetType () + { + GenNode const& elm = values.child(i); + return elm.data.get>(); + } + + }; + + }; + + + +template +struct IdxIter; + +template +struct IdxIter> + { + /////TODO as long as Types is not variadic (#987), we need to strip NullType here (instead of just using sizeof...(TYPES) + enum {SIZ = lib::meta::count::List>::value }; + + using Seq = typename BuildIndexSeq::Ascending; + }; + + + +template +class TupleBuilder; + +template +class TupleBuilder> + : public Tuple + { + template + using PickArg = typename ElementMapper::template Access; + + + public: + template + TupleBuilder (SRC values) + : Tuple (PickArg{values}...) + { } + }; + + + +template +Tuple +buildTuple (SRC values) +{ + using IndexSeq = typename IdxIter::Seq; + + return TupleBuilder (values); +} + @@ -84,10 +164,16 @@ int main (int, char**) { using NiceTypes = Types; - using UgglyTypes = Types; + using UgglyTypes = Types; - Tuple uggs("lalü", "lala", 12, 34, 5.6, Time(7,8,9)); + using Uggs = Tuple; + +// Rec args = MakeRec().scope("lalü", "lala", 12, 34, 5.6, Time(7,8,9)); + Rec args = MakeRec().scope("lalü", 42); + cout << args < (args); cout << uggs <