From 01937f973609a0c704e8c05ed8ba680db18eb32b Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 23 Nov 2017 17:49:43 +0100 Subject: [PATCH] Research: possiblity to detect a generic Lambda? --- research/try.cpp | 60 +++------------------- tests/library/iter-tree-explorer-test.cpp | 7 +++ wiki/thinkPad.ichthyo.mm | 62 +++++++++++++++++++++++ 3 files changed, 77 insertions(+), 52 deletions(-) diff --git a/research/try.cpp b/research/try.cpp index 21c2c0fd5..cf4dbbed4 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -34,31 +34,21 @@ // 3/17 - generic function signature traits, including support for Lambdas // 9/17 - manipulate variadic templates to treat varargs in several chunks // 11/17 - metaprogramming to detect the presence of extension points +// 11/17 - detect generic lambda /** @file try.cpp - ** Metaprogramming: how to detect that a type in question exposes a free function extension point. - ** Since such an extension point is typically injected alongside with the type exposing the extension - ** point and intended to be picked up by ADL, all we have to check is if it is valid to invoke the - ** extension point function with an instance of the target type. - ** - ** There are two difficulties to overcome, though - ** - a function might return void. And while we may indeed pick up `void` from `decltype(expr)`, - ** there is not much we can do with a void type. The remedy is just to use this type as template - ** parameter on another template instantiation, which fails if this type can not legally be formed. - ** - we do not know how to get a value of the type to probe, in order to feed it into the extension - ** point function. Fortunately, the `std::declval()` function was included into the C++ language - ** for this very purpose. + ** Metaprogramming: is it possible to distinguish a generic lambda from something not a function at all? */ typedef unsigned int uint; #include "lib/format-cout.hpp" #include "lib/format-util.hpp" -#include "lib/meta/duck-detector.hpp" +#include "lib/meta/function.hpp" #include "lib/test/test-helper.hpp" -#include +//#include #include #include @@ -108,49 +98,15 @@ class Fishy friend void fun1 (Fishy&); }; -#define META_DETECT_EXTENSION_POINT(_FUN_) \ - template \ - class HasExtensionPoint_##_FUN_ \ - { \ - template()))>\ - struct Probe \ - { }; \ - \ - template \ - static Yes_t check(Probe * ); \ - template \ - static No_t check(...); \ - \ - public: \ - static const bool value = (sizeof(Yes_t)==sizeof(check(0))); \ - }; - - -META_DETECT_EXTENSION_POINT (fun) -META_DETECT_EXTENSION_POINT (fun1) int main (int, char**) { - fun1 (23); - fun1 (); + auto lamb1 = [](int i) { return double(i) / (i*i); }; + auto lamb2 = [](auto i) { return double(i) / (i*i); }; - SHOW_EXPR ( HasExtensionPoint_fun::value ); - SHOW_EXPR ( HasExtensionPoint_fun1::value ); - SHOW_EXPR ( HasExtensionPoint_fun1::value ); - SHOW_EXPR ( HasExtensionPoint_fun1::value ); - SHOW_EXPR ( HasExtensionPoint_fun1::value ); - SHOW_EXPR ( HasExtensionPoint_fun1::value ); - SHOW_EXPR ( HasExtensionPoint_fun1::value ); - SHOW_EXPR ( HasExtensionPoint_fun1::value ); - SHOW_EXPR ( HasExtensionPoint_fun1::value ); - - SHOW_EXPR ( HasExtensionPoint_fun1::value ); - SHOW_EXPR ( HasExtensionPoint_fun1::value ); - SHOW_EXPR ( HasExtensionPoint_fun1::value ); - SHOW_EXPR ( HasExtensionPoint_fun1::value ); - SHOW_EXPR ( HasExtensionPoint_fun1::value ); + SHOW_TYPE (decltype(lamb1)); + SHOW_TYPE (decltype(lamb2)); cout << "\n.gulp.\n"; diff --git a/tests/library/iter-tree-explorer-test.cpp b/tests/library/iter-tree-explorer-test.cpp index 39692241f..224048279 100644 --- a/tests/library/iter-tree-explorer-test.cpp +++ b/tests/library/iter-tree-explorer-test.cpp @@ -311,6 +311,13 @@ namespace test{ treeExplore(CountDown{5}) .expand([](CountDown const& core){ return CountDown{ yield(core) - 1}; }) ); + +#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #1117 + verify_treeExpandingIterator( + treeExplore(CountDown{5}) + .expand([](auto & it){ return CountDown{ *it - 1}; }) + ); +#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #1117 } diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 504819676..2c84efa8d 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -5188,6 +5188,68 @@ + + + + + + + + +

+ _fun<FUN>::Sig scheitert +

+ + +
+ +
+ + + + + + +

+ das ist aber unpraktisch.... +

+ + +
+ +
+ + + + + + +

+ ....also ist es gradezu natürlich, +

+

+ einen Expand-Funktor als generisches Lambda zu schreiben! +

+ + +
+
+ + + + + + + + + + + + + + + +