Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User-defined attributes in C++11?

Is there a way to create user-defined attributes in C++11 or later?

For example,

[[noreturn]] void exit();

is a compiler-defined C++11 attribute.

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.

like image 637
oconnor0 Avatar asked Jan 15 '16 19:01

oconnor0


People also ask

What are user defined attributes?

User Defined Attributes are a user customized property of elements and panels. This could be amongst other things; A Name to define things such as Notes, Finish, Specification etc. A Number to define things such as Class, Phase etc.

What are the attributes used in C?

Attributes are a mechanism by which the developer can attach extra information to language entities with a generalized syntax, instead of introducing new syntactic constructs or keywords for each feature.

How do you create a user defined attribute?

From the Administration tab, expand Roles > Default > Business Objects > Request. Click Attributes, and in the Attributes screen for the Request business object, click Create Attribute. Enter the name of the user-defined attribute.

What is attributes in C++ with example?

Everything in C++ is associated with classes and objects, along with its attributes and methods. For example: in real life, a car is an object. The car has attributes, such as weight and color, and methods, such as drive and brake. Attributes and methods are basically variables and functions that belongs to the class.


2 Answers

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 :

One planned use for attributes is improved support for 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.

like image 55
Nùménor Avatar answered Nov 13 '22 07:11

Nùménor


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.

like image 32
Martin Bonner supports Monica Avatar answered Nov 13 '22 07:11

Martin Bonner supports Monica