Open
Description
This would allow to optimize code using standard algorithms on containers holding xtensor containers:
std::vector<xarray<double>> lhs;
std::vector<xaray<double>> a;
std::vector<xarray<double>> b;
std::transform(a.cbegin(), a.cend(), b.cbegin(), lhs.begin(), [](const auto& xa, const auto& xb) { return xa + xb; });
The last line is equivalent to
auto it_lhs = lhs.begin();
for (auto ita = a.cebgin(), itb = b.cbegin(); ita != ita.cend(); ++ita, ++ibt)
{
*it_lhs++ = *ita + *ibt;
}
The following line *it_lhs++ = *ita + *ibt;
uses a temporary to avoid aliasing. However, in this case, we would like to have
noalias(*it_lhs++) = *ita + *itb;
instead.
The usage would be:
std::transform(a.cbegin(), a.cend(), b.cbegin(), noalias_begin(lhs), [](const auto& xa, const auto& xb) { return xa + xb; });