Skip to content

Lambdas in various cases of std::apply in xfunction.hpp don't return correct types #2911

@vakokako

Description

@vakokako

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions