If you want to perform non-aliased operations on the underlying object associated with a shared pointer you could explicitly delegate to a worker routine that takes a non-aliased pointer parameter:
void worker (mytype *__restrict x, mytype *__restrict y)
{
// do something with x, y with a no-alias guarantee
}
int main()
{
std::shared_ptr<mytype> p(new mytype);
std::shared_ptr<mytype> q(new mytype);
// explicitly delegate the shared object
worker(p.get(), q.get());
return 0;
}
I'm not sure exactly what you have in mind, but this would allow the high-level memory management to be dealt with safely by the smart pointer, while doing the low level work possibly more efficiently with no-alias pointers.
As @BenVoigt pointed out, restrict
is only offically part of c99
- c++
isn't supposed to know anything about it. MSVC
supports it anyway via __restrict
and as you've said GCC
has __restrict__
.
Hope this helps.
restrict
or__restrict__
keyword. If you're asking about language extensions in a particular compiler, you need to say which. – Blackcapstd::shared_ptr<T>
s. – Inaccurate