After an update from #2876, the following code stopped compiling:
auto values_original = xt::xtensor<double, 1>{ 1., 2., 3. };
auto indexes = xt::arange<size_t>(values_original.size());
auto map = [&](const size_t& index) -> auto& { return values_original[index]; };
auto values_mapped = xt::vectorize(map)(indexes);
for (size_t i = 0; i < values_original.size(); ++i) {
EXPECT_TRUE(&(values_mapped[i]) == &(values_original[i]));
}
The reason is in this function:
|
template <class F, class... CT> |
|
inline auto xfunction_stepper<F, CT...>::operator*() const -> reference |
|
{ |
|
return std::apply( |
|
[&](auto&... e) |
|
{ |
|
return (p_f->m_f)(*e...); |
|
}, |
|
m_st |
|
); |
|
} |
Here, the lambda needs to have a return type reference instead of returning by value.
The same problem occurs in every use case of std::apply in xfunction.hpp.
After an update from #2876, the following code stopped compiling:
The reason is in this function:
xtensor/include/xtensor/core/xfunction.hpp
Lines 1108 to 1118 in 5caa64d
Here, the lambda needs to have a return type
referenceinstead of returning by value.The same problem occurs in every use case of std::apply in xfunction.hpp.