简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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