Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should ellipsis in attribute-list in C++ be used for?

In C++ reference I found information about allowed syntax of attributes in C++, it is:

[[attribute-list]]
[[ using attribute-namespace : attribute-list ]]

"where attribute-list is a comma-separated sequence of zero or more attributes (possibly ending with an ellipsis ... indicating a pack expansion)"

I've tried to use its, but I see no difference between:

[[deprecated]] void f() 
{
}

and

[[deprecated...]] void f() 
{
}

In both cases output is the same.

like image 437
baziorek Avatar asked Feb 25 '18 23:02

baziorek


People also ask

What is __ attribute __ in C?

The __attribute__ directive is used to decorate a code declaration in C, C++ and Objective-C programming languages. This gives the declared code additional attributes that would help the compiler incorporate optimizations or elicit useful warnings to the consumer of that code.

What are the attributes used in C?

attr1 appertains to the variable declarations a and b, attr2 appertains to the type int, attr3 appertains to the variable declaration a, and attr4 appertains to the variable declaration b.

What is Va_list in C?

va_list is a complete object type suitable for holding the information needed by the macros va_start, va_copy, va_arg, and va_end. If a va_list instance is created, passed to another function, and used via va_arg in that function, then any subsequent use in the calling function should be preceded by a call to va_end.

What are variadic functions in C?

Variadic functions are functions that can take a variable number of arguments. In C programming, a variadic function adds flexibility to the program. It takes one fixed argument and then any number of arguments can be passed.


1 Answers

This was added to the specification for consistency and also because the future of attributes is still being discussed. Considering that we currently have pack expansion in variadic templates (see Variadic template pack expansion) like this:

// pack expansion in function arguments
template <typename... Args>
void f(Args... args) {}

// pack expansion in inheritance
template <typename... Inherited>
struct MyClass : Inherited... {};

Along the same lines, it also makes sense to think about pack expansion for attributes. A few example scenarios could be:

template <typename... Ts>
class [[Ts...]] MyClass {};

or

template <typename... Ts>
class [[Ts()...]] MyClass {};

But, again, this is only in the specification and currently there is no attribute that can be used like that.

like image 115
HugoTeixeira Avatar answered Nov 09 '22 05:11

HugoTeixeira