多次使用 [x, y, z, ...]-clause 语法,不应该允许 operator[] 接受多个参数吗?

With several uses of [x, y, z, ...]-clause syntax, shouldn't operator[] be allowed to accept multiple parameters?

从 C++11 开始,我们可以编写 lambda 表达式,例如:

auto foo = [a, b]() { return a+b; };

带方括号的捕获子句,其中的项目用逗号分隔。在 C++17 中,我们将能够使用结构化绑定:

for (const auto& [name, description] : planet_descriptions) {
    std::cout << "Planet " << name << ":\n" << description << "\n\n";
}

这是逗号分隔方括号从句的另一个示例。

然而,我们不能覆盖 class' operator[] 来获取多个参数,例如这个:

template<typename V, typename I, typename J>
const V& operator[](I i, J j) const {
    return data_[width() * i + j];
}

not compile

我知道有变通办法——这里提到了很多:

C++ [] array operator with multiple arguments?

但是 - 为什么前者是语言的一部分而后者是不可能的,即使是程序员自行决定的重载?仅仅是因为没有人提出其他建议,还是有一些特定的原因?

备注:

这当然是一个选择,尽管对许多人来说令人惊讶,因为一般倾向于坚持 C 程序员熟悉的运算符的 C 语法。

这也不是一个新想法,Gabriel Dos Reis 在 2014 年提出了它。Uniform handling of operator[] and operator() 的想法的最后记录状态如下:

In c++std-core-14770, Dos Reis suggests that operator[] and operator() should both be allowed to be static. In addition to that, he suggests that both should allow multiple parameters. It's well known that there's a possibility that this breaks existing code (foo[1,2] is valid, the thing in brackets is a comma-expression) but there are possibilities to fix such cases (by requiring parens if a comma-expression is desired). EWG should discuss whether such unification is to be strived for.

Discussed in Rapperswil 2014. EWG points out that there are more issues to consider here, in terms of other operators, motivations, connections with captureless lambdas, who knows what else, so an analysis paper is requested.

所以用这位著名的 C++ 语言理论家的话来说:如果你喜欢它,那就写一篇关于它的论文。