Skip to content

Commit

Permalink
Fix error C2668: 'operator new[]': ambiguous call to overloaded function
Browse files Browse the repository at this point in the history
See rttrorg#346 
Note that `std::is_bounded_array` is introduced in C++20.
  • Loading branch information
burak-yildizoz authored Apr 25, 2024
1 parent 7edbd58 commit b48341b
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/rttr/detail/variant/variant_data_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,16 @@ struct variant_data_policy_array_big : variant_data_base_policy<T, variant_data_

static RTTR_INLINE void clone(const T& value, variant_data& dest)
{
reinterpret_cast<array_dest_type&>(dest) = new T;
if constexpr (std::is_bounded_array_v<T>)
{
constexpr size_t size = std::extent_v<T>;
using Type = std::remove_extent_t<T>;
reinterpret_cast<array_dest_type&>(dest) = new Type[size];
}
else
{
reinterpret_cast<array_dest_type&>(dest) = new T;
}

COPY_ARRAY_PRE_PROC(value, dest);
}
Expand All @@ -530,7 +539,16 @@ struct variant_data_policy_array_big : variant_data_base_policy<T, variant_data_
static RTTR_INLINE void create(U&& value, variant_data& dest)
{
using array_dest_type = decltype(new T);
reinterpret_cast<array_dest_type&>(dest) = new T;
if constexpr (std::is_bounded_array_v<T>)
{
constexpr size_t size = std::extent_v<T>;
using Type = std::remove_extent_t<T>;
reinterpret_cast<array_dest_type&>(dest) = new Type[size];
}
else
{
reinterpret_cast<array_dest_type&>(dest) = new T;
}

COPY_ARRAY_PRE_PROC(value, dest);
}
Expand Down

0 comments on commit b48341b

Please sign in to comment.