Skip to content

Commit

Permalink
In array cross-construction include implicit cast of ValueType
Browse files Browse the repository at this point in the history
  • Loading branch information
Wentzell committed Sep 16, 2024
1 parent 4ad0c2a commit 958fa60
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions c++/nda/basic_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,12 @@ namespace nda {
* @param a nda::ArrayOfRank object.
*/
template <ArrayOfRank<Rank> A>
requires(HasValueTypeConstructibleFrom<A, value_type>)
requires(HasValueTypeConstructibleFrom<A, ValueType>)
basic_array(A const &a) : lay(a.shape()), sto{lay.size(), mem::do_not_initialize} {
static_assert(std::is_constructible_v<value_type, get_value_t<A>>, "Error in nda::basic_array: Incompatible value types in constructor");
static_assert(std::is_constructible_v<ValueType, get_value_t<A>>, "Error in nda::basic_array: Incompatible value types in constructor");
if constexpr (std::is_trivial_v<ValueType> or is_complex_v<ValueType>) {
// trivial and complex value types can use the optimized assign_from_ndarray
assign_from_ndarray(a);
assign_from_ndarray(nda::map([](auto &val) { return static_cast<ValueType>(val); })(a));
} else {
// general value types may not be default constructible -> use placement new
nda::for_each(lay.lengths(), [&](auto const &...is) { new (sto.data() + lay(is...)) ValueType{a(is...)}; });
Expand Down

0 comments on commit 958fa60

Please sign in to comment.