From 8f865183e363947bf67621c1e61d37d3eae9a7dc Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 19 Nov 2017 00:35:10 +0100 Subject: [PATCH] Research: how to build a meta predicate to perform this detection --- research/try.cpp | 66 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/research/try.cpp b/research/try.cpp index 6a18af5c0..bf14e0ec9 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -45,14 +45,15 @@ typedef unsigned int uint; #include "lib/format-cout.hpp" #include "lib/format-util.hpp" -//#include "lib/meta/function.hpp" +#include "lib/meta/duck-detector.hpp" #include "lib/test/test-helper.hpp" #include #include #include -//using lib::meta::_Fun; +using lib::meta::No_t; +using lib::meta::Yes_t; using lib::test::showSizeof; using std::function; @@ -65,38 +66,81 @@ using std::string; #define SHOW_TYPE(_TY_) \ cout << "typeof( " << STRINGIFY(_TY_) << " )= " << lib::meta::typeStr<_TY_>() <()))> -struct Probe +class Cheesy { }; +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); - fun2 (); + fun1 (); - using Ty1 = decltype (fun1(12)); - using Ty2 = decltype (fun2()); + 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 ); - cout << "siz-1="<< sizeof(Ty1)<