简体   繁体   English

C ++ 11中用户定义的属性?

[英]User-defined attributes in C++11?

Is there a way to create user-defined attributes in C++11 or later? 有没有办法在C ++ 11或更高版本中创建用户定义的属性?

For example, 例如,

[[noreturn]] void exit();

is a compiler-defined C++11 attribute. 是编译器定义的C ++ 11属性。

I'd like to define something like: 我想定义类似的东西:

[[comingsoon]] int function(int);

Is there a mechanism for this? 这有机制吗?

Edit: I should mention I'm using Clang. 编辑:我应该提到我正在使用Clang。

For now it's not possible to define user-attributes. 目前,无法定义用户属性。

There is, as far as i know, no information about if this feature is planned or not. 据我所知,没有关于此功能是否已计划的信息。 However, look at this FAQ answer from Stroustrup : https://isocpp.org/wiki/faq/cpp11-language-misc#attributes , especially this part : 但是,请查看Stroustrup的这个FAQ答案: https//isocpp.org/wiki/faq/cpp11-language-misc#attributes ,尤其是这部分:

One planned use for attributes is improved support for OpenMP. 对属性的一种计划用途是改进对OpenMP的支持。 For example: 例如:

for [ [ omp::parallel() ] ] (int i=0; i<v.size(); ++i) {
    // ...
}

It could mean that they plan to allow programmer to define it's own attribute. 这可能意味着他们计划允许程序员定义它自己的属性。 Wait & see. 等着看。

The language provides no way of adding attributes. 该语言无法添加属性。

Of course, if you are using Clang, you can edit the source of Clang , and add any attributes you like. 当然,如果你使用的是Clang,你可以编辑Clang的源代码,并添加你喜欢的任何属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM