From 6834793243091a478e7b5ee6328d544daed135b3 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Thu, 31 Oct 2024 13:48:45 -0700 Subject: [PATCH] Add more C++20 type traits {DRQS 177082446} (#5060) --- groups/bsl/bsl+bslhdrs/bsl_type_traits.h | 11 +++++ .../bslim/bslim_bslstandardheadertest.t.cpp | 49 ++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/groups/bsl/bsl+bslhdrs/bsl_type_traits.h b/groups/bsl/bsl+bslhdrs/bsl_type_traits.h index 3a8d1869f7..59c3c526ca 100644 --- a/groups/bsl/bsl+bslhdrs/bsl_type_traits.h +++ b/groups/bsl/bsl+bslhdrs/bsl_type_traits.h @@ -508,9 +508,15 @@ using std::is_nothrow_convertible; using std::is_nothrow_convertible_v; // 20.15.7.6, other transformations +using std::remove_cvref; +using std::remove_cvref_t; using std::common_reference; using std::common_reference_t; using std::basic_common_reference; +using std::unwrap_reference; +using std::unwrap_reference_t; +using std::unwrap_ref_decay; +using std::unwrap_ref_decay_t; #endif #ifdef BSLS_LIBRARYFEATURES_HAS_CPP20_IS_LAYOUT_COMPATIBLE @@ -533,6 +539,11 @@ using std::is_pointer_interconvertible_with_class; using std::is_corresponding_member; #endif +#ifdef BSLS_LIBRARYFEATURES_HAS_CPP20_BASELINE_LIBRARY +// 20.15.10, constant evaluation context +using std::is_constant_evaluated; +#endif + #if 0 // These traits are provided by BDE, and have additional members for // Bloomberg legacy code still using the pre-standard interface. diff --git a/groups/bsl/bslim/bslim_bslstandardheadertest.t.cpp b/groups/bsl/bslim/bslim_bslstandardheadertest.t.cpp index 74965c8368..cd1f1000fc 100644 --- a/groups/bsl/bslim/bslim_bslstandardheadertest.t.cpp +++ b/groups/bsl/bslim/bslim_bslstandardheadertest.t.cpp @@ -1005,23 +1005,33 @@ int main(int argc, char *argv[]) // - `bsl::is_bounded_array` // - `bsl::is_unbounded_array` // - `bsl::is_nothrow_convertible` + // - `bsl::is_constant_evaluated` // - `bsl::is_layout_compatible` // - `bsl::is_pointer_interconvertible_base_of` // - `bsl::common_reference` // - 'bsl::basic_common_reference // - `bsl::is_pointer_interconvertible_with_class` // - `bsl::is_corresponding_member` + // - `bsl::remove_cvref` + // - `bsl::unwrap_reference` + // - `bsl::unwrap_ref_decay` // // 2. When the trait has a `*_v` form, that trait has the same value // as the non-`*_v` form. // - // 3. The feature test macros defined in `` for the imported + // 3. When the trait has a `*_t` form, that trait has the same value + // as the non-`*_t` form. + // + // 4. The feature test macros defined in `` for the imported // features are available and have appropriate values. // // Plan: // 1. Verify that: // o `__cpp_lib_is_layout_compatible >= 201907L` // o `__cpp_lib_is_pointer_interconvertible >= 201907L` + // o `__cpp_lib_unwrap_ref >= 201811L` + // o `__cpp_lib_remove_cvref >= 201711L` + // o `__cpp_lib_is_constant_evaluated >= 201811L` // // 2. Verify that `__cpp_lib_is_layout_compatible` also also determines // the availability of @@ -1087,6 +1097,43 @@ int main(int argc, char *argv[]) bool result = bsl::is_same:: value; ASSERT(false == result); } + + if (veryVerbose) { + Q('bsl::remove_cvref'); + } + { + using T = const int &; + using RET = int; + + ASSERT(__cpp_lib_remove_cvref >= 201711L) + ASSERT((bsl::is_same_v::type, RET>)); + ASSERT((bsl::is_same_v, RET>)); + } + + if (veryVerbose) { + Q('bsl::unwrap_reference'); + Q('bsl::unwrap_ref_decay'); + } + { + using T = bsl::reference_wrapper; + using RET1 = int &; + using RET2 = int &; + + ASSERT(__cpp_lib_unwrap_ref >= 201811L); + ASSERT((bsl::is_same_v::type, RET1>)); + ASSERT((bsl::is_same_v, RET1>)); + + ASSERT((bsl::is_same_v::type, RET2>)); + ASSERT((bsl::is_same_v, RET2>)); + } + if (veryVerbose) { + Q('bsl::is_constant_evaluated'); + } + { + ASSERT(__cpp_lib_is_constant_evaluated >= 201811L); + const bool b = bsl::is_constant_evaluated(); + (void) b; + } #else if (veryVerbose) { puts("SKIPPED: "