diff --git a/include/stdx/utility.hpp b/include/stdx/utility.hpp index e85ba0f..fab1bbf 100644 --- a/include/stdx/utility.hpp +++ b/include/stdx/utility.hpp @@ -163,20 +163,8 @@ struct type_val { } }; -template -constexpr inline auto is_type = [] { return std::true_type{}; }; -template <> -constexpr inline auto is_type = [] { return std::false_type{}; }; - -template struct typer { - using type = void; -}; -template struct typer { - using type = T; -}; - -template constexpr auto type_of() -> void; -template constexpr auto type_of() -> typename typer::type; +template constexpr inline auto is_type = true; +template <> constexpr inline auto is_type = false; class cx_base { struct unusable {}; @@ -236,21 +224,22 @@ template constexpr auto is_ct_v = is_ct_v; #define FWD(x) std::forward(x) #endif +#ifndef STDX_IS_TYPE +#define STDX_IS_TYPE(...) \ + ::stdx::cxv_detail::is_type<__typeof__(::stdx::cxv_detail::from_any( \ + __VA_ARGS__))> +#endif + #ifndef CX_VALUE #define CX_VALUE(...) \ []() constexpr { \ STDX_PRAGMA(diagnostic push) \ STDX_PRAGMA(diagnostic ignored "-Wold-style-cast") \ STDX_PRAGMA(diagnostic ignored "-Wunused-value") \ - if constexpr (decltype(::stdx::cxv_detail::is_type< \ - __typeof__(::stdx::cxv_detail::from_any( \ - __VA_ARGS__))>())::value) { \ + if constexpr (STDX_IS_TYPE(__VA_ARGS__)) { \ return ::stdx::overload{ \ ::stdx::cxv_detail::cx_base{}, [] { \ - return ::stdx::type_identity< \ - decltype(::stdx::cxv_detail::type_of< \ - ::stdx::cxv_detail::from_any( \ - __VA_ARGS__)>())>{}; \ + return ::stdx::type_identity<__typeof__(__VA_ARGS__)>{}; \ }}; \ } else { \ return ::stdx::overload{::stdx::cxv_detail::cx_base{}, [] { \ @@ -264,6 +253,7 @@ template constexpr auto is_ct_v = is_ct_v; #if __cplusplus >= 202002L +#ifndef CT_WRAP #define CT_WRAP(...) \ [&](auto f) { \ if constexpr (::stdx::is_ct_v) { \ @@ -278,7 +268,9 @@ template constexpr auto is_ct_v = is_ct_v; return f(); \ } \ }([&] { return __VA_ARGS__; }) +#endif +#ifndef CX_DETECT #ifdef __clang__ #define CX_DETECT(...) \ std::is_empty_v; \ } #endif +#endif +#ifndef CX_WRAP #define CX_WRAP(...) \ [&]([[maybe_unused]] auto f) { \ STDX_PRAGMA(diagnostic push) \ STDX_PRAGMA(diagnostic ignored "-Wold-style-cast") \ - if constexpr (decltype(::stdx::cxv_detail::is_type< \ - __typeof__(::stdx::cxv_detail::from_any( \ - __VA_ARGS__))>())::value) { \ - return ::stdx::overload{ \ - ::stdx::cxv_detail::cx_base{}, [&] { \ - return ::stdx::type_identity< \ - typename ::stdx::cxv_detail::typer< \ - __typeof__(::stdx::cxv_detail::from_any( \ - __VA_ARGS__))>::type>{}; \ - }}; \ + if constexpr (STDX_IS_TYPE(__VA_ARGS__)) { \ + return ::stdx::type_identity<__typeof__(__VA_ARGS__)>{}; \ } else if constexpr (::stdx::is_cx_value_v< \ std::invoke_result_t> or \ std::is_empty_v< \ @@ -331,6 +317,7 @@ constexpr auto cx_detect1(auto) { return 0; } }) #endif +#endif // NOLINTEND(cppcoreguidelines-macro-usage) // NOLINTEND(modernize-use-constraints) diff --git a/test/utility.cpp b/test/utility.cpp index e9aa348..bfbaeb9 100644 --- a/test/utility.cpp +++ b/test/utility.cpp @@ -359,16 +359,14 @@ TEST_CASE("CX_WRAP template argument", "[utility]") { } TEST_CASE("CX_WRAP type argument", "[utility]") { - STATIC_REQUIRE(stdx::is_cx_value_v); STATIC_REQUIRE( - std::is_same_v>); + std::is_same_v>); } TEST_CASE("CX_WRAP empty type argument", "[utility]") { using X = std::integral_constant; - STATIC_REQUIRE(stdx::is_cx_value_v); STATIC_REQUIRE( - std::is_same_v>); + std::is_same_v>); } TEST_CASE("CX_WRAP integral_constant arg", "[utility]") {