ヌルであってはならないポインタを表現するときは、私は__attribute__((nonnull))
の使用に慣れています。"__attribute __((nonnull))" vs "not_null <T*>"はいつ使用しますか?
void f(int* ptr __attribute__((nonnull)));
int main(){
int* ptr = new int(1);
f(ptr);
}
void f(int* ptr){/*impl*/}
しかし、GSLと、not_null<T*>
ラッパータイプもあります。
void function1(gsl :: not_null n);
void f(gsl::not_null<int*> n);
int main(){
int* ptr = new int(1);
f(ptr);
}
void f(gsl::not_null<int*> n){/*impl*/}
言語機能は、私はいつも今__attribute__((nonnull))
の代わりにnot_null<T*>
を使用する必要があり、GSLのバージョンをサポートするために存在していると仮定すると?
私は、コンパイラ属性が最適化を助けているかもしれないが、ラッパーバージョンが非アトリビュートポインタに解決されるという印象を受けました。 「私はいつも属性((非NULL))の代わりにNOT_NULLを使用する必要があります
1つの質問は、 '__attribute __ (nonnull)) '主要なコンパイラ間で移植可能? – WhiZTiM
リファレンスや 'span'を使わないのはなぜですか? – Jarod42