0

I found it slow when calculate expression of array. So I wonder about can I use rvalue to store the intermediate results for reducing alloc action?

#include "SArray.hpp"

template <typename T>
SArray<T>&& operator* (SArray<T>&& s, const T& scale) {
    for (size_t i = 0; i < s.size(); ++i)
        s[i] *= scale;
    return std::move(s);
}

int main() {

    SArray<int> w = SArray<int>({1,2,3,4,5,6}) * 2;

    return 0;
}
Luster
  • 171
  • 1
  • 1
  • 5

0 Answers0