我怎么能不将函数(std :: bind)包装到命名空间中?

use*_*087 4 c++ bind wrapper

我想将绑定类模板包装到一个单独的命名空间:

namespace my_space {
template<typename... R> using bind = std::bind<R...>;
}
Run Code Online (Sandbox Code Playgroud)

并得到一个错误:

error: 'bind<R ...>' in namespace 'std' does not name a type.
Run Code Online (Sandbox Code Playgroud)

我怎么能这样做?这里可以找到一个小例子.

Sho*_*hoe 8

为什么你的代码不起作用

您的代码无法编译,因为它std::bind是一个函数,而不是一个类型.您可以using仅为类型声明别名.

虽然g++诊断不是最好的,但Clang ++会给以下错误:

错误:预期的类型

哪个更清楚*.

你可以做什么

谢天谢地,您可以std::bind使用以下命令导入名称:

namespace my_space {
    using std::bind;
}
Run Code Online (Sandbox Code Playgroud)

Live demo

具体定义如下:

§7.3.3/ 1所述的using声明[namespace.alias]

using声明在声明区域中引入了一个名称,其中出现using声明.

*个人意见.