自己的 std::is_function 实现 [英] own std::is_function implementation

查看:32
本文介绍了自己的 std::is_function 实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

建议此处以下列方式实现:

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 {};

但它是一个有效的函数语法吗?Visual Studio 2013 报错:

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

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

推荐答案

函数参数之后的constvolatile 称为 cv-qualifier-seq.C++14 标准的第 8.3.5 节第 6 段说:

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:

带有 cv-qualifier-seq 或 ref-qualifier 的函数类型(包括由 typedef-name (7.1.3,14.1)) 命名的类型应仅显示为:

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,

——函数 typedef 声明或别名声明的顶级函数类型,

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

— 类型参数 (14.1) 的默认参数中的类型 ID,或

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

——类型参数的模板参数的类型 ID (14.3.1).

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

在您的示例中,Ret(Args...)constRet(Args...)volatile 满足最后一种情况.

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

这篇关于自己的 std::is_function 实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆