Evgeny Eltishev
Evgeny Eltishev

Reputation: 603

own std::is_function implementation

It's suggested here to be implemented in a following way:

template<class Ret, class... Args>
struct is_function<Ret(Args...)const> : std::true_type {};
template<class Ret, class... Args>
struct is_function<Ret(Args...)volatile> : std::true_type {};

But is it a valid function syntax? Visual Studio 2013 gives an error:

error C2270: 'abstract declarator' : modifiers not allowed on nonmember functions   

Upvotes: 2

Views: 379

Answers (1)

Vaughn Cato
Vaughn Cato

Reputation: 64308

The const or volatile after the function parameters is called a cv-qualifier-seq. Section 8.3.5 paragraph 6 of the C++14 standard says:

A function type with a cv-qualifier-seq or a ref-qualifier (including a type named by typedef-name (7.1.3,14.1)) shall appear only as:

— the function type for a non-static member function,

— the function type to which a pointer to member refers,

— the top-level function type of a function typedef declaration or alias-declaration,

— the type-id in the default argument of a type-parameter (14.1), or

— the type-id of a template-argument for a type-parameter (14.3.1).

In your example, Ret(Args...)const and Ret(Args...)volatile satisfy the last case.

Upvotes: 3

Related Questions