diff --git a/include/boost/variant2/variant.hpp b/include/boost/variant2/variant.hpp index 6315832..311d83b 100644 --- a/include/boost/variant2/variant.hpp +++ b/include/boost/variant2/variant.hpp @@ -848,7 +848,15 @@ template using resolve_overload_index = mp11::mp_find using get_index_type = unsigned; +template using get_smallest_unsigned_type = mp11::mp_cond< + + mp11::mp_bool< N <= (std::numeric_limits::max)() >, unsigned char, + mp11::mp_bool< N <= (std::numeric_limits::max)() >, unsigned short, + mp11::mp_true, unsigned + +>; + +template using get_index_type = get_smallest_unsigned_type< (Double + 1) * sizeof...(T) >; // variant_base @@ -1000,7 +1008,7 @@ template struct variant_base_impl st_[ i2 ].emplace( mp11::mp_size_t(), std::forward(a)... ); static_assert( J * 2 + 1 <= (std::numeric_limits::max)(), "" ); - ix_ = J * 2 + i2; + ix_ = static_cast( J * 2 + i2 ); } static constexpr bool uses_double_storage() noexcept @@ -1193,7 +1201,7 @@ template struct variant_base_impl void _destroy() noexcept { - mp11::mp_with_index<1 + sizeof...(T)>( ix_ / 2, _destroy_L1{ this, ix_ & 1 } ); + mp11::mp_with_index<1 + sizeof...(T)>( ix_ / 2, _destroy_L1{ this, static_cast( ix_ & 1 ) } ); } ~variant_base_impl() noexcept @@ -1236,7 +1244,7 @@ template struct variant_base_impl _destroy(); static_assert( J * 2 + 1 <= (std::numeric_limits::max)(), "" ); - ix_ = J * 2 + i2; + ix_ = static_cast( J * 2 + i2 ); } static constexpr bool uses_double_storage() noexcept