From acc15b46abea8d4201042a32546875194cd6adc7 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Tue, 6 Mar 2018 03:53:18 +0100 Subject: [PATCH] Traits and util cleanup --- include/continuable/continuable-base.hpp | 2 +- .../continuable/detail/composition-any.hpp | 4 --- include/continuable/detail/composition.hpp | 4 --- include/continuable/detail/features.hpp | 16 +++++----- include/continuable/detail/traits.hpp | 17 ----------- include/continuable/detail/util.hpp | 30 ------------------- .../multi/test-continuable-regression.cpp | 7 ++++- 7 files changed, 14 insertions(+), 66 deletions(-) diff --git a/include/continuable/continuable-base.hpp b/include/continuable/continuable-base.hpp index b1d8d2e..4898a6d 100644 --- a/include/continuable/continuable-base.hpp +++ b/include/continuable/continuable-base.hpp @@ -507,7 +507,7 @@ public: /// // ... /// }); /// - /// (supply(10, 'T') || supply(10.f, 'T')) + /// (make_ready_continuable(10, 'A') || make_ready_continuable(29, 'B')) /// .then([](int a, char b) { /// // ... /// }); diff --git a/include/continuable/detail/composition-any.hpp b/include/continuable/detail/composition-any.hpp index dc8ffc9..607c765 100644 --- a/include/continuable/detail/composition-any.hpp +++ b/include/continuable/detail/composition-any.hpp @@ -197,10 +197,6 @@ struct composition_finalizer { }; } }; - -template <> -struct composition_finalizer - : composition_finalizer {}; } // namespace composition } // namespace detail } // namespace cti diff --git a/include/continuable/detail/composition.hpp b/include/continuable/detail/composition.hpp index eb13033..be55c5a 100644 --- a/include/continuable/detail/composition.hpp +++ b/include/continuable/detail/composition.hpp @@ -49,7 +49,6 @@ namespace detail { namespace composition { struct composition_strategy_all_tag {}; struct composition_strategy_any_tag {}; -struct composition_strategy_any_fail_fast_tag {}; struct composition_strategy_seq_tag {}; template @@ -62,9 +61,6 @@ template <> struct is_composition_strategy // ... : std::true_type {}; template <> -struct is_composition_strategy // ... - : std::true_type {}; -template <> struct is_composition_strategy // ... : std::true_type {}; diff --git a/include/continuable/detail/features.hpp b/include/continuable/detail/features.hpp index d1c10fc..06b17aa 100644 --- a/include/continuable/detail/features.hpp +++ b/include/continuable/detail/features.hpp @@ -52,28 +52,26 @@ #if (defined(_MSC_VER) && defined(_HAS_CXX17) && _HAS_CXX17) || \ (__cplusplus >= 201703L) #define CONTINUABLE_HAS_CXX17_CONSTEXPR_IF - #define CONTINUABLE_HAS_CXX17_FOLD_EXPRESSION #define CONTINUABLE_HAS_CXX17_DISJUNCTION #define CONTINUABLE_HAS_CXX17_CONJUNCTION #else // Generic feature detection based on __has_feature #if defined(__has_feature) - #if !defined(CONTINUABLE_HAS_CXX17_FOLD_EXPRESSION) && \ + #if !defined(CONTINUABLE_HAS_CXX17_CONSTEXPR_IF) && \ __has_feature(cxx_if_constexpr) #define CONTINUABLE_HAS_CXX17_CONSTEXPR_IF #endif - - #if !defined(CONTINUABLE_HAS_CXX17_FOLD_EXPRESSION) && \ - __has_feature(cxx_fold_expressions) - // PR not merged into the clang master yet - #define CONTINUABLE_HAS_CXX17_FOLD_EXPRESSION - #endif #endif - #if !defined(CONTINUABLE_HAS_CXX17_FOLD_EXPRESSION) && \ + #if !defined(CONTINUABLE_HAS_CXX17_DISJUNCTION) && \ defined(__cpp_lib_experimental_logical_traits) && \ (__cpp_lib_experimental_logical_traits >= 201511) #define CONTINUABLE_HAS_CXX17_DISJUNCTION + #endif + + #if !defined(CONTINUABLE_HAS_CXX17_CONJUNCTION) && \ + defined(__cpp_lib_experimental_logical_traits) && \ + (__cpp_lib_experimental_logical_traits >= 201511) #define CONTINUABLE_HAS_CXX17_CONJUNCTION #endif #endif diff --git a/include/continuable/detail/traits.hpp b/include/continuable/detail/traits.hpp index 60dc905..cf30e5a 100644 --- a/include/continuable/detail/traits.hpp +++ b/include/continuable/detail/traits.hpp @@ -272,23 +272,6 @@ constexpr auto static_if(Type&& type, Check&& check, std::forward(falseCallback)); } -/// A compile-time while loop, which loops as long the value matches -/// the predicate. The handler shall return the next value. -template -constexpr auto static_while(Value&& value, Predicate&& predicate, - Handler&& handler) { - return static_if(std::forward(value), predicate, - [&](auto&& result) mutable { - return static_while( - handler(std::forward(result)), - std::forward(predicate), - std::forward(handler)); - }, - [&](auto&& result) mutable { - return std::forward(result); - }); -} - /// Returns a validator which checks whether the given sequenceable is empty inline auto is_empty() noexcept { return [](auto const& checkable) { diff --git a/include/continuable/detail/util.hpp b/include/continuable/detail/util.hpp index c025b59..bdb33c8 100644 --- a/include/continuable/detail/util.hpp +++ b/include/continuable/detail/util.hpp @@ -263,24 +263,6 @@ private: *(volatile int*)0 = 0; #endif } - -/// Exposes functionality to emulate later standard features -namespace emulation { -#ifndef CONTINUABLE_HAS_CXX17_FOLD_EXPRESSION -/// Combines the given arguments with the given folding function -template -constexpr auto fold(F&& /*folder*/, First&& first) { - return std::forward(first); -} -/// Combines the given arguments with the given folding function -template -auto fold(F&& folder, First&& first, Second&& second, Rest&&... rest) { - auto res = folder(std::forward(first), std::forward(second)); - return fold(std::forward(folder), std::move(res), - std::forward(rest)...); -} -#endif // CONTINUABLE_HAS_CXX17_FOLD_EXPRESSION -} // namespace emulation } // namespace util } // namespace detail } // namespace cti @@ -291,16 +273,4 @@ auto fold(F&& folder, First&& first, Second&& second, Rest&&... rest) { #define CONTINUABLE_CONSTEXPR_IF(EXPR, TRUE_BRANCH, FALSE_BRANCH) #endif // CONTINUABLE_CONSTEXPR_IF -#ifdef CONTINUABLE_HAS_CXX17_FOLD_EXPRESSION -#define CONTINUABLE_FOLD_EXPRESSION(OP, PACK) (... OP PACK) -#else -#define CONTINUABLE_FOLD_EXPRESSION(OP, PACK) \ - cti::detail::util::emulation::fold( \ - [](auto&& left, auto&& right) { \ - return std::forward(left) \ - OP std::forward(right); \ - }, \ - PACK) -#endif // CONTINUABLE_HAS_CXX17_FOLD_EXPRESSION - #endif // CONTINUABLE_DETAIL_UTIL_HPP_INCLUDED diff --git a/test/unit-test/multi/test-continuable-regression.cpp b/test/unit-test/multi/test-continuable-regression.cpp index d460bfe..f91e9ff 100644 --- a/test/unit-test/multi/test-continuable-regression.cpp +++ b/test/unit-test/multi/test-continuable-regression.cpp @@ -23,7 +23,9 @@ #include +#include #include +#include using namespace cti; using namespace cti::detail; @@ -39,7 +41,10 @@ TEST(regression_tests, are_multiple_args_mergeable) { std::make_tuple(1, 2, 3, 4)); auto count = traits::unpack(tp2, [](auto... args) { - return CONTINUABLE_FOLD_EXPRESSION(+, args...); + std::vector v{args...}; + int c = 0; + std::count(v.begin(), v.end(), c); + return c; }); EXPECT_EQ(count, 20); }