From c5aa5e3cd2c47fb8457c7c81fed7314a815c18d3 Mon Sep 17 00:00:00 2001 From: Sergei Shirokov Date: Thu, 26 Sep 2024 17:33:56 +0300 Subject: [PATCH] revert fixes --- include/cetl/type_traits_ext.hpp | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/include/cetl/type_traits_ext.hpp b/include/cetl/type_traits_ext.hpp index 84fca02..f13395e 100644 --- a/include/cetl/type_traits_ext.hpp +++ b/include/cetl/type_traits_ext.hpp @@ -102,24 +102,9 @@ struct partial // -------------------------------------------------------------------------------------------- -namespace detail -{ -enum narrowing_detector_tag -{ -}; -template -struct narrowing_detector -{ - narrowing_detector(narrowing_detector_tag, std::initializer_list il) - { - (void) il; - } -}; -} // namespace detail - /// The `value` is true if the following expression is well-formed: /// @code -/// To x[] = { std::forward(from), std::forward(from) }; +/// To x[] = { std::forward(from) }; /// @endcode template struct is_convertible_without_narrowing : std::false_type @@ -128,8 +113,16 @@ template struct is_convertible_without_narrowing< From, To, - void_t{std::declval(), - {std::declval(), std::declval()}})>> : std::true_type + // The number of braces is of an essential importance here: {{ }} attempts to initialize the first element + // of the array with the value, while {{{ }}} performs direct-list-initialization of To. + // Incorrect usage of the braces will cause incorrect detection of the applicable conversion. + // Notice that there is a subtle difference between C++14 and the newer standards with the guaranteed copy + // elision: a double-brace conversion is invalid in C++14 for noncopyable types while in C++17+ it is valid. + // + // An alternative way to test the conversion is to define a function that accepts an array rvalue: + // static void test_conversion(To (&&)[1]); + // And check if it is invocable with the argument of type From. + void_t{{{std::declval()}}})>> : std::true_type {}; static_assert(is_convertible_without_narrowing::value, "self-test failure"); static_assert(!is_convertible_without_narrowing::value, "self-test failure");