Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Rename "aggregate_initialize" to "no_narrowing""
This reverts commit 1380b7e.
  • Loading branch information
yaito3014 committed Mar 13, 2026
commit c378972919699dc3ea4ca3bcad2d954902ed2dda
14 changes: 7 additions & 7 deletions include/iris/rvariant/rvariant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,10 @@ class rvariant : private detail::rvariant_base_t<Ts...>
(!std::is_same_v<std::remove_cvref_t<T>, rvariant>) &&
(!is_ttp_specialization_of_v<std::remove_cvref_t<T>, std::in_place_type_t>) &&
(!is_ctp_specialization_of_v<std::remove_cvref_t<T>, std::in_place_index_t>) &&
std::is_constructible_v<typename no_narrowing_resolution<T, Ts...>::type, T>
std::is_constructible_v<typename aggregate_initialize_resolution<T, Ts...>::type, T>
constexpr /* not explicit */ rvariant(T&& t)
noexcept(std::is_nothrow_constructible_v<typename no_narrowing_resolution<T, Ts...>::type, T>)
: base_type(std::in_place_index<no_narrowing_resolution<T, Ts...>::index>, std::forward<T>(t))
noexcept(std::is_nothrow_constructible_v<typename aggregate_initialize_resolution<T, Ts...>::type, T>)
: base_type(std::in_place_index<aggregate_initialize_resolution<T, Ts...>::index>, std::forward<T>(t))
{}

IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_BEGIN
Expand All @@ -632,12 +632,12 @@ IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_BEGIN
template<class T>
requires
(!std::is_same_v<std::remove_cvref_t<T>, rvariant>) &&
detail::variant_assignable<typename no_narrowing_resolution<T, Ts...>::type, T>::value
detail::variant_assignable<typename aggregate_initialize_resolution<T, Ts...>::type, T>::value
constexpr rvariant& operator=(T&& t)
noexcept(detail::variant_nothrow_assignable<typename no_narrowing_resolution<T, Ts...>::type, T>::value)
noexcept(detail::variant_nothrow_assignable<typename aggregate_initialize_resolution<T, Ts...>::type, T>::value)
{
using Tj = no_narrowing_resolution<T, Ts...>::type; // either plain type or wrapped with recursive_wrapper
constexpr std::size_t j = no_narrowing_resolution<T, Ts...>::index;
using Tj = aggregate_initialize_resolution<T, Ts...>::type; // either plain type or wrapped with recursive_wrapper
constexpr std::size_t j = aggregate_initialize_resolution<T, Ts...>::index;
static_assert(j != std::variant_npos);

this->raw_visit([this, &t]<std::size_t i, class Ti>(std::in_place_index_t<i>, [[maybe_unused]] Ti& ti)
Expand Down
23 changes: 11 additions & 12 deletions include/iris/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,38 +272,37 @@ struct aggregate_initialize_tag
};

template<std::size_t I, class Ti>
struct no_narrowing_overload
struct aggregate_initialize_overload
Comment thread
yaito3014 marked this conversation as resolved.
Outdated
{
template<class T>
auto operator()(T&&) -> aggregate_initialize_tag<I, Ti>
auto operator()(Ti, T&&) -> aggregate_initialize_tag<I, Ti>
requires is_convertible_without_narrowing_v<T, Ti>
Comment on lines 277 to +279

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the first parameter Ti can be omitted, as it existed for checking is_convertible by passing-by-value

@yaito3014 yaito3014 Mar 13, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the Ti parameter cannot be omitted, since we should consider overload resolution for Ti including implicit conversion sequence's priority.

For example, constructing rvariant<int, long> from int should be resolved to index() == 0 though both int and long are equally convertible from int without narrowing. This is because identity conversion should occur prior to integral promotion in standard conversion.

{
return {}; // silence MSVC warning
}
};

template<class Is, class... Ts>
struct no_narrowing_fun;
struct aggregate_initialize_fun;

// Imaginary function FUN of https://eel.is/c++draft/variant#ctor-14
template<std::size_t... Is, class... Ts>
struct no_narrowing_fun<std::index_sequence<Is...>, Ts...>
: no_narrowing_overload<Is, Ts>...
struct aggregate_initialize_fun<std::index_sequence<Is...>, Ts...>
: aggregate_initialize_overload<Is, Ts>...
{
using no_narrowing_overload<Is, Ts>::operator()...;
using aggregate_initialize_overload<Is, Ts>::operator()...;
};

template<class... Ts>
using aggregate_initialize_fun_for = no_narrowing_fun<std::index_sequence_for<Ts...>, Ts...>;
using aggregate_initialize_fun_for = aggregate_initialize_fun<std::index_sequence_for<Ts...>, Ts...>;

template<class Enabled, class T, class... Ts>
struct no_narrowing_resolution {};
struct aggregate_initialize_resolution {};

template<class T, class... Ts>
struct no_narrowing_resolution<
struct aggregate_initialize_resolution<
std::void_t<decltype(aggregate_initialize_fun_for<Ts...>{}(std::declval<T>(), std::declval<T>()))>, T, Ts...
>
{
> {
using tag = decltype(aggregate_initialize_fun_for<Ts...>{}(std::declval<T>(), std::declval<T>()));
using type = tag::type;
static constexpr std::size_t index = tag::index;
Expand All @@ -315,7 +314,7 @@ struct no_narrowing_resolution<
// because they would lead to unnecessarily nested instantiation for
// legitimate infinite recursion errors on recursive types.
template<class T, class... Ts>
struct no_narrowing_resolution : detail::no_narrowing_resolution<void, T, Ts...> {};
struct aggregate_initialize_resolution : detail::aggregate_initialize_resolution<void, T, Ts...> {};

} // iris

Expand Down