diff --git a/research/try.cpp b/research/try.cpp index b5f66742a..a880d5f14 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -76,21 +76,23 @@ using std::string; cout << "typeof( " << STRINGIFY(_TY_) << " )= " << lib::meta::typeStr<_TY_>() < void -fun1 (int i, int j, int k) +fun2 (ARGS... is) { - cout << "FUN-1: "< @@ -140,7 +142,7 @@ dispatch (ARGS...args) enum {SIZ = sizeof...(args)}; using First = typename BuildIndexSeq<3>::Ascending; - using Next = typename BuildIndexSeq<3>::OffsetBy<3>; + using Next = typename BuildIdxIter::template After<3>; return dispatch_ (First(),Next(), args...); } @@ -149,8 +151,9 @@ dispatch (ARGS...args) int main (int, char**) { - fun1 (1,2,3); - fun2 (4,5,6); + fun2 (1,2,3,4); + fun2 (5,6); + fun2 (); auto arr = dispatch (2,3,4,5,6,7,8); cout << util::join(arr) << "| " << showSizeof(arr) < { - using TypeIdxIterator = typename IndexIter::Seq; + /** meta-sequence to drive instantiation of the ElmMapper */ + using SequenceIterator = typename BuildIdxIter::Ascending; protected: template - TupleConstructor (SRC values, IndexSeq*) + TupleConstructor (SRC values, IndexSeq) : Tuple (_ElmMapper_, idx>{values}...) { } @@ -191,7 +192,7 @@ namespace meta { public: template TupleConstructor (SRC values) - : TupleConstructor (values, (TypeIdxIterator*)nullptr) + : TupleConstructor (values, SequenceIterator()) { } }; diff --git a/src/lib/meta/variadic-helper.hpp b/src/lib/meta/variadic-helper.hpp index 7b57bd71a..97896dcd8 100644 --- a/src/lib/meta/variadic-helper.hpp +++ b/src/lib/meta/variadic-helper.hpp @@ -57,7 +57,6 @@ #include "lib/meta/typeseq-util.hpp" #include "lib/meta/util.hpp" - namespace lib { namespace meta { @@ -124,6 +123,27 @@ namespace meta { +//////////////////////////TICKET #943 : temporary workaround until full C++14 compliance (need constexpr) + template + constexpr inline X const& + max (X const& a, X const& b) + { + return a < b? b : a; + } + + template + constexpr inline X const& + min (X const& a, X const& b) + { + return b < a? b : a; + } +//////////////////////////TICKET #943 : temporary workaround until full C++14 compliance (need constexpr) + + + + + + /** Hold a sequence of index numbers as template parameters */ template struct IndexSeq @@ -132,7 +152,10 @@ namespace meta { using AppendElm = IndexSeq; }; - /** build an `IndexSeq<0, 1, 2, ..., n-1>` */ + /** + * build regular sequences of index number + * e.g. `IndexSeq<0, 1, 2, ..., n-1>` + */ template struct BuildIndexSeq { @@ -141,36 +164,83 @@ namespace meta { template using OffsetBy = typename BuildIndexSeq::template OffsetBy::template AppendElm; - template - using FilledWith = typename BuildIndexSeq::template FilledWith::template AppendElm; + template + using FilledWith = typename BuildIndexSeq::template FilledWith::template AppendElm; + + template + using First = typename BuildIndexSeq::Ascending; + + template + using After = typename BuildIndexSeq::template OffsetBy; }; template<> struct BuildIndexSeq<0> { - using Ascending = IndexSeq<>; + using Empty = IndexSeq<>; - template - using OffsetBy = IndexSeq<>; + using Ascending = Empty; template - using FilledWith = IndexSeq<>; + using OffsetBy = Empty; + + template + using FilledWith = Empty; + + template + using First = Empty; + + template + using After = Empty; }; - /** build an index number sequence from a structured reference type */ - template - struct IndexIter; - + /** + * build a sequence of index numbers based on a type sequence + */ + template + struct BuildIdxIter + { + enum {SIZ = sizeof...(TYPES) }; + using Builder = BuildIndexSeq; + + using Ascending = typename Builder::Ascending; + + template + using OffsetBy = typename Builder::template OffsetBy; + + template + using FilledWith = typename Builder::template FilledWith; + + template + using First = typename Builder::template First; + + template + using After = typename Builder::template After; + }; + /** build an index number sequence from a type sequence */ template - struct IndexIter> + struct BuildIdxIter> { /////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 Builder = BuildIndexSeq; - using Seq = typename BuildIndexSeq::Ascending; + using Ascending = typename Builder::Ascending; + + template + using OffsetBy = typename Builder::template OffsetBy; + + template + using FilledWith = typename Builder::template FilledWith; + + template + using First = typename Builder::template First; + + template + using After = typename Builder::template After; };