fix make_array with is_convertible_without_narrowing

This commit is contained in:
Laurent Rineau 2024-04-23 14:29:33 +02:00
parent ca1f11d715
commit 940a7ebe9f
1 changed files with 8 additions and 1 deletions

View File

@ -13,6 +13,7 @@
#define CGAL_ARRAY_H
#include <CGAL/config.h>
#include <CGAL/type_traits.h>
#include <array>
#include <utility>
@ -63,7 +64,13 @@ constexpr
std::array<Make_array_element_type_t<T, Args...>, sizeof...(Args) >
make_array(Args&& ... args)
{
return {{ std::forward<Args>(args)... }};
using Target_type = Make_array_element_type_t<T, Args...>;
if constexpr ( (CGAL::is_convertible_without_narrowing_v<cpp20::remove_cvref_t<Args>, Target_type>&&...) )
return {{ std::forward<Args>(args)... }};
else {
std::array< Target_type, sizeof...(Args) > a = { { static_cast<Target_type>(args)... } };
return a;
}
}
// Functor version