Pix*_*ist 16 c++ language-lawyer
考虑
namespace foo
{
namespace bar
{
void f();
void f(int);
}
}
Run Code Online (Sandbox Code Playgroud)
在foo一个可以使所有foo::bar::f可访问为foo::fvia
using bar::f; // in foo
Run Code Online (Sandbox Code Playgroud)
是否有任何技术原因,语法的不存在性,使所有foo::bar::f可访问foo::g样
using bar::f as g;
// or in line with using declarations for types:
using g = bar::f;
Run Code Online (Sandbox Code Playgroud)
或者有这样的事情甚至被考虑但被拒绝了?(为什么?)
Tar*_*ama 10
我想不出任何技术原因,我认为这是一个合适的(非冲突)语法和一个非常重要的用例的问题.
目前有一个标准提议是为语言添加函数别名以支持opaque typedef.根据那篇论文,这个特征以前在90年代初考虑过,但被拒绝了:
Stroustrup在他的D&E书中将[函数别名]描述为在解决由于多重继承引起的名称冲突的上下文中的"重命名"特性:"这个概念的语义很简单,实现很简单; 问题似乎是要找到一个合适的语法."他说这样的提议"是在1990年的西雅图标准会议上提出的",虽然最初有"绝大多数",但这个特征最终没有被采纳: "在下次会议上,...我们同意这种名称冲突不太可能足以保证单独的语言功能."
建议的语法如下:
template< class RA, class R = std::less<> >
void
sort( RA b, RA const e, R lt = {} )
{
using operator<() = lt; // operator < has type R
// Remaining code in this scope uses infix < in place of calls to lt().
// (A future proposal may suggest synthesis of other relational
// operators from an operator< declared in this fashion.)
}
Run Code Online (Sandbox Code Playgroud)
参加最近的标准会议的人也许可以权衡对提案的反应.