From 08dbd7573674959c06f06a09bf4236a762407a0c Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Thu, 21 Sep 2017 23:36:09 +0200 Subject: [PATCH] Update the codestyle --- include/continuable/continuable-base.hpp | 181 +++++++++++++++-------- 1 file changed, 121 insertions(+), 60 deletions(-) diff --git a/include/continuable/continuable-base.hpp b/include/continuable/continuable-base.hpp index 23b248a..3891e67 100644 --- a/include/continuable/continuable-base.hpp +++ b/include/continuable/continuable-base.hpp @@ -83,7 +83,8 @@ inline namespace abi_v1 { /// invocation on destruction. /// /// \since version 1.0.0 -template class continuable_base; +template +class continuable_base; /// Declares the internal private namespace of the continuable library /// which isn't intended to be used by users of the library. @@ -144,8 +145,10 @@ struct constant : std::integral_constant { /// \endcond }; -template using bool_constant = constant; -template using size_constant = constant; +template +using bool_constant = constant; +template +using size_constant = constant; template constexpr auto constant_of(std::integral_constant /*value*/ = {}) { @@ -173,13 +176,17 @@ using at_t = decltype(std::get(std::declval>())); /// Evaluates to an integral constant which represents the size /// of the given pack. -template using size_of_t = size_constant; +template +using size_of_t = size_constant; /// A tagging type for wrapping other types -template struct identity {}; -template struct identity : std::common_type {}; +template +struct identity {}; +template +struct identity : std::common_type {}; -template struct is_identity : std::false_type {}; +template +struct is_identity : std::false_type {}; template struct is_identity> : std::true_type {}; @@ -191,7 +198,8 @@ template constexpr identity identity_of(identity /*type*/) noexcept { return {}; } -template constexpr auto identity_of() noexcept { +template +constexpr auto identity_of() noexcept { return std::conditional_t>::value, T, identity>>{}; } @@ -202,7 +210,8 @@ constexpr auto get(identity) noexcept { } /// Helper to trick compilers about that a parameter pack is used -template void unused(T&&... args) { +template +void unused(T&&... args) { auto use = [](auto&& type) mutable { (void)type; return 0; @@ -216,7 +225,8 @@ namespace detail { // Equivalent to C++17's std::void_t which targets a bug in GCC, // that prevents correct SFINAE behavior. // See http://stackoverflow.com/questions/35753920 for details. -template struct deduce_to_void : std::common_type {}; +template +struct deduce_to_void : std::common_type {}; } // end namespace detail /// C++17 like void_t type @@ -240,7 +250,8 @@ constexpr void static_if_impl(std::true_type, Type&& type, template constexpr void static_if_impl(std::false_type, Type&& /*type*/, - TrueCallback&& /*trueCallback*/) {} + TrueCallback&& /*trueCallback*/) { +} template constexpr auto static_if_impl(std::true_type, Type&& type, @@ -274,7 +285,8 @@ constexpr auto pack_size_of(identity) noexcept { } /// Returns an index sequence of the given type -template constexpr auto sequenceOf(T&& /*sequenceable*/) noexcept { +template +constexpr auto sequenceOf(T&& /*sequenceable*/) noexcept { return std::make_index_sequence()))::value>(); } @@ -429,7 +441,8 @@ constexpr auto pop_first(identity) noexcept { } /// Returns the merged sequence -template constexpr auto merge(Left&& left) { +template +constexpr auto merge(Left&& left) { return std::forward(left); } /// Merges the left sequenceable with the right ones @@ -518,7 +531,8 @@ using is_invokable_t = typename detail::is_invokable_impl::type; namespace detail { /// Forwards every element in the tuple except the last one -template auto forward_except_last(T&& sequenceable) { +template +auto forward_except_last(T&& sequenceable) { auto size = pack_size_of(identity_of(sequenceable)) - size_constant_of<1>(); auto sequence = std::make_index_sequence(); @@ -625,13 +639,16 @@ struct non_movable { /// is moved to another instance. class ownership { explicit constexpr ownership(bool acquired, bool frozen) - : acquired_(acquired), frozen_(frozen) {} + : acquired_(acquired), frozen_(frozen) { + } public: - constexpr ownership() : acquired_(true), frozen_(false) {} + constexpr ownership() : acquired_(true), frozen_(false) { + } constexpr ownership(ownership const&) = default; ownership(ownership&& right) noexcept - : acquired_(right.consume()), frozen_(right.is_frozen()) {} + : acquired_(right.consume()), frozen_(right.is_frozen()) { + } ownership& operator=(ownership const&) = default; ownership& operator=(ownership&& right) noexcept { acquired_ = right.consume(); @@ -645,8 +662,12 @@ public: is_frozen() || right.is_frozen()); } - constexpr bool is_acquired() const noexcept { return acquired_; } - constexpr bool is_frozen() const noexcept { return frozen_; } + constexpr bool is_acquired() const noexcept { + return acquired_; + } + constexpr bool is_frozen() const noexcept { + return frozen_; + } void release() noexcept { assert(is_acquired() && "Tried to release the ownership twice!"); @@ -673,11 +694,13 @@ private: }; /// Represents a present signature hint -template using signature_hint_tag = util::identity; +template +using signature_hint_tag = util::identity; /// Represents an absent signature hint struct absent_signature_hint_tag {}; -template struct is_absent_hint : std::false_type {}; +template +struct is_absent_hint : std::false_type {}; template <> struct is_absent_hint : std::true_type {}; @@ -699,7 +722,8 @@ struct this_thread_executor_tag {}; /// -> void namespace base { /// Returns the signature hint of the given continuable -template constexpr auto hint_of(util::identity) { +template +constexpr auto hint_of(util::identity) { static_assert(util::fail::value, "Expected a continuation with an existing signature hint!"); return util::identity_of(); @@ -711,7 +735,8 @@ hint_of(util::identity>>) { return signature_hint_tag{}; } -template struct is_continuation : std::false_type {}; +template +struct is_continuation : std::false_type {}; template struct is_continuation> : std::true_type {}; @@ -769,14 +794,18 @@ struct attorney { namespace decoration { /// Helper class wrapping the underlaying unwrapping lambda /// in order to extend it with a hint method. -template class invoker : public T { +template +class invoker : public T { public: - explicit invoker(T invoke) : T(std::move(invoke)) {} + explicit invoker(T invoke) : T(std::move(invoke)) { + } using T::operator(); /// Returns the underlaying signature hint - static constexpr Hint hint() noexcept { return {}; } + static constexpr Hint hint() noexcept { + return {}; + } }; template @@ -805,7 +834,8 @@ constexpr auto invoker_of(util::identity>) { } /// - ? -> nextCallback(?) -template auto invoker_of(util::identity) { +template +auto invoker_of(util::identity) { return make_invoker( [](auto&& callback, auto&& nextCallback, auto&&... args) { auto result = std::forward(callback)( @@ -943,7 +973,7 @@ template constexpr auto next_hint_of(util::identity /*callback*/, signature_hint_tag /*current*/) { return decoration::invoker_of(util::identity_of()( - std::declval()...))>()) + std::declval()...))>()) .hint(); } @@ -993,7 +1023,9 @@ auto chain_continuation(Continuation&& continuation, Callback&& callback, /// Workaround for GCC bug: /// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64095 struct empty_callback { - template void operator()(Args...) const {} + template + void operator()(Args...) const { + } }; /// Final invokes the given continuation chain: @@ -1008,13 +1040,16 @@ void finalize_continuation(Continuation&& continuation) { /// Workaround for GCC bug: /// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64095 -template class supplier_callback { +template +class supplier_callback { T data_; public: - explicit supplier_callback(T data) : data_(std::move(data)) {} + explicit supplier_callback(T data) : data_(std::move(data)) { + } - template auto operator()(Args...) { + template + auto operator()(Args...) { return std::move(data_); } }; @@ -1034,9 +1069,12 @@ namespace compose { struct strategy_all_tag {}; struct strategy_any_tag {}; -template struct is_strategy : std::false_type {}; -template <> struct is_strategy : std::true_type {}; -template <> struct is_strategy : std::true_type {}; +template +struct is_strategy : std::false_type {}; +template <> +struct is_strategy : std::true_type {}; +template <> +struct is_strategy : std::true_type {}; /// Provides support for extracting the signature hint out /// of given types and parameters. @@ -1109,7 +1147,8 @@ class all_result_submitter : public std::enable_shared_from_this< public: explicit all_result_submitter(T callback) - : callback_(std::move(callback)), left_(Submissions) {} + : callback_(std::move(callback)), left_(Submissions) { + } /// Creates a submitter which submits it's result into the tuple template @@ -1160,7 +1199,8 @@ class any_result_submitter std::once_flag flag_; public: - explicit any_result_submitter(T callback) : callback_(std::move(callback)) {} + explicit any_result_submitter(T callback) : callback_(std::move(callback)) { + } /// Creates a submitter which submits it's result to the callback auto create_callback() { @@ -1171,7 +1211,8 @@ public: private: // Invokes the callback with the given arguments - template void invoke(Args&&... args) { + template + void invoke(Args&&... args) { std::call_once(flag_, std::move(callback_), std::forward(args)...); } }; @@ -1408,7 +1449,8 @@ auto sequential_connect(Left&& left, Right&& right) { namespace transforms { /// Provides helper functions and typedefs for converting callback arguments /// to their types a promise can accept. -template struct future_trait { +template +struct future_trait { /// The promise type used to create the future using promise_t = std::promise>; /// Boxes the argument pack into a tuple @@ -1416,13 +1458,17 @@ template struct future_trait { promise.set_value(std::make_tuple(std::move(args)...)); } }; -template <> struct future_trait<> { +template <> +struct future_trait<> { /// The promise type used to create the future using promise_t = std::promise; /// Boxes the argument pack into void - static void resolve(promise_t& promise) { promise.set_value(); } + static void resolve(promise_t& promise) { + promise.set_value(); + } }; -template struct future_trait { +template +struct future_trait { /// The promise type used to create the future using promise_t = std::promise; /// Boxes the argument pack into nothing @@ -1431,7 +1477,8 @@ template struct future_trait { } }; -template class promise_callback; +template +class promise_callback; template class promise_callback> @@ -1447,9 +1494,13 @@ public: promise_callback& operator=(promise_callback&&) = delete; /// Resolves the promise - void operator()(Args... args) { this->resolve(promise_, std::move(args)...); } + void operator()(Args... args) { + this->resolve(promise_, std::move(args)...); + } /// Returns the future from the promise - auto get_future() { return promise_.get_future(); } + auto get_future() { + return promise_.get_future(); + } }; /// Transforms the continuation to a future @@ -1472,9 +1523,11 @@ auto as_future(continuable_base&& continuable) { } // end namespace transforms } // end namespace detail -template class continuable_base { +template +class continuable_base { /// \cond false - template friend class continuable_base; + template + friend class continuable_base; friend struct detail::base::attorney; // The continuation type or intermediate result @@ -1485,17 +1538,20 @@ template class continuable_base { /// Constructor accepting the data object while erasing the annotation explicit continuable_base(Data data, detail::ownership ownership) - : data_(std::move(data)), ownership_(std::move(ownership)) {} + : data_(std::move(data)), ownership_(std::move(ownership)) { + } public: /// Constructor accepting the data object while erasing the annotation - explicit continuable_base(Data data) : data_(std::move(data)) {} + explicit continuable_base(Data data) : data_(std::move(data)) { + } /// Constructor accepting any object convertible to the data object, /// while erasing the annotation template , Data>::value>* = nullptr> - continuable_base(OData&& data) : data_(std::forward(data)) {} + continuable_base(OData&& data) : data_(std::forward(data)) { + } /// Constructor taking the data of other continuable_base objects /// while erasing the hint. @@ -1504,7 +1560,8 @@ public: /// the continuable by any object which is useful for type-erasure. template continuable_base(continuable_base&& other) - : continuable_base(std::move(other).materialize().consume_data()) {} + : continuable_base(std::move(other).materialize().consume_data()) { + } /// \cond false continuable_base(continuable_base&&) = default; @@ -1783,7 +1840,9 @@ public: /// continuable_base was released already. /// /// \since version 1.0.0 - void done() && { detail::base::finalize_continuation(std::move(*this)); } + void done() && { + detail::base::finalize_continuation(std::move(*this)); + } /// Predicate to check whether the cti::continuable_base is frozen or not. /// @@ -1828,7 +1887,9 @@ public: } private: - void release() noexcept { ownership_.release(); } + void release() noexcept { + ownership_.release(); + } auto materialize() && noexcept(std::is_nothrow_move_constructible::value) { @@ -1971,8 +2032,8 @@ auto when_all(Continuables&&... continuables) { /// /// \deprecated Use the `when_all` function instead. template -[[deprecated("Replaced by cti::when_all")]] -auto all_of(Continuables&&... continuables) { +[[deprecated("Replaced by cti::when_all")]] auto +all_of(Continuables&&... continuables) { return when_all(std::forward(continuables)...); } @@ -1998,8 +2059,8 @@ auto when_any(Continuables&&... continuables) { /// /// \deprecated Use the `when_any` function instead. template -[[deprecated("Replaced by cti::when_any")]] -auto any_of(Continuables&&... continuables) { +[[deprecated("Replaced by cti::when_any")]] auto +any_of(Continuables&&... continuables) { return when_any(std::forward(continuables)...); } @@ -2025,8 +2086,8 @@ auto when_seq(Continuables&&... continuables) { /// /// \deprecated Use the `when_seq` function instead. template -[[deprecated("Replaced by cti::when_seq")]] -auto seq_of(Continuables&&... continuables) { +[[deprecated("Replaced by cti::when_seq")]] auto +seq_of(Continuables&&... continuables) { return when_seq(std::forward(continuables)...); } @@ -2057,7 +2118,7 @@ struct continuable_trait { }; /// \cond false -} // end inline namespace abi_... +} // namespace abi_v1 /// \endcond } // end namespace cti