Skip to content

Commit

Permalink
revert fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
serges147 committed Sep 26, 2024
1 parent 13ff0ee commit c5aa5e3
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions include/cetl/type_traits_ext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,9 @@ struct partial

// --------------------------------------------------------------------------------------------

namespace detail
{
enum narrowing_detector_tag
{
};
template <typename T>
struct narrowing_detector
{
narrowing_detector(narrowing_detector_tag, std::initializer_list<T> il)
{
(void) il;
}
};
} // namespace detail

/// The `value` is true if the following expression is well-formed:
/// @code
/// To x[] = { std::forward<From>(from), std::forward<From>(from) };
/// To x[] = { std::forward<From>(from) };
/// @endcode
template <typename From, typename To, typename = void>
struct is_convertible_without_narrowing : std::false_type
Expand All @@ -128,8 +113,16 @@ template <typename From, typename To>
struct is_convertible_without_narrowing<
From,
To,
void_t<decltype(detail::narrowing_detector<To>{std::declval<detail::narrowing_detector_tag>(),
{std::declval<From>(), std::declval<From>()}})>> : 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<decltype(std::array<To, 1>{{{std::declval<From>()}}})>> : std::true_type
{};
static_assert(is_convertible_without_narrowing<std::uint32_t, std::uint64_t>::value, "self-test failure");
static_assert(!is_convertible_without_narrowing<std::uint64_t, std::uint32_t>::value, "self-test failure");
Expand Down

0 comments on commit c5aa5e3

Please sign in to comment.