在 C++ 中使用 `restrict` 类型限定符和 `unique_ptr` 的受限别名

Restricted Aliasing using `restrict` type qualifier and `unique_ptr` in C++

在 GNU GCC 编译器提供的 C++ 扩展部分中限制 pointer aliasing, I have used so far the __restrict__ type qualifier as described here。比如下面的函数,

void fn (int *__restrict__ rptr, int &__restrict__ rref)
 {
   /* ... */
 }

接受受限指针和受限引用作为其参数。

随着 unique_ptr 被引入 C++ 标准,我想知道 GCC 编译器是否会通过使用 unique_ptr.

提供相同的优化(或更好)的机器代码

是否还应该使用 __restrict__ 这样的扩展名?在最近的 C++ 标准中是否有更好的方法来产生相同的优化(对于指针和引用)?

__restrict__unique_ptr 做不同的事情。 __restrict__ 承诺没有其他内容引用此对象(因此编译器可以优化)。 unique_ptr 管理堆分配对象的生命周期。它不允许优化器做出任何假设。

如果有一种说法就好了"this unique_ptr is the only way of referring to this object",但我不知道 GCC 是否支持。