Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions include/stdx/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,14 @@ struct type_val {
}
};

template <int> constexpr auto is_type() -> std::false_type;
template <typename> constexpr auto is_type() -> std::true_type;
template <typename>
constexpr inline auto is_type = [] { return std::true_type{}; };
template <>
constexpr inline auto is_type<from_any> = [] { return std::false_type{}; };

template <typename> struct typer;
template <typename> struct typer {
using type = void;
};
template <typename T> struct typer<from_any(T)> {
using type = T;
};
Expand Down Expand Up @@ -239,8 +243,8 @@ template <typename T> constexpr auto is_ct_v<T const> = is_ct_v<T>;
STDX_PRAGMA(diagnostic ignored "-Wold-style-cast") \
STDX_PRAGMA(diagnostic ignored "-Wunused-value") \
if constexpr (decltype(::stdx::cxv_detail::is_type< \
::stdx::cxv_detail::from_any( \
__VA_ARGS__)>())::value) { \
__typeof__(::stdx::cxv_detail::from_any( \
__VA_ARGS__))>())::value) { \
return ::stdx::overload{ \
::stdx::cxv_detail::cx_base{}, [] { \
return ::stdx::type_identity< \
Expand Down Expand Up @@ -299,14 +303,14 @@ constexpr auto cx_detect1(auto) { return 0; }
STDX_PRAGMA(diagnostic push) \
STDX_PRAGMA(diagnostic ignored "-Wold-style-cast") \
if constexpr (decltype(::stdx::cxv_detail::is_type< \
::stdx::cxv_detail::from_any( \
__VA_ARGS__)>())::value) { \
__typeof__(::stdx::cxv_detail::from_any( \
__VA_ARGS__))>())::value) { \
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__)>())>{}; \
typename ::stdx::cxv_detail::typer< \
__typeof__(::stdx::cxv_detail::from_any( \
__VA_ARGS__))>::type>{}; \
}}; \
} else if constexpr (::stdx::is_cx_value_v< \
std::invoke_result_t<decltype(f)>> or \
Expand Down
15 changes: 15 additions & 0 deletions test/ct_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,18 @@ TEST_CASE("FORMAT an integral_constant argument", "[ct_format]") {
auto I = std::integral_constant<int, 17>{};
STATIC_REQUIRE(STDX_CT_FORMAT("Hello {}", I) == "Hello 17"_fmt_res);
}

#ifdef __clang__
namespace {
struct expression_test {
int f(int x) { return x; }
};
} // namespace

TEST_CASE("FORMAT non-constexpr expression", "[utility]") {
auto x = 17;
constexpr auto expected =
stdx::format_result{"Hello {}"_ctst, stdx::make_tuple(17)};
CHECK(STDX_CT_FORMAT("Hello {}", expression_test{}.f(x)) == expected);
}
#endif
16 changes: 16 additions & 0 deletions test/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,20 @@ TEST_CASE("CX_WRAP integral_constant arg", "[utility]") {
STATIC_REQUIRE(std::is_same_v<decltype(CX_WRAP(x)), decltype(x)>);
CHECK(CX_WRAP(x)() == 17);
}

#ifdef __clang__
namespace {
struct expression_test {
int f(int x) { return x; }
};
} // namespace

TEST_CASE("CX_WRAP non-constexpr expression", "[utility]") {
auto x = 17;
STATIC_REQUIRE(
std::is_same_v<decltype(CX_WRAP(expression_test{}.f(x))), int>);
CHECK(CX_WRAP(expression_test{}.f(x)) == 17);
}
#endif

#endif