【发布时间】:2016-01-11 11:21:02
【问题描述】:
考虑
namespace foo
{
namespace bar
{
void f();
void f(int);
}
}
在foo 中,可以通过foo::f 将所有foo::bar::f 访问
using bar::f; // in foo
不存在使所有foo::bar::f 可以像foo::g 一样访问的语法是否存在任何技术原因
using bar::f as g;
// or in line with using declarations for types:
using g = bar::f;
或者类似的事情被考虑过但被拒绝了? (为什么?)
【问题讨论】:
-
解决方法:
auto g = [](auto ...args){ foo::bar::f(std::forward<decltype(args)>(args)...); }; -
@KerrekSB:引入一个
g,它的匹配度可能远远超过任何f。 -
@Pixelchemist 好吧,可以使用 SFINAE 来规避这一点。
-
@Pixelchemist:是的,它会产生完全不同的重载集。
-
问题的背景是需要将函数推送到嵌套命名空间中,以使
using std::f;可用于尾随返回类型和constexpr规范。我想以不同的名称将它们拖出封闭的命名空间,因为它们所模仿的函数在std中具有相同的名称。
标签: c++ language-lawyer