I (mostly) like the new C++ Core Guidelines initiative, and what the Guidelines Support Libary offers. Specifically, I want to use span
s more. However, I'm coming up against the issue of __restrict__
not being part of C++ while I want to/need to use it.
To be more concrete: Without span
's, I would declare:
void foo(int* __restrict__ p, size_t len);
But if I now declare:
void foo(gsl::span<int> s);
I don't get the __restrict__
effect unless my compiler super-smart. I could pray real hard to the gods of gcc/clang/msvc and say:
void foo(gsl::span<int> __restrict__ s);
or alternatively, I could tweak the GSL span<T>
implementation so that the T* begin
and T* end
pointers are themselves __restrict__
'ed. However, it's not at all certain this will be respected.
So, can I force the __restrict__
'ion somehow? Or should I just give it up? This kind of takes the fun out of switching to span
's...
__restrict__
ongsl::span
you probably don't want to usegsl::span
in the first place, but first I'd make sure that switching to span actually slows down your program. – Soupandfishint* __restrict__ p = s.data();
? – Swelter__restrict__
may provide, the overhead introduced bygsl::span
will probably forbidding. If you care about a particular piece of code, where__restrict__
allows the compiler to generate significantly more efficient code then it is very likely, that the added indirection will break those compiler optimizations. – Soupandfish