File tree Expand file tree Collapse file tree 2 files changed +36
-18
lines changed Expand file tree Collapse file tree 2 files changed +36
-18
lines changed Original file line number Diff line number Diff line change @@ -277,26 +277,23 @@ template <typename T> constexpr auto is_ct_v<T const> = is_ct_v<T>;
277
277
}([&]() constexpr { return __VA_ARGS__; })
278
278
#endif
279
279
280
- #ifndef CX_DETECT
281
- #ifdef __clang__
282
- #define CX_DETECT (...) \
283
- std::is_empty_v<decltype ([&] { \
284
- return (__VA_ARGS__) + ::stdx::cxv_detail::type_val{}; \
285
- })>
286
- #else
287
280
namespace stdx {
288
281
inline namespace v1 {
289
- template <auto > constexpr auto cx_detect0 () {}
290
- constexpr auto cx_detect1 (auto ) { return 0 ; }
282
+ namespace cxv_detail {
283
+ template <auto > constexpr auto cx_sfinae = std::true_type{};
284
+
285
+ #ifdef __clang__
286
+ auto cx_detect (auto f) -> decltype(cx_sfinae<from_any{f ()}>);
287
+ auto cx_detect (...) -> std::false_type;
288
+ #else
289
+ auto cx_detect (auto f) {
290
+ constexpr auto b = requires { cx_sfinae<from_any{f ()}>; };
291
+ return std::bool_constant<b>{};
292
+ }
293
+ #endif
294
+ } // namespace cxv_detail
291
295
} // namespace v1
292
296
} // namespace stdx
293
- #define CX_DETECT (...) \
294
- requires { \
295
- ::stdx::cx_detect0<::stdx::cx_detect1 ( \
296
- (__VA_ARGS__) + ::stdx::cxv_detail::type_val{})>; \
297
- }
298
- #endif
299
- #endif
300
297
301
298
#ifndef CX_WRAP
302
299
#define CX_WRAP (...) \
@@ -310,7 +307,8 @@ constexpr auto cx_detect1(auto) { return 0; }
310
307
std::is_empty_v< \
311
308
std::invoke_result_t <decltype (f)>>) { \
312
309
return f (); \
313
- } else if constexpr (CX_DETECT (__VA_ARGS__)) { \
310
+ } else if constexpr (decltype (::stdx::cxv_detail::cx_detect ( \
311
+ f))::value) { \
314
312
return ::stdx::overload{::stdx::cxv_detail::cx_base{}, f}; \
315
313
} else { \
316
314
return f (); \
Original file line number Diff line number Diff line change @@ -317,6 +317,26 @@ TEST_CASE("CX_WRAP string_view runtime arg", "[utility]") {
317
317
CHECK (CX_WRAP (x) == std::string_view{" hello" });
318
318
}
319
319
320
+ namespace {
321
+ auto at_init_time () { return 17 ; }
322
+ auto nc_var = at_init_time();
323
+ } // namespace
324
+
325
+ TEST_CASE (" CX_WRAP static runtime arg" , " [utility]" ) {
326
+ STATIC_REQUIRE (std::is_same_v<decltype (CX_WRAP (nc_var)), decltype (nc_var)>);
327
+ CHECK (CX_WRAP (nc_var) == 17 );
328
+ }
329
+
330
+ namespace {
331
+ constexpr auto at_compile_time () { return 17 ; }
332
+ constexpr auto c_var = at_compile_time();
333
+ } // namespace
334
+
335
+ TEST_CASE (" CX_WRAP static constexpr arg" , " [utility]" ) {
336
+ STATIC_REQUIRE (stdx::is_cx_value_v<decltype (CX_WRAP (c_var))>);
337
+ STATIC_REQUIRE (CX_WRAP (c_var)() == 17 );
338
+ }
339
+
320
340
TEST_CASE (" CX_WRAP const integral type" , " [utility]" ) {
321
341
auto const x = 17 ;
322
342
STATIC_REQUIRE (stdx::is_cx_value_v<decltype (CX_WRAP (x))>);
@@ -378,7 +398,7 @@ TEST_CASE("CX_WRAP integral_constant arg", "[utility]") {
378
398
#ifdef __clang__
379
399
namespace {
380
400
struct expression_test {
381
- int f (int x) { return x; }
401
+ auto f (int x) -> int { return x; }
382
402
};
383
403
} // namespace
384
404
You can’t perform that action at this time.
0 commit comments