为什么禁止“braced-init-list”在内置的“operator[]”中?
我刚刚注意到,在 N3291 中标记了一个更改(5.2.1 下标 [expr.sub]):
之前,可以使用新的重载 operator[]
braced-init-list:
struct X {
Z operator[](std::initializer_list<int>);
};
X x;
x[{1,2,3}] = 7; // OK: meaning x.operator[]({1,2,3})
现在已删除并替换为:
花括号初始化列表不得与内置下标运算符一起使用。
问题出在哪里?
I just noticed, that in N3291 a change is marked (5.2.1 Subscripting [expr.sub]):
Before, it was ok to overload operator[]
with the new braced-init-list:
struct X {
Z operator[](std::initializer_list<int>);
};
X x;
x[{1,2,3}] = 7; // OK: meaning x.operator[]({1,2,3})
Now that is removed and replaced with:
A braced-init-list shall not be used with the built-in subscript operator.
What was the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
x[{1,2,3}]
不是内置的[]
运算符。它调用用户定义的运算符函数。因此,深呼吸并继续使用这种有趣的语法。x[{1,2,3}]
is not the built-in[]
operator. It invokes a user defined operator function. So take a deep breath and go on using this fun syntax.一些仔细的谷歌搜索将我指向问题798< /a>,他们只是将其移动到13.5.5 [over.sub],而不是删除 它。
some careful googling pointed me to issue 798, they only moved it to 13.5.5 [over.sub], not deleted it.