2

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   
Evgeny Eltishev
  • 593
  • 3
  • 18
  • 3
    Have you tried the code in an online compiler that uses gcc/clang? VS2013 has issues with variadic templates. It's possible that your code is correct and that the bug is in the compiler. – Borgleader Dec 21 '14 at 22:09
  • 2
    @Borgleader I checked it on IdeOne.com and you were right, it's VS issue. But still, is there any example of function with such signature? Why `const` and `volatile` can be put to non-member functions? – Evgeny Eltishev Dec 21 '14 at 22:18

1 Answers1

3

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.

Vaughn Cato
  • 63,448
  • 5
  • 82
  • 132
  • There's even an example in C++11's /10 (has moved to /6 in C++14, I think). You beat me by 10 s :) – dyp Dec 21 '14 at 23:00
  • 1
    @dyp: Nice. I'm sure you'll get me next time. – Vaughn Cato Dec 21 '14 at 23:07
  • There's actually very little that you can do with cv or ref qualifiers on non-member functions. They're legal, but pretty much useless. You can't declare a function that has them. You can't create a pointer to such a function. – Marshall Clow Dec 22 '14 at 20:06