diff --git a/include/Continuable.h b/include/Continuable.h index ee69d16..c4e26d5 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -38,15 +38,9 @@ void debug(std::string const& m) namespace detail { - // ContinuableState forward declaration. - /// The internal state of the continuable - /// which is used to save certain internal types. - template - class ContinuableState; - - // ContinuableImpl forward declaration. - template - class _ContinuableImpl; + // Continuable forward declaration. + template + class Continuable; // convert_void_to_continuable forward declaration. /// Corrects void return types from functional types which should be @@ -67,23 +61,10 @@ namespace detail struct is_continuable : public std::false_type { }; - template - struct is_continuable<_ContinuableImpl<_STy, _CTy>> + template + struct is_continuable> : public std::true_type { }; - template - class ContinuableState<_WeakContextType> - { - template - friend class _ContinuableImpl; - - typedef std::weak_ptr<_WeakContextType> weak_reference_t; - }; - - struct WeakContext { }; - - typedef ContinuableState DefaultContinuableState; - // MSVC 12 has issues to detect the parameter pack otherwise. template struct unary_chainer<_NextRTy, fu::identity<_NextATy...>> @@ -138,19 +119,17 @@ namespace detail } }; - template - class _ContinuableImpl, std::function> + template + class Continuable { - // Make all instances of _ContinuableImpl to a friend. - template - friend class _ContinuableImpl; + // Make all templates of Continuable to a friend. + template + friend class Continuable; public: 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 @@ -158,8 +137,6 @@ namespace detail bool _released; - WeakReference _reference; - template void invoke(_CTy&& callback) { @@ -201,11 +178,10 @@ namespace detail public: /// Deleted copy construct - _ContinuableImpl(_ContinuableImpl const&) = delete; + Continuable(Continuable const&) = delete; /// Move construct - template - _ContinuableImpl(_ContinuableImpl<_RSTy, Callback<_ATy...>>&& right) + Continuable(Continuable&& right) : _released(right._released), _callback_insert(std::move(right._callback_insert)) { right._released = true; @@ -213,18 +189,18 @@ namespace detail // Construct through a ForwardFunction template - _ContinuableImpl(_FTy&& callback_insert) + Continuable(_FTy&& callback_insert) : _callback_insert(std::forward<_FTy>(callback_insert)), _released(false) { } - template - _ContinuableImpl(_FTy&& callback_insert, _ContinuableImpl<_RSTy, _RCTy>&& right) + template + Continuable(_FTy&& callback_insert, Continuable<_RATy...>&& right) : _callback_insert(std::forward<_FTy>(callback_insert)), _released(right._released) { right._released = true; } /// Destructor which calls the dispatch chain if needed. - ~_ContinuableImpl() + ~Continuable() { // Dispatch everything. if (!_released) @@ -238,12 +214,10 @@ namespace detail } /// Deleted copy assign - template - _ContinuableImpl& operator= (_ContinuableImpl const&) = delete; + Continuable& operator= (Continuable const&) = delete; /// Move construct assign - template - _ContinuableImpl& operator= (_ContinuableImpl<_RSTy, Callback<_ATy...>>&& right) + Continuable& operator= (Continuable&& right) { _released = right._released; right._released = true; @@ -288,7 +262,7 @@ namespace detail } template - _ContinuableImpl& _wrap_all(_CTy&&...) + Continuable& _wrap_all(_CTy&&...) { typedef multiple_all_chainer<_CTy...> type; @@ -298,14 +272,14 @@ namespace detail /// Placeholder template auto all(_CTy&&... functionals) - -> _ContinuableImpl& + -> Continuable& { return *this; } /// Placeholder template - _ContinuableImpl& some(size_t const count, _CTy&&...) + Continuable& some(size_t const count, _CTy&&...) { return *this; } @@ -313,7 +287,7 @@ namespace detail /// Placeholder template auto any(_CTy&&... functionals) - -> _ContinuableImpl& // FIXME gcc build &-> decltype(some(1, std::declval<_CTy>()...)) + -> Continuable& // FIXME gcc build &-> decltype(some(1, std::declval<_CTy>()...)) { // Equivalent to invoke `some` with count 1. return some(1, std::forward<_CTy>(functionals)...); @@ -321,14 +295,14 @@ namespace detail /* /// Validates the Continuable - inline _ContinuableImpl& Validate() + inline Continuable& Validate() { _released = false; return *this; } /// Invalidates the Continuable - inline _ContinuableImpl& Invalidate() + inline Continuable& Invalidate() { _released = true; return *this; @@ -339,7 +313,7 @@ namespace detail template<> struct convert_void_to_continuable { - typedef _ContinuableImpl> type; + typedef Continuable<> type; template static type invoke(Fn functional, Args&&... args) @@ -355,10 +329,10 @@ namespace detail } }; - template - struct convert_void_to_continuable<_ContinuableImpl<_State, _CTy>> + template + struct convert_void_to_continuable> { - typedef _ContinuableImpl<_State, _CTy> type; + typedef Continuable<_CTy...> type; template static type invoke(Fn functional, Args&&... args) @@ -367,17 +341,10 @@ namespace detail return functional(std::forward(args)...); } }; -} -/// A continuable provides useful methods to react on the result of callbacks -/// and allows to chain multiple callback calls to a chain. -template -using Continuable = detail::_ContinuableImpl< - detail::DefaultContinuableState, - Callback>; + /// A continuable provides useful methods to react on the result of callbacks + /// and allows to chain multiple callback calls to a chain. -namespace detail -{ template struct ContinuableFactory; @@ -399,6 +366,9 @@ namespace detail } // detail +template +using Continuable = detail::Continuable; + /// Wraps a functional object which expects a r-value callback as argument into a continuable. /// The callable is invoked when the continuable shall continue. /// For example: