In C++, we have square brackets in different places and I think it's sometimes important to distinguish them when talking to other developers. While I can call all of them "square brackets", I think they have better names, depending on what they do.
I am thinking of
int arr[1024];arr[13] = 17;int x = arr[13];int y = map["key"];auto lambda = [&](){return 23 + arr[13];};delete[][[deprecated("for reasons")]]auto [x, y] = std::make_pair(1, 2);IMHO, the array assignment and array access brackets are called subscript operator. What about all the others? Do they have good names?
(2), (3), (4) — arr[13] — It's an operator. So, "subscript operator" or "square brackets operator"? To further point out the lhs type, "{map,vector,array} subscript operator"?
(1) — int arr[1024]; — The grammar doesn't seem to have a name specifically for the brackets. The whole arr[1024] is an "(array) declarator".
My colleague called the array declaration brackets (1.) "subscript operator" and I felt that this is the wrong term
I would point out that it's not an operator, without suggesting an other term. Just call them brackets.
(5) — [...](){} — This is commonly called a "lambda capture list". The grammar calls it a "lambda-introducer", but the term feels rather obscure.
(6) — delete[] — The whole thing is an array delete (expression). The brackets themselves don't have a separate name.
(7) — [[nodiscard]] — The whole thing is an "attribute" (the grammar calls it an "attribute-specifier", or "...-seq" for a list of attributes). The double brackets themselves don't seem to have a separate name.
(8) — auto [x, y] — The whole thing is a "structured binding (declaration)", or a "decomposition declaration" (I've only seen the latter in Clang error messages, not in the standard). The brackets themselves don't have a separate name here. The thing enclosed in brackets is called an identifier-list in the grammar.
new keyword).delete is the delete expression operator as per C++20 draft [expr.delete] (N4713, chapter 8.5.2.5). The array version of it is just an alternative.Source: C++20 Draft N4713
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With