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 indexes = xt::xtensor<size_t, 1>{};
auto value_map = xt::xtensor<double, 1>{};
auto f = [&](size_t index) -> auto& { return value_map[index]; };
auto values = xt::vectorize(f)(value_map);
*values.begin();

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions