Traits and util cleanup

This commit is contained in:
Denis Blank 2018-03-06 03:53:18 +01:00
parent 0dbcccdc9e
commit acc15b46ab
7 changed files with 14 additions and 66 deletions

View File

@ -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) {
/// // ...
/// });

View File

@ -197,10 +197,6 @@ struct composition_finalizer<composition_strategy_any_tag> {
};
}
};
template <>
struct composition_finalizer<composition_strategy_any_fail_fast_tag>
: composition_finalizer<composition_strategy_any_tag> {};
} // namespace composition
} // namespace detail
} // namespace cti

View File

@ -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 <typename T>
@ -62,9 +61,6 @@ template <>
struct is_composition_strategy<composition_strategy_any_tag> // ...
: std::true_type {};
template <>
struct is_composition_strategy<composition_strategy_any_fail_fast_tag> // ...
: std::true_type {};
template <>
struct is_composition_strategy<composition_strategy_seq_tag> // ...
: std::true_type {};

View File

@ -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

View File

@ -272,23 +272,6 @@ constexpr auto static_if(Type&& type, Check&& check,
std::forward<FalseCallback>(falseCallback));
}
/// A compile-time while loop, which loops as long the value matches
/// the predicate. The handler shall return the next value.
template <typename Value, typename Predicate, typename Handler>
constexpr auto static_while(Value&& value, Predicate&& predicate,
Handler&& handler) {
return static_if(std::forward<Value>(value), predicate,
[&](auto&& result) mutable {
return static_while(
handler(std::forward<decltype(result)>(result)),
std::forward<Predicate>(predicate),
std::forward<Handler>(handler));
},
[&](auto&& result) mutable {
return std::forward<decltype(result)>(result);
});
}
/// Returns a validator which checks whether the given sequenceable is empty
inline auto is_empty() noexcept {
return [](auto const& checkable) {

View File

@ -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 <typename F, typename First>
constexpr auto fold(F&& /*folder*/, First&& first) {
return std::forward<First>(first);
}
/// Combines the given arguments with the given folding function
template <typename F, typename First, typename Second, typename... Rest>
auto fold(F&& folder, First&& first, Second&& second, Rest&&... rest) {
auto res = folder(std::forward<First>(first), std::forward<Second>(second));
return fold(std::forward<F>(folder), std::move(res),
std::forward<Rest>(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<decltype(left)>(left) \
OP std::forward<decltype(right)>(right); \
}, \
PACK)
#endif // CONTINUABLE_HAS_CXX17_FOLD_EXPRESSION
#endif // CONTINUABLE_DETAIL_UTIL_HPP_INCLUDED

View File

@ -23,7 +23,9 @@
#include <test-continuable.hpp>
#include <algorithm>
#include <functional>
#include <vector>
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<int> v{args...};
int c = 0;
std::count(v.begin(), v.end(), c);
return c;
});
EXPECT_EQ(count, 20);
}