diff --git a/include/asyncpp/core.h b/include/asyncpp/core.h index 401c176..60e76d1 100644 --- a/include/asyncpp/core.h +++ b/include/asyncpp/core.h @@ -6,7 +6,13 @@ #include "core/stream.h" #include "core/task.h" -#include "core/future.inl" -#include "core/misc.inl" #include "core/result.inl" #include "core/stream.inl" + +#include "core/future/map.inl" +#include "core/future/lazy.inl" +#include "core/future/and_then.inl" + +#ifdef asyncpp_timing +#include "core/future/timeout.inl" +#endif diff --git a/include/asyncpp/core/future.h b/include/asyncpp/core/future.h index 575a5ef..50fd9fd 100644 --- a/include/asyncpp/core/future.h +++ b/include/asyncpp/core/future.h @@ -2,6 +2,7 @@ #include +#include "misc.h" #include "result.h" #include "future.pre.h" @@ -28,19 +29,17 @@ namespace asyncpp /** * @brief Transform the result of this future. */ - template - inline auto map(X_lambda&& p_lambda) const &; - - /** - * @brief Transform the result of this future. - */ - template + template< + chaining_mode X_mode = copy, + typename X_lambda> inline auto map(X_lambda&& p_lambda) &; /** * @brief Transform the result of this future. */ - template + template< + chaining_mode X_mode = move, + typename X_lambda> inline auto map(X_lambda&& p_lambda) &&; public: @@ -48,21 +47,18 @@ namespace asyncpp * @brief Execute the given lambda after the future is finished and * wait for the future returned by the lambda. */ - template - inline auto and_then(X_lambda&& p_lambda) const &; - - /** - * @brief Execute the given lambda after the future is finished and - * wait for the future returned by the lambda. - */ - template + template< + chaining_mode X_mode = copy, + typename X_lambda> inline auto and_then(X_lambda&& p_lambda) &; /** * @brief Execute the given lambda after the future is finished and * wait for the future returned by the lambda. */ - template + template< + chaining_mode X_mode = move, + typename X_lambda> inline auto and_then(X_lambda&& p_lambda) &&; #ifdef asyncpp_timing @@ -72,15 +68,10 @@ namespace asyncpp * * This method is only enabled if timer.h is included before. */ - template - inline auto timeout(const duration& p_timeout) const &; - - /** - * @brief Throw an execption if the timeout has passed. - * - * This method is only enabled if timer.h is included before. - */ - template + template< + chaining_mode X_mode = copy, + typename X_base, + typename X_ratio> inline auto timeout(const duration& p_timeout) &; /** @@ -88,7 +79,10 @@ namespace asyncpp * * This method is only enabled if timer.h is included before. */ - template + template< + chaining_mode X_mode = move, + typename X_base, + typename X_ratio> inline auto timeout(const duration& p_timeout) &&; #endif }; diff --git a/include/asyncpp/core/future.inl b/include/asyncpp/core/future.inl deleted file mode 100644 index 9834fb1..0000000 --- a/include/asyncpp/core/future.inl +++ /dev/null @@ -1,186 +0,0 @@ -#pragma once - -#include "future.h" - -#include "future/map.inl" -#include "future/lazy.inl" -#include "future/and_then.inl" - -#ifdef asyncpp_timing -#include -#endif - -namespace asyncpp -{ - - /* base_future::map */ - - template< - typename T_value, - typename T_derived> - template< - typename X_lambda> - auto base_future - ::map(X_lambda&& p_lambda) const & - { - using lambda_type = X_lambda; - using map_type = __future::map_impl; - - auto& self = static_cast(*this); - - return map_type( - std::forward(self), - std::forward(p_lambda)); - } - - template< - typename T_value, - typename T_derived> - template< - typename X_lambda> - auto base_future - ::map(X_lambda&& p_lambda) & - { - using lambda_type = X_lambda; - using map_type = __future::map_impl; - - auto& self = static_cast(*this); - - return map_type( - std::forward(self), - std::forward(p_lambda)); - } - - template< - typename T_value, - typename T_derived> - template< - typename X_lambda> - auto base_future - ::map(X_lambda&& p_lambda) && - { - using lambda_type = X_lambda; - using map_type = __future::map_impl; - - auto& self = static_cast(*this); - - return map_type( - std::forward(self), - std::forward(p_lambda)); - } - - /* base_future::and_then */ - - template< - typename T_value, - typename T_derived> - template< - typename X_lambda> - auto base_future - ::and_then(X_lambda&& p_lambda) const & - { - using lambda_type = X_lambda; - using and_then_type = __future::and_then_impl; - - auto& self = static_cast(*this); - - return and_then_type( - std::forward(self), - std::forward(p_lambda)); - } - - template< - typename T_value, - typename T_derived> - template< - typename X_lambda> - auto base_future - ::and_then(X_lambda&& p_lambda) & - { - using lambda_type = X_lambda; - using and_then_type = __future::and_then_impl; - - auto& self = static_cast(*this); - - return and_then_type( - std::forward(self), - std::forward(p_lambda)); - } - - template< - typename T_value, - typename T_derived> - template< - typename X_lambda> - auto base_future - ::and_then(X_lambda&& p_lambda) && - { - using lambda_type = X_lambda; - using and_then_type = __future::and_then_impl; - - auto& self = static_cast(*this); - - return and_then_type( - std::forward(self), - std::forward(p_lambda)); - } - - /* base_future::timeout */ - - #ifdef asyncpp_timing - template< - typename T_value, - typename T_derived> - template< - typename X_base, - typename X_ratio> - auto base_future - ::timeout(const duration& p_timeout) const & - { - using timeout_type = timing::timeout; - - auto& self = static_cast(*this); - - return timeout_type( - std::forward(self), - p_timeout); - } - - template< - typename T_value, - typename T_derived> - template< - typename X_base, - typename X_ratio> - auto base_future - ::timeout(const duration& p_timeout) & - { - using timeout_type = timing::timeout; - - auto& self = static_cast(*this); - - return timeout_type( - std::forward(self), - p_timeout); - } - - template< - typename T_value, - typename T_derived> - template< - typename X_base, - typename X_ratio> - auto base_future - ::timeout(const duration& p_timeout) && - { - using timeout_type = timing::timeout; - - auto& self = static_cast(*this); - - return timeout_type( - std::forward(self), - p_timeout); - } - #endif - -} diff --git a/include/asyncpp/core/future/and_then.h b/include/asyncpp/core/future/and_then.h index 63d441b..e9ed584 100644 --- a/include/asyncpp/core/future/and_then.h +++ b/include/asyncpp/core/future/and_then.h @@ -10,10 +10,10 @@ namespace __future { template< typename T_future, typename T_lambda> - struct and_then_impl final : + struct and_then_future final : public base_future< decltype(std::declval()(std::declval::value_type>())), - and_then_impl + and_then_future > { public: @@ -23,7 +23,7 @@ namespace __future { using second_future_type = decltype(std::declval()(std::declval())); using second_future_type_ptr = std::unique_ptr; using value_type = typename second_future_type::value_type; - using this_type = and_then_impl; + using this_type = and_then_future; using base_future_type = base_future; using result_type = typename base_future_type::result_type; @@ -39,10 +39,13 @@ namespace __future { template< typename X_future, typename X_lambda> - inline and_then_impl( + inline and_then_future( X_future&& p_outer, X_lambda&& p_lambda); + inline and_then_future(and_then_future &&) = default; + inline and_then_future(and_then_future const &) = default; + public: /* future */ /** * @brief Poll the result from the future. diff --git a/include/asyncpp/core/future/and_then.inl b/include/asyncpp/core/future/and_then.inl index 4e1d737..2a611a0 100644 --- a/include/asyncpp/core/future/and_then.inl +++ b/include/asyncpp/core/future/and_then.inl @@ -1,11 +1,12 @@ #pragma once -#include "map.h" +#include "and_then.h" +#include "../future.h" namespace asyncpp { namespace __future { - /* and_then_impl */ + /* and_then_future */ template< typename T_future, @@ -13,8 +14,8 @@ namespace __future { template< typename X_future, typename X_lambda> - and_then_impl - ::and_then_impl( + and_then_future + ::and_then_future( X_future&& p_first, X_lambda&& p_lambda) : _first (std::forward(p_first)) @@ -24,8 +25,8 @@ namespace __future { template< typename T_future, typename T_lambda> - typename and_then_impl::result_type - and_then_impl + typename and_then_future::result_type + and_then_future ::poll() { while (true) @@ -45,4 +46,61 @@ namespace __future { } } + /* and_then_impl */ + + template< + chaining_mode X_mode, + typename X_self, + typename X_lambda> + auto and_then_impl(X_self&& p_self, X_lambda&& p_lambda) + { + using lambda_type = X_lambda; + using self_type = X_self; + using derived_type = typename std::decay_t::derived_type; + using derived_storage_type = storage_type_t; + using derived_ref_type = std::conditional_t< + std::is_const_v>, + derived_type const &, + derived_type &>; + using derived_forward_type = forward_type_t; + using and_then_future_type = __future::and_then_future; + + static_assert( + X_mode != ref || !std::is_rvalue_reference_v, + "Can not store rvalue reference as lvalue reference!"); + + auto& self = static_cast(p_self); + + return and_then_future_type( + std::forward(self), + std::forward (p_lambda)); + } + } } + +namespace asyncpp +{ + + /* future_base::and_then */ + + template< + typename T_value, + typename T_derived> + template< + chaining_mode X_mode, + typename X_lambda> + auto base_future + ::and_then(X_lambda&& p_lambda) & + { return __future::and_then_impl(*this, std::forward(p_lambda)); } + + template< + typename T_value, + typename T_derived> + template< + chaining_mode X_mode, + typename X_lambda> + auto base_future + ::and_then(X_lambda&& p_lambda) && + { return __future::and_then_impl(std::move(*this), std::forward(p_lambda)); } + +} diff --git a/include/asyncpp/core/future/lazy.h b/include/asyncpp/core/future/lazy.h index 552021e..ca50eab 100644 --- a/include/asyncpp/core/future/lazy.h +++ b/include/asyncpp/core/future/lazy.h @@ -9,16 +9,16 @@ namespace asyncpp { template - struct lazy_impl final : + struct lazy_future final : public base_future< decltype(std::declval()()), - lazy_impl + lazy_future > { public: using lambda_type = T_lambda; using value_type = decltype(std::declval()()); - using this_type = lazy_impl; + using this_type = lazy_future; using base_future_type = base_future; using result_type = typename base_future_type::result_type; @@ -30,9 +30,12 @@ namespace asyncpp * @brief Constructor. */ template - inline lazy_impl( + inline lazy_future( X_lambda&& p_lambda); + inline lazy_future(lazy_future &&) = default; + inline lazy_future(lazy_future const &) = default; + public: /* future */ /** * @brief Poll the result from the future. diff --git a/include/asyncpp/core/future/lazy.inl b/include/asyncpp/core/future/lazy.inl index 60b5f03..4747e67 100644 --- a/include/asyncpp/core/future/lazy.inl +++ b/include/asyncpp/core/future/lazy.inl @@ -8,18 +8,18 @@ namespace asyncpp namespace __future { - /* lazy_impl */ + /* lazy_future */ template template - lazy_impl::lazy_impl( + lazy_future::lazy_future( X_lambda&& p_lambda) : _lambda(std::forward(p_lambda)) { } template template - inline auto lazy_impl + inline auto lazy_future ::poll() -> std::enable_if_t< std::is_void_v, @@ -31,7 +31,7 @@ namespace asyncpp template template - inline auto lazy_impl + inline auto lazy_future ::poll() -> std::enable_if_t< !std::is_void_v, @@ -45,7 +45,7 @@ namespace asyncpp inline auto lazy(X_lambda&& p_lambda) { using lambda_type = X_lambda; - using lazy_type = __future::lazy_impl; + using lazy_type = __future::lazy_future; return lazy_type(std::forward(p_lambda)); } diff --git a/include/asyncpp/core/future/map.h b/include/asyncpp/core/future/map.h index 979c740..9a72f97 100644 --- a/include/asyncpp/core/future/map.h +++ b/include/asyncpp/core/future/map.h @@ -8,10 +8,10 @@ namespace __future { template< typename T_future, typename T_lambda> - struct map_impl final : + struct map_future final : public base_future< typename std::decay_t::value_type, - map_impl + map_future > { public: @@ -19,7 +19,7 @@ namespace __future { using lambda_type = T_lambda; using future_value_type = typename std::decay_t::value_type; using value_type = decltype(std::declval()(std::declval())); - using this_type = map_impl; + using this_type = map_future; using base_future_type = base_future; using result_type = typename base_future_type::result_type; @@ -34,10 +34,13 @@ namespace __future { template< typename X_future, typename X_lambda> - inline map_impl( + inline map_future( X_future&& p_future, X_lambda&& p_lambda); + inline map_future(map_future &&) = default; + inline map_future(map_future const &) = default; + public: /* future */ /** * @brief Poll the result from the future. diff --git a/include/asyncpp/core/future/map.inl b/include/asyncpp/core/future/map.inl index c03d292..9e67dd0 100644 --- a/include/asyncpp/core/future/map.inl +++ b/include/asyncpp/core/future/map.inl @@ -5,7 +5,7 @@ namespace asyncpp { namespace __future { - /* map_impl */ + /* map_future */ template< typename T_future, @@ -13,8 +13,8 @@ namespace __future { template< typename X_future, typename X_lambda> - map_impl - ::map_impl( + map_future + ::map_future( X_future&& p_future, X_lambda&& p_lambda) : _future(std::forward(p_future)) @@ -24,8 +24,8 @@ namespace __future { template< typename T_future, typename T_lambda> - typename map_impl::result_type - map_impl + typename map_future::result_type + map_future ::poll() { auto r = _future.poll(); @@ -34,4 +34,61 @@ namespace __future { : result_type::not_ready(); } + /* map_impl */ + + template< + chaining_mode X_mode, + typename X_self, + typename X_lambda> + auto map_impl(X_self&& p_self, X_lambda&& p_lambda) + { + using lambda_type = X_lambda; + using self_type = X_self; + using derived_type = typename std::decay_t::derived_type; + using derived_storage_type = storage_type_t; + using derived_ref_type = std::conditional_t< + std::is_const_v>, + derived_type const &, + derived_type &>; + using derived_forward_type = forward_type_t; + using map_future_type = __future::map_future; + + static_assert( + X_mode != ref || !std::is_rvalue_reference_v, + "Can not store rvalue reference as lvalue reference!"); + + auto& self = static_cast(p_self); + + return map_future_type( + std::forward(self), + std::forward (p_lambda)); + } + } } + +namespace asyncpp +{ + + /* future_base::map */ + + template< + typename T_value, + typename T_derived> + template< + chaining_mode X_mode, + typename X_lambda> + auto base_future + ::map(X_lambda&& p_lambda) & + { return __future::map_impl(*this, std::forward(p_lambda)); } + + template< + typename T_value, + typename T_derived> + template< + chaining_mode X_mode, + typename X_lambda> + auto base_future + ::map(X_lambda&& p_lambda) && + { return __future::map_impl(std::move(*this), std::forward(p_lambda)); } + +} diff --git a/include/asyncpp/core/future/timeout.inl b/include/asyncpp/core/future/timeout.inl new file mode 100644 index 0000000..b324da5 --- /dev/null +++ b/include/asyncpp/core/future/timeout.inl @@ -0,0 +1,63 @@ +#pragma once + +#include "../future.h" + +namespace asyncpp { +namespace __future { + + template< + chaining_mode X_mode, + typename X_self, + typename X_base, + typename X_ratio> + auto helper_timeout( + X_self&& p_self, + const duration& p_timeout) + { + using self_type = X_self; + using derived_type = typename std::decay_t::derived_type; + using derived_storage_type = storage_type_t; + using derived_ref_type = std::conditional_t< + std::is_const_v>, + derived_type const &, + derived_type &>; + using derived_forward_type = forward_type_t; + using timeout_type = timing::timeout; + + auto& self = static_cast(p_self); + + return timeout_type( + std::forward(self), + p_timeout); + } + +} } + +namespace asyncpp +{ + + /* future_base::timeout */ + + template< + typename T_value, + typename T_derived> + template< + chaining_mode X_mode, + typename X_base, + typename X_ratio> + auto base_future + ::timeout(const duration& p_timeout) & + { return __future::helper_timeout(*this, p_timeout); } + + template< + typename T_value, + typename T_derived> + template< + chaining_mode X_mode, + typename X_base, + typename X_ratio> + auto base_future + ::timeout(const duration& p_timeout) && + { return __future::helper_timeout(std::move(*this), p_timeout); } + +} diff --git a/include/asyncpp/core/misc.h b/include/asyncpp/core/misc.h index 4eede91..d85677a 100644 --- a/include/asyncpp/core/misc.h +++ b/include/asyncpp/core/misc.h @@ -1,28 +1,7 @@ -#pragma once +#pragma -#include +#include "misc/chaining.h" +#include "misc/timing.h" -namespace asyncpp -{ - - using clock = std::chrono::steady_clock; - - using time_point = clock::time_point; - - template - using duration = std::chrono::duration; - - /** - * @brief Get the current time point. - */ - inline time_point now(); - - /** - * @brief Returns the lowest of the two passed deadlines (if not null) - * or nullptr if no deadline was passed. - */ - inline const time_point * merge_deadlines( - const time_point * p_deadline_0, - const time_point * p_deadline_1); - -} +#include "misc/chaining.inl" +#include "misc/timing.inl" diff --git a/include/asyncpp/core/misc/chaining.h b/include/asyncpp/core/misc/chaining.h new file mode 100644 index 0000000..5baa167 --- /dev/null +++ b/include/asyncpp/core/misc/chaining.h @@ -0,0 +1,39 @@ +#pragma once + +namespace asyncpp +{ + + enum chaining_mode + { + move, + copy, + ref, + }; + + /** + * @brief Get the storage type of the passed type for the passed mode. + * + * move: T + * copy: T + * ref T & + */ + template + struct storage_type; + + /** + * @brief Get the forward type of the passed type for the passed mode. + * + * move: T && + * copy: T const & + * ref T & + */ + template + struct forward_type; + + template + using storage_type_t = typename storage_type::type; + + template + using forward_type_t = typename forward_type::type; + +} diff --git a/include/asyncpp/core/misc/chaining.inl b/include/asyncpp/core/misc/chaining.inl new file mode 100644 index 0000000..84a6002 --- /dev/null +++ b/include/asyncpp/core/misc/chaining.inl @@ -0,0 +1,34 @@ +#pragma once + +namespace asyncpp +{ + + /* storage_type */ + + template + struct storage_type + { using type = X_type; }; + + template + struct storage_type + { using type = X_type; }; + + template + struct storage_type + { using type = X_type&; }; + + /* forward_type */ + + template + struct forward_type + { using type = std::decay_t &&; }; + + template + struct forward_type + { using type = std::decay_t const &; }; + + template + struct forward_type + { using type = std::remove_reference_t &; }; + +} diff --git a/include/asyncpp/core/misc/timing.h b/include/asyncpp/core/misc/timing.h new file mode 100644 index 0000000..4eede91 --- /dev/null +++ b/include/asyncpp/core/misc/timing.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +namespace asyncpp +{ + + using clock = std::chrono::steady_clock; + + using time_point = clock::time_point; + + template + using duration = std::chrono::duration; + + /** + * @brief Get the current time point. + */ + inline time_point now(); + + /** + * @brief Returns the lowest of the two passed deadlines (if not null) + * or nullptr if no deadline was passed. + */ + inline const time_point * merge_deadlines( + const time_point * p_deadline_0, + const time_point * p_deadline_1); + +} diff --git a/include/asyncpp/core/misc.inl b/include/asyncpp/core/misc/timing.inl similarity index 91% rename from include/asyncpp/core/misc.inl rename to include/asyncpp/core/misc/timing.inl index 853448a..e335659 100644 --- a/include/asyncpp/core/misc.inl +++ b/include/asyncpp/core/misc/timing.inl @@ -1,11 +1,11 @@ #pragma once -#include "misc.h" +#include "timing.h" namespace asyncpp { - #ifndef __asyncpp_has_impl_timer_now + #ifndef __asyncpp_has_impl_timer_now time_point now() { return clock::now(); } #endif diff --git a/include/asyncpp/core/stream.inl b/include/asyncpp/core/stream.inl index 9eebd0f..17996e9 100644 --- a/include/asyncpp/core/stream.inl +++ b/include/asyncpp/core/stream.inl @@ -80,7 +80,7 @@ namespace asyncpp ::map(X_lambda&& p_lambda) const & { using lambda_type = X_lambda; - using map_type = __stream::map_impl; + using map_type = __stream::map_future; auto& self = static_cast(*this); @@ -98,7 +98,7 @@ namespace asyncpp ::map(X_lambda&& p_lambda) & { using lambda_type = X_lambda; - using map_type = __stream::map_impl; + using map_type = __stream::map_future; auto& self = static_cast(*this); @@ -116,7 +116,7 @@ namespace asyncpp ::map(X_lambda&& p_lambda) && { using lambda_type = X_lambda; - using map_type = __stream::map_impl; + using map_type = __stream::map_future; auto& self = static_cast(*this); diff --git a/include/asyncpp/core/stream/map.h b/include/asyncpp/core/stream/map.h index d20d1c4..ab69f49 100644 --- a/include/asyncpp/core/stream/map.h +++ b/include/asyncpp/core/stream/map.h @@ -8,10 +8,10 @@ namespace __stream { template< typename T_stream, typename T_lambda> - struct map_impl final : + struct map_future final : public base_stream< decltype(std::declval()(std::declval())), - map_impl + map_future > { public: @@ -19,7 +19,7 @@ namespace __stream { using lambda_type = T_lambda; using inner_value_type = typename stream_type::value_type; using value_type = decltype(std::declval()(std::declval())); - using this_type = map_impl; + using this_type = map_future; using base_stream_type = base_stream; using result_type = typename base_stream_type::result_type; @@ -34,7 +34,7 @@ namespace __stream { template< typename X_stream, typename X_lambda> - inline map_impl( + inline map_future( X_stream&& p_stream, X_lambda&& p_lambda); diff --git a/include/asyncpp/core/stream/map.inl b/include/asyncpp/core/stream/map.inl index 3235abe..c39e3c5 100644 --- a/include/asyncpp/core/stream/map.inl +++ b/include/asyncpp/core/stream/map.inl @@ -5,7 +5,7 @@ namespace asyncpp { namespace __stream { - /* map_impl */ + /* map_future */ template< typename T_stream, @@ -13,7 +13,7 @@ namespace __stream { template< typename X_stream, typename X_lambda> - map_impl::map_impl( + map_future::map_future( X_stream&& p_stream, X_lambda&& p_lambda) : _stream(std::forward(p_stream)) @@ -23,8 +23,8 @@ namespace __stream { template< typename T_stream, typename T_lambda> - typename map_impl::result_type - map_impl + typename map_future::result_type + map_future ::poll() { auto r = _stream.poll(); diff --git a/include/asyncpp/timing/impl/timer_impl.h b/include/asyncpp/timing/impl/timer_impl.h index 91dbe92..c0a4525 100644 --- a/include/asyncpp/timing/impl/timer_impl.h +++ b/include/asyncpp/timing/impl/timer_impl.h @@ -42,7 +42,7 @@ namespace timing { X_args&&... p_args); inline void idle( - const asyncpp::time_point * p_deadline); + const time_point * p_deadline); inline thread_lock_ptr_u init_thread(); }; @@ -70,7 +70,7 @@ namespace timing { owner_type& p_owner); inline void idle( - const asyncpp::time_point * p_deadline); + const time_point * p_deadline); inline thread_lock_ptr_u init_thread(); }; diff --git a/include/asyncpp/timing/impl/timer_impl.inl b/include/asyncpp/timing/impl/timer_impl.inl index da1f05a..0dce7a7 100644 --- a/include/asyncpp/timing/impl/timer_impl.inl +++ b/include/asyncpp/timing/impl/timer_impl.inl @@ -30,7 +30,7 @@ namespace __impl { { } template - void timer_impl::idle(const asyncpp::time_point * p_deadline) + void timer_impl::idle(const time_point * p_deadline) { { auto r = owner._registrations.lock(); @@ -63,7 +63,7 @@ namespace __impl { { } void timer_impl::idle( - const asyncpp::time_point * p_deadline) + const time_point * p_deadline) { } timer_impl::thread_lock_ptr_u diff --git a/include/asyncpp/timing/interval.inl b/include/asyncpp/timing/interval.inl index d6fe04e..8b1e17b 100644 --- a/include/asyncpp/timing/interval.inl +++ b/include/asyncpp/timing/interval.inl @@ -1,9 +1,8 @@ #pragma once -#include +#include "interval.h" #include "delay.inl" -#include "interval.h" namespace asyncpp { namespace timing { @@ -12,7 +11,7 @@ namespace timing { template interval::interval( - const asyncpp::duration& p_duration, + const ::asyncpp::duration& p_duration, time_point p_deadline) : interval(asyncpp::now() + p_duration, p_duration, p_deadline) { } @@ -20,7 +19,7 @@ namespace timing { template interval::interval( const time_point& p_at, - const asyncpp::duration& p_duration, + const ::asyncpp::duration& p_duration, time_point p_deadline) : _delay (p_at) , _duration(p_duration) @@ -36,7 +35,7 @@ namespace timing { { if ( _deadline.time_since_epoch().count() && _delay.deadline() >= _deadline - && asyncpp::now() >= _delay.deadline()) + && asyncpp::now() >= _delay.deadline()) return result_type::done(); auto ret = _delay.poll(); diff --git a/include/asyncpp/timing/timeout.h b/include/asyncpp/timing/timeout.h index f54c4a7..4fdc92b 100644 --- a/include/asyncpp/timing/timeout.h +++ b/include/asyncpp/timing/timeout.h @@ -68,7 +68,7 @@ namespace timing { template struct timeout final - : public __impl::timeout_impl> + : public __impl::timeout_impl> { public: using inner_type = T_inner; diff --git a/include/asyncpp/timing/timeout.inl b/include/asyncpp/timing/timeout.inl index b98f4b3..6c79e7f 100644 --- a/include/asyncpp/timing/timeout.inl +++ b/include/asyncpp/timing/timeout.inl @@ -1,7 +1,5 @@ #pragma once -#include - #include "timeout.h" namespace asyncpp { diff --git a/include/asyncpp/timing/timer.h b/include/asyncpp/timing/timer.h index de16d55..cca6831 100644 --- a/include/asyncpp/timing/timer.h +++ b/include/asyncpp/timing/timer.h @@ -39,7 +39,7 @@ namespace timing { * This method is called as soon as the runtime has nothing to do. * The passed deadline is the timepoint the method should return (or null if not set). */ - inline void idle(const asyncpp::time_point * p_deadline); + inline void idle(const time_point * p_deadline); /** * @brief This method is calld by the executor when a new thread needs to be initialized. diff --git a/include/asyncpp/timing/timer.inl b/include/asyncpp/timing/timer.inl index b35973f..a085ec9 100644 --- a/include/asyncpp/timing/timer.inl +++ b/include/asyncpp/timing/timer.inl @@ -1,7 +1,5 @@ #pragma once -#include - #include "timer.h" #include "delay.inl" @@ -21,7 +19,7 @@ namespace timing { { } template - void timer::idle(const asyncpp::time_point * p_deadline) + void timer::idle(const time_point * p_deadline) { auto now = asyncpp::now(); diff --git a/test/asyncpp/timing/timeout_tests.cpp b/test/asyncpp/timing/timeout_tests.cpp index 27d3449..15204a5 100644 --- a/test/asyncpp/timing/timeout_tests.cpp +++ b/test/asyncpp/timing/timeout_tests.cpp @@ -33,6 +33,12 @@ public: } }; +auto make_test_future(int i) +{ + test_future ret(i); + return ret; +} + struct test_stream : public base_stream { @@ -70,7 +76,7 @@ TEST(timeout_tests, poll_future_no_timeout) test_future t(0); auto f = t - .timeout(std::chrono::seconds(5)); + .timeout(std::chrono::seconds(5)); EXPECT_CALL(m, now()) .WillOnce(Return(time_point(std::chrono::seconds(0))));