From ef3f494ba204c9d9bfdec7eb9870bb3a53ff112e Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Wed, 15 Jul 2015 00:58:30 +0200 Subject: [PATCH] more experiments --- test.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/test.cpp b/test.cpp index 0b4e577..49b08e8 100644 --- a/test.cpp +++ b/test.cpp @@ -147,7 +147,7 @@ public: MoveCaptureLamda(std::function&& functional, Capture&&... capture) : _functional(std::move(functional)), _capture(std::make_tuple(std::forward(capture)...)) { } - void invoke(Args&&... args) + void operator() (Args&&... args) { _functional(std::move(std::get(_capture))..., std::forward(args)...); } @@ -170,7 +170,7 @@ public: MoveCaptureLamda(std::function&& functional, Capture&&... capture) : _functional(std::move(functional)), _capture(std::make_tuple(std::forward(capture)...)) { } - ReturnType invoke(Args&&... args) + ReturnType operator() (Args&&... args) { return _functional(std::move(std::get(_capture))..., std::forward(args)...); } @@ -209,6 +209,49 @@ public: } }; +template +class copymove +{ + T _content; + + bool consumed; + + copymove& move(copymove& right) + { + // _content = std::move(right._content); + return *this; + } + + copymove& move(copymove&& right) + { + // _content = std::move(right._content); + return *this; + } + +public: + copymove(copymove const& right) : consumed(false) + { + // move(right._content); + } + + copymove(T& right) : consumed(false) + { + _content = std::move(right); + } + + copymove& operator= (copymove& right) + { + return move(right); + } + + T get() + { + assert(!consumed && "already consumed!"); + consumed = true; + return move(right._content); + } +}; + int main(int /*argc*/, char** /*argv*/) { /* @@ -506,7 +549,8 @@ int main(int /*argc*/, char** /*argv*/) // std::function fntest = std::move(fn); - MoveCaptureLamda>, fu::identity, fu::sequence_of_t<1>, fu::sequence_of_t<0>> capture([](std::unique_ptr) + MoveCaptureLamda>, fu::identity, fu::sequence_of_t<1>, fu::sequence_of_t<0>> capture( + [](std::unique_ptr capture, int arg) { int i = 0; @@ -515,8 +559,16 @@ int main(int /*argc*/, char** /*argv*/) }, std::unique_ptr(new int(90))); - capture.invoke(); + capture(1); + + capture(2); + + std::unique_ptr uptr(new int(90)); + copymove> mycapture(std::move(uptr)); + auto capt = [mycapture] + { + + }; - capture.invoke(); return 0; }