diff --git a/research/try.cpp b/research/try.cpp index 80dec741c..9da803893 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -51,6 +51,16 @@ using std::endl; class Interface { public: + Interface(){} + Interface(Interface const& o) { cout << "COPY.CT from "<<&o<<" !!!\n"; } + Interface(Interface const&& o) { cout << "MOVE.CT from "<<&o<<" !!!\n"; } + + Interface& + operator= (Interface const& o) { cout << "COPY= from "<<&o<<" !!!\n"; return *this; } + Interface& + operator= (Interface const&& o) { cout << "MOVE= from "<<&o<<" !!!\n"; return *this; } + + virtual ~Interface() { } virtual string op() const =0; }; @@ -73,42 +83,57 @@ class Impl }; template -void -diagnostics (string id, const void* addr) +string +showRefRRefVal() { - cout << id << "\n" - << "invoked with.. " << lib::test::showType() - << "\n Address ... " << addr - << "\n is lRef ... " << std::is_lvalue_reference::value - << "\n is rRef ... " << std::is_rvalue_reference::value + return std::is_lvalue_reference::value? " by REF" + : std::is_rvalue_reference::value? " by MOVE": " VAL"; +} + +template +void +diagnostics (string id, X const& x) +{ + cout << "--"<() + << "\n Address ... " << &x + << showRefRRefVal() << "\n" ; } +template +void +diagnostics (string id, X const& x, XS const&... xs) +{ + diagnostics (id, x); + diagnostics (id, xs...); +} void invoke (Interface const& ref) { using Ty = Interface const&; - diagnostics ("Invoke", &ref); + diagnostics ("Invoke", ref); cout << "instanceof Impl?" << bool(INSTANCEOF(Impl, &ref)) <<"\n"; - cout << ref.op(); + cout << "________________" + << ref.op() + << "____\n"; } -template +template void -indirect_1 (FUN fun, A&& a) +indirect_1 (FUN fun, ARG&&... args) { - diagnostics ("Indirect-1", &a); - fun (std::forward (a)); + diagnostics ("Indirect-1", args...); + fun (std::forward (args)...); } -template +template void -indirect_2 (FUN fun, A&& a) +indirect_2 (FUN fun, ARG&&... args) { - diagnostics ("Indirect-2", &a); - indirect_1 (fun, std::forward (a)); + diagnostics ("Indirect-2", args...); + indirect_1 (fun, std::forward(args)...); }