Skip to content

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

Closed

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.

Activity

  1. JohanMabille commented on May 6, 2026

    @JohanMabille
    Member

    Wow good catch! Unbelievable that we haven't catched it earlier!

  2. added a commit that references this issue on May 12, 2026
    6c2e51b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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