diff --git a/include/continuable/detail/traits.hpp b/include/continuable/detail/traits.hpp index cf30e5a..fec1fd9 100644 --- a/include/continuable/detail/traits.hpp +++ b/include/continuable/detail/traits.hpp @@ -42,84 +42,6 @@ namespace cti { namespace detail { namespace traits { -/// \cond false -#define CTI__FOR_EACH_BOOLEAN_BIN_OP(CTI__OP__) \ - CTI__OP__(==) \ - CTI__OP__(!=) CTI__OP__(<=) CTI__OP__(>=) CTI__OP__(<) CTI__OP__(>) -#define CTI__FOR_EACH_BOOLEAN_UNA_OP(CTI__OP__) CTI__OP__(!) -#define CTI__FOR_EACH_INTEGRAL_BIN_OP(CTI__OP__) \ - CTI__OP__(*) \ - CTI__OP__(/) CTI__OP__(+) CTI__OP__(-) CTI__FOR_EACH_BOOLEAN_BIN_OP(CTI__OP__) -#define CTI__FOR_EACH_INTEGRAL_UNA_OP(CTI__OP__) \ - CTI__OP__(~) CTI__FOR_EACH_BOOLEAN_UNA_OP(CTI__OP__) -/// \endcond - -template -struct constant : std::integral_constant { -/// \cond false -#define CTI__INST(CTI__OP) \ - template \ - constexpr auto operator CTI__OP(std::integral_constant) \ - const noexcept { \ - return constant{}; \ - } - CTI__FOR_EACH_INTEGRAL_BIN_OP(CTI__INST) -#undef CTI__INST -#define CTI__INST(CTI__OP) \ - constexpr auto operator CTI__OP() const noexcept { \ - return constant{}; \ - } - CTI__FOR_EACH_INTEGRAL_UNA_OP(CTI__INST) -#undef CTI__INST - /// \endcond -}; - -template -struct constant : std::integral_constant { -/// \cond false -#define CTI__INST(CTI__OP) \ - template \ - constexpr auto operator CTI__OP(std::integral_constant) \ - const noexcept { \ - return constant{}; \ - } - CTI__FOR_EACH_BOOLEAN_BIN_OP(CTI__INST) -#undef CTI__INST -#define CTI__INST(CTI__OP) \ - constexpr auto operator CTI__OP() const noexcept { \ - return constant{}; \ - } - CTI__FOR_EACH_BOOLEAN_UNA_OP(CTI__INST) -#undef CTI__INST - /// \endcond -}; - -template -using bool_constant = constant; -template -using size_constant = constant; - -template -constexpr auto constant_of(std::integral_constant /*value*/ = {}) { - return constant{}; -} -template -constexpr auto -size_constant_of(std::integral_constant /*value*/ = {}) { - return size_constant{}; -} -template -constexpr auto -bool_constant_of(std::integral_constant /*value*/ = {}) { - return bool_constant{}; -} - -#undef CTI__FOR_EACH_BOOLEAN_BIN_OP -#undef CTI__FOR_EACH_BOOLEAN_UNA_OP -#undef CTI__FOR_EACH_INTEGRAL_BIN_OP -#undef CTI__FOR_EACH_INTEGRAL_UNA_OP - /// Evaluates to the element at position I. template using at_t = decltype(std::get(std::declval>())); @@ -165,14 +87,6 @@ template using void_t = typename detail::deduce_to_void::type; namespace detail { -template > -struct is_valid_impl : std::common_type {}; - -template -struct is_valid_impl()(std::declval()))>> - : std::common_type {}; - template constexpr void static_if_impl(std::true_type, Type&& type, TrueCallback&& trueCallback) { @@ -208,47 +122,25 @@ struct tuple_like_size::value)>> } // namespace detail /// Returns the pack size of the given empty pack -constexpr auto pack_size_of(identity<>) noexcept { - return size_constant<0U>{}; +constexpr std::size_t pack_size_of(identity<>) noexcept { + return 0U; } /// Returns the pack size of the given type template -constexpr auto pack_size_of(identity) noexcept { - return size_constant::value>{}; +constexpr std::size_t pack_size_of(identity) noexcept { + return detail::tuple_like_size::value; } /// Returns the pack size of the given type template -constexpr auto pack_size_of(identity) noexcept { - return size_constant<2U + sizeof...(Args)>{}; +constexpr std::size_t pack_size_of(identity) noexcept { + return 2U + sizeof...(Args); } /// Returns an index sequence of the given type template -constexpr auto sequence_of(T&& /*sequenceable*/) noexcept { - return std::make_index_sequence()))::value>(); -} - -/// Returns a check which returns a true type if the current value -/// is below the -template -constexpr auto is_less_than(size_constant end) noexcept { - return [=](auto current) { return end > current; }; -} - -/// Compile-time check for validating a certain expression -template -constexpr auto is_valid(T&& /*type*/, Check&& /*check*/) noexcept { - return typename detail::is_valid_impl::type{}; -} - -/// Creates a static callable validation object. -template -constexpr auto validator_of(Check&& check) noexcept( - std::is_nothrow_move_constructible>::value) { - return [check = std::forward(check)](auto&& matchable) { - return is_valid(std::forward(matchable), check); - }; +constexpr auto sequence_of(identity) noexcept { + constexpr auto const size = pack_size_of(identity{}); + return std::make_index_sequence(); } /// Invokes the callback only if the given type matches the check @@ -272,18 +164,11 @@ constexpr auto static_if(Type&& type, Check&& check, std::forward(falseCallback)); } -/// Returns a validator which checks whether the given sequenceable is empty -inline auto is_empty() noexcept { - return [](auto const& checkable) { - return pack_size_of(checkable) == size_constant_of<0>(); - }; -} - /// Calls the given unpacker with the content of the given sequence template constexpr decltype(auto) unpack(std::integer_sequence, U&& unpacker) { - return std::forward(unpacker)(size_constant_of()...); + return std::forward(unpacker)(std::integral_constant{}...); } /// Calls the given unpacker with the content of the given sequenceable diff --git a/include/continuable/detail/util.hpp b/include/continuable/detail/util.hpp index bdb33c8..d46b55a 100644 --- a/include/continuable/detail/util.hpp +++ b/include/continuable/detail/util.hpp @@ -52,9 +52,8 @@ namespace detail { /// Forwards every element in the tuple except the last one template auto forward_except_last(T&& sequenceable) { - auto size = pack_size_of(traits::identity_of(sequenceable)) - - traits::size_constant_of<1>(); - auto sequence = std::make_index_sequence(); + constexpr auto const size = pack_size_of(traits::identify()) - 1U; + constexpr auto const sequence = std::make_index_sequence(); return traits::unpack(std::forward(sequenceable), [](auto&&... args) {