gpt4 book ai didi

c++ - 自己的 std::is_function 实现

转载 作者:搜寻专家 更新时间:2023-10-31 01:41:59 24 4
gpt4 key购买 nike

建议here以下列方式实现:

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 报错:

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

最佳答案

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

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).

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

关于c++ - 自己的 std::is_function 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27594273/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com