From 23cc0597b5588a33d6cb8ea26948ee4efb2b2529 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 27 Sep 2017 00:26:04 +0200 Subject: [PATCH] Investigation: basically working yet convoluted solution draft --- research/try.cpp | 72 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 20 deletions(-) diff --git a/research/try.cpp b/research/try.cpp index 06a602aa9..9682dfeed 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -86,41 +86,73 @@ fun2 (int const& i, int const& j, int const& k) } -template -struct Idx - { }; + /** Hold a sequence of index numbers as template parameters */ + template + struct IndexSeq + { + template + using AppendElm = IndexSeq; + }; + + /** build an `IndexSeq<0, 1, 2, ..., n-1>` */ + template + struct BuildIndexSeq + { + using Ascending = typename BuildIndexSeq::Ascending::template AppendElm; + + template + using FilledWith = typename BuildIndexSeq::template FilledWith::template AppendElm; + }; + + template<> + struct BuildIndexSeq<0> + { + using Ascending = IndexSeq<>; + + template + using FilledWith = IndexSeq<>;; + }; -template -struct IdxSeq - { - template - struct First + +template +struct Pick; + +template +struct Pick + : Pick + { + static auto + get (ARG, ARGS ...args) { - - }; + return Pick::get (args...); + } }; -template -struct Pick - { - template - Pick (ARGS... args) - { } +template +struct Pick<0, ARG,ARGS...> + { + static ARG + get (ARG a, ARGS...) + { + return a; + } }; template void -dispatch (Idx, ARGS...args) +dispatch_ (IndexSeq, ARGS...args) { - fun1 (Pick{args...} ...); + fun1 (Pick::get(args...) ...); } template void dispatch (ARGS...args) { - using First = typename IdxSeq::template First<3>; + enum {SIZ = sizeof...(args)}; + + using First = typename BuildIndexSeq<3>::Ascending; dispatch_ (First{}, args...); } @@ -132,7 +164,7 @@ main (int, char**) fun1 (1,2,3); fun2 (4,5,6); -// dispatch (2,3,4,5,6,7,8); + dispatch (2,3,4,5,6,7,8); cout << "\n.gulp.\n";