I have class like this:
struct S{
void method1(int *a){
// use a
}
void method2(int *a){
// use a
}
};
To avoid allocation, I am doing following:
std::array<int, 100> a;
S s;
s.method1(a.data());
However much nicer will be if I can able to do, without making all methods templates.
std::array<int, 100> a;
S s;
s.method1(a);
In C++20 I can use std::span, but currently I want to avoid it as well.
Any easy way to define some operator that will be able to convert / cast, but only inside the class?
std::arrayis not to decay to a pointer. You may useint a[100]if you need the implicit array to pointer decay.std::arrayfora, as it will occupy ~400 bytes (assumingintis 4 bytes) on the stack which is quite a lot.