From e2c4dec015a0dc601a809632a1c1c877eb1b983e Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 19 Mar 2017 01:26:48 +0100 Subject: [PATCH] Function-Tools: verify coverage of reference and rvalue reference types the usual suspects... turns out we need specialisations for those too, even while in most cases those special reference type won't make it far, and just degrade to function pointer --- research/try.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/research/try.cpp b/research/try.cpp index d8bc331b4..5cfddcddc 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -57,6 +57,7 @@ using std::placeholders::_1; using std::bind; using std::string; using std::tuple; +using std::move; ////////////////############# Investigation of implementation variants namespace lib { @@ -87,6 +88,12 @@ namespace meta { : _FuZ { }; + /** Specialisation for passing a rvalue reference */ + template + struct _FuZ + : _FuZ + { }; + /** Specialisation to deal with member pointer to function */ template struct _FuZ @@ -157,6 +164,36 @@ showType (F) SHOW_TYPE (Sig); } +template +void +showRef (F&) + { + using Sig = typename _FuZ::Sig; + + SHOW_TYPE (F); + SHOW_TYPE (Sig); + } + +template +void +showCRef (F&) + { + using Sig = typename _FuZ::Sig; + + SHOW_TYPE (F); + SHOW_TYPE (Sig); + } + +template +void +showRRef (F&&) + { + using Sig = typename _FuZ::Sig; + + SHOW_TYPE (F); + SHOW_TYPE (Sig); + } + using Fun = function; using Fuk = function; @@ -192,10 +229,47 @@ main (int, char**) cout << "\n\n-------\n"; + showRef (funny); + showRef (lambda); + showRef (f7); + + showCRef (funny); + showCRef (lambda); + showCRef (f7); + + showRRef (move(lambda)); + showRRef (move(f7)); + + showType (move(&funny)); + showType (move(lambda)); + showType (move(f7)); + + Fun& funRef = f1; + Funky& funkyRef = funk; + Fun const& funCRef = f1; + Funky const& funkyCRef = funk; + showType (funRef); + showType (funkyRef); + showType (funCRef); + showType (funkyCRef); + + cout << "\n\n-------\n"; + SHOW_TYPE (decltype(&Funky::operator())); SHOW_TYPE (decltype(lambda)); SHOW_TYPE (_FuZ::Sig); + SHOW_TYPE (_FuZ::Sig); + SHOW_TYPE (_FuZ::Sig); + SHOW_TYPE (_FuZ::Sig); + SHOW_TYPE (_FuZ::Sig); + SHOW_TYPE (_FuZ::Sig); + SHOW_TYPE (_FuZ::Sig); + + using Siggy = _FuZ::Sig; + SHOW_TYPE (_FuZ::Sig); + SHOW_TYPE (_FuZ::Sig); + SHOW_TYPE (_FuZ::Sig); cout << "\n.gulp.\n";