From a9f480cf415b107c3b41f10ff1f2b421b382c85a Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Thu, 18 Jun 2015 02:46:50 +0200 Subject: [PATCH] some work --- include/Continuable.h | 24 ++++++++++++++++++------ test.cpp | 2 ++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/Continuable.h b/include/Continuable.h index 5d5f9ae..6c3c5b6 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -42,7 +42,7 @@ namespace detail /// The internal state of the continuable /// which is used to save certain internal types. template - struct ContinuableState; + class ContinuableState; // ContinuableImpl forward declaration. template @@ -71,12 +71,18 @@ namespace detail struct is_continuable<_ContinuableImpl<_STy, _CTy>> : public std::true_type { }; - template - struct ContinuableState, _Proxy> + template + class ContinuableState<_WeakContextType> { + template + friend class _ContinuableImpl; + + typedef std::weak_ptr<_WeakContextType> weak_reference_t; }; - typedef ContinuableState, void> DefaultContinuableState; + struct WeakContext { }; + + typedef ContinuableState DefaultContinuableState; // MSVC 12 has issues to detect the parameter pack otherwise. template @@ -117,6 +123,8 @@ namespace detail typedef Callback<_ATy...> CallbackFunction; typedef std::function&&)> ForwardFunction; + typedef typename ContinuableState<_STy...>::weak_reference_t WeakReference; + private: /// Functional which expects a callback that is inserted from the Continuable /// to chain everything together @@ -124,6 +132,8 @@ namespace detail bool _released; + WeakReference _reference; + template void invoke(_CTy&& callback) { @@ -168,7 +178,8 @@ namespace detail _ContinuableImpl(_ContinuableImpl const&) = delete; /// Move construct - _ContinuableImpl(_ContinuableImpl&& right) + template + _ContinuableImpl(_ContinuableImpl<_RSTy, Callback<_ATy...>>&& right) : _released(right._released), _callback_insert(std::move(right._callback_insert)) { right._released = true; @@ -205,7 +216,8 @@ namespace detail _ContinuableImpl& operator= (_ContinuableImpl const&) = delete; /// Move construct assign - _ContinuableImpl& operator= (_ContinuableImpl&& right) + template + _ContinuableImpl& operator= (_ContinuableImpl<_RSTy, Callback<_ATy...>>&& right) { _released = right._released; right._released = true; diff --git a/test.cpp b/test.cpp index 5298ae4..a3b9b96 100644 --- a/test.cpp +++ b/test.cpp @@ -222,6 +222,8 @@ int main(int /*argc*/, char** /*argv*/) //// Here we go //entry(); + + std::cout << "ok" << std::endl; return 0; }