From afe8a925611ff16bbfc8a97219771e6bdc1192d7 Mon Sep 17 00:00:00 2001 From: Daniel Marshall Date: Sat, 9 Nov 2019 17:51:43 +0000 Subject: [PATCH 1/4] Make underlying_type SFINAE-friendly --- stl/inc/type_traits | 11 ++++++++++- stl/inc/yvals_core.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/stl/inc/type_traits b/stl/inc/type_traits index 7adf7b62d57..44fbf7d3798 100644 --- a/stl/inc/type_traits +++ b/stl/inc/type_traits @@ -1151,11 +1151,20 @@ template using aligned_union_t = typename aligned_union<_Len, _Types...>::type; // STRUCT TEMPLATE underlying_type +template > +struct _Underlying_type {}; + +template +struct _Underlying_type<_Ty, false> {}; + template -struct underlying_type { // determine underlying type for enum +struct _Underlying_type<_Ty, true> { using type = __underlying_type(_Ty); }; +template +struct underlying_type : _Underlying_type<_Ty> {}; // determine underlying type for enum + template using underlying_type_t = typename underlying_type<_Ty>::type; diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 1da8c63ed42..3ebe1794020 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -149,6 +149,7 @@ // P0063R3 C11 Standard Library // P0074R0 owner_less<> // P0092R1 floor(), ceil(), round(), abs() +// P0340R3 SFINAE-Friendly underlying_type // P0414R2 shared_ptr, shared_ptr // P0418R2 atomic compare_exchange memory_order Requirements // P0435R1 Overhauling common_type From e26e8366c6aa62c4ff74b3379d7404808be1d8c8 Mon Sep 17 00:00:00 2001 From: Daniel Marshall Date: Sat, 9 Nov 2019 18:48:12 +0000 Subject: [PATCH 2/4] Remove unneeded specialisation --- stl/inc/type_traits | 3 --- 1 file changed, 3 deletions(-) diff --git a/stl/inc/type_traits b/stl/inc/type_traits index 44fbf7d3798..4a7418378b8 100644 --- a/stl/inc/type_traits +++ b/stl/inc/type_traits @@ -1154,9 +1154,6 @@ using aligned_union_t = typename aligned_union<_Len, _Types...>::type; template > struct _Underlying_type {}; -template -struct _Underlying_type<_Ty, false> {}; - template struct _Underlying_type<_Ty, true> { using type = __underlying_type(_Ty); From 56bfa4f1efa37f3c58293c72af129d423a743ba2 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Mon, 11 Nov 2019 17:09:01 -0800 Subject: [PATCH 3/4] Use the primary template for the true case. This improves readability. --- stl/inc/type_traits | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stl/inc/type_traits b/stl/inc/type_traits index 4a7418378b8..1796b8a46e2 100644 --- a/stl/inc/type_traits +++ b/stl/inc/type_traits @@ -1152,13 +1152,13 @@ using aligned_union_t = typename aligned_union<_Len, _Types...>::type; // STRUCT TEMPLATE underlying_type template > -struct _Underlying_type {}; - -template -struct _Underlying_type<_Ty, true> { +struct _Underlying_type { using type = __underlying_type(_Ty); }; +template +struct _Underlying_type<_Ty, false> {}; + template struct underlying_type : _Underlying_type<_Ty> {}; // determine underlying type for enum From 2efa287f0ac8effdfe7c9436b2fef0b253d548f4 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Mon, 11 Nov 2019 19:39:02 -0800 Subject: [PATCH 4/4] Avoid an instantiation, micro-optimizing throughput. --- stl/inc/type_traits | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/type_traits b/stl/inc/type_traits index 1796b8a46e2..190994f281a 100644 --- a/stl/inc/type_traits +++ b/stl/inc/type_traits @@ -1163,7 +1163,7 @@ template struct underlying_type : _Underlying_type<_Ty> {}; // determine underlying type for enum template -using underlying_type_t = typename underlying_type<_Ty>::type; +using underlying_type_t = typename _Underlying_type<_Ty>::type; // STRUCT TEMPLATE rank template