diff --git a/src/lib/meta/util.hpp b/src/lib/meta/util.hpp index 13f40acf2..4a9c12425 100644 --- a/src/lib/meta/util.hpp +++ b/src/lib/meta/util.hpp @@ -189,6 +189,34 @@ namespace meta { + namespace { + /** + * check for the necessary precondition, not sufficient. + * @remark Detecting the possibility of structured binding reliably will be possible with C++23. + * Even a partial implementation, covering only `std::tuple_element` is surprisingly + * complicated, due to the built-in limit checks. What do do with a `tuple<>`? + */ + template::value> + struct _Probe_TupleProtocol + { }; + } + template + using enable_if_TupleProtocol = std::void_t<_Probe_TupleProtocol>>; + + /** Trait template to detect a »tuple-like« type, + * which can be used in structured bindings. + * @note we check only one precondition: the support for `std::tuple_size` + */ + template + struct is_Structured + : std::false_type + { }; + + template + struct is_Structured> + : std::true_type + { }; + /** Trait template for detecting a typelist type. * For example, this allows to write specialisations diff --git a/src/steam/engine/feed-manifold.hpp b/src/steam/engine/feed-manifold.hpp index 52183e62f..3291f3d16 100644 --- a/src/steam/engine/feed-manifold.hpp +++ b/src/steam/engine/feed-manifold.hpp @@ -107,23 +107,19 @@ namespace engine { using lib::meta::is_TernaryFun; using std::remove_reference_t; using lib::meta::enable_if; + using lib::meta::is_Structured; + using std::is_pointer; + using std::is_reference; + using std::tuple_size_v; using std::void_t; using std::__and_; using std::__not_; - template - struct is_Structured - : std::false_type - { }; - template - struct is_Structured>> - : std::true_type - { }; template struct is_Value - : __and_<__not_> - ,__not_> + : __and_<__not_> + ,__not_> ,__not_> ,std::is_default_constructible ,std::is_copy_assignable @@ -132,13 +128,17 @@ namespace engine { template struct is_Buffer - : __and_<__not_> - ,__not_> + : __and_<__not_> + ,__not_> ,std::is_default_constructible ,__not_<_Fun> > { }; + + + + /** Helper to pick up the parameter dimensions from the processing function * @remark this is the rather simple yet common case that media processing * is done by a function, which takes an array of input and output diff --git a/tests/library/meta/meta-utils-test.cpp b/tests/library/meta/meta-utils-test.cpp index 016322be7..f33f8eb81 100644 --- a/tests/library/meta/meta-utils-test.cpp +++ b/tests/library/meta/meta-utils-test.cpp @@ -20,20 +20,21 @@ #include "lib/test/run.hpp" #include "lib/meta/util.hpp" #include "lib/meta/typelist.hpp" +#include "lib/hetero-data.hpp" +#include "lib/test/diagnostic-output.hpp" #include -#include -using std::cout; -using std::endl;/////////////////////////TODO - +#include +#include namespace lib { namespace meta { namespace test { using std::string; - - + using std::array; + using std::tuple; + using std::pair; @@ -42,6 +43,7 @@ namespace test { * @test verify basic type trait and metaprogramming helpers. * - marker types to tell which overload the compiler picks * - simple trait to detect the possibility of a string conversion + * - trait to detect (possibly) structured types (»tuple-like«) * - trait to detect a typelist type */ class MetaUtils_test : public Test @@ -53,6 +55,7 @@ namespace test { verify_genericTypeDisplay(); detect_stringConversion(); + detect_tupleProtocol(); detect_typeList(); } @@ -162,6 +165,42 @@ namespace test { } + void + detect_tupleProtocol() + { + // verify arbitrary non-structured types + CHECK ((not is_Structured())); + CHECK ((not is_Structured())); + CHECK ((not is_Structured())); + CHECK ((not is_Structured())); + CHECK ((not is_Structured())); + CHECK ((not is_Structured())); + CHECK ((not is_Structured())); + CHECK ((not is_Structured())); + CHECK ((not is_Structured())); + CHECK ((not is_Structured())); + CHECK ((not is_Structured())); + CHECK ((not is_Structured())); + CHECK ((not is_Structured())); + CHECK ((not is_Structured())); + CHECK ((not is_Structured())); + CHECK ((not is_Structured())); + CHECK ((not is_Structured())); + CHECK ((not is_Structured >())); + + // the following indeed support C++ tuple protocol + CHECK (( is_Structured >())); + CHECK (( is_Structured >())); + CHECK (( is_Structured >())); + CHECK (( is_Structured >())); + CHECK (( is_Structured >())); + CHECK (( is_Structured >())); + CHECK (( is_Structured >())); + CHECK (( is_Structured >())); + CHECK (( is_Structured >())); + } + + //-------------------------------------------------TEST-types-- typedef Types< int diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 40b8ae106..58be2cc87 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -92049,6 +92049,52 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ MetaUtils_test::detect_tupleProtocol() +

+ + +
+
+
+
+
+
+
+