Suppose I have a type T in C++. It has all sorts of methods, it can be used as a parameter to a bunch of functions etc.
Now suppose I want to work on k elements of type T, with k being known at compile-time and also small (e.g. k=2 or k=3); and with most/all actions being elementwise. Naturally, I could hold an std::array<T, n> and fill my code with loops such as:
for(auto i = 0; i < k; i++) { c[i] = foo( a[i], b[i] ); }
for a function T3 foo(T1 a, T2 b).
but I want to avoid that. Is there some convenient idiom I could use for working with these vectorized-T's as though they were just T's?
Ideally, I would be able to write:
vectorized<T1> a = bar();
vectorized<T2> b = baz();
auto c = foo(a,b);
and, based solely on the existence of the above-mentioned foo(), that would work. I don't realistically expect to get that far, but something loopless in that general direction would be nice.
Note:
- We're not talking SIMD vectorization here (although that's a potential optimization for compilers to consider).
- C++14 solutions are preferred, unfortunately. C++17/20 solutions are relevant (but would not be the accepted answer since I'm stuck with C++14).