-1

In C++ we have angle brackets in different places and I think it's sometimes important to distinguish them when talking to other developers, e.g. during mob programming when navigating someone (e.g. "go to the arrow operator in line 36" or "now write the spaceship operator"). While I can of course call them "angle brackets", I think they have better names, depending on what they do.

I am thinking of

  1. comparison, like bool smaller = a < b;
  2. bit shift, like auto x = 1 << 8;
  3. console output, like std::cout << "Hello";
  4. console input, like int age; std::cin >> age;
  5. types, like std::vector<int> v;
  6. templates, like template<typename T> T t() { return 0;}
  7. member templates, if that is any different to 6.
  8. lambda parameters, like []<int>(){ return 5;}
  9. as part of pointers, like a->b();
  10. similarly, but with an additional asterisk, like x->*member();
  11. the new comparison, like int compare = a <=> b;
  12. the new return types, like auto main() -> int{}
  13. maybe even includes, like #include <iomanip>;, although these are preprocessor and not C++
  14. for completeness sake, the funny stuff like <: and :> or ??< and ??>
Thomas Weller
  • 55,411
  • 20
  • 125
  • 222

1 Answers1

4

In many cases, the angle brackets do not have a name themselves, because they are part of another construct.

  1. is called relational operator [source: C++ 20 standard, chapter 7.6.9, [expr.rel], page 140], also comparison operator or just less-than operator and greater-than operator
  2. is called shift operator [source: C++ 20 standard, chapter 7.6.7, [expr.shift], page 139]
  3. is called insertion operator [source: C++ 20 standard, chapter 29.7.5.6, [ostream.rvalue], page 1422], technically it's implemented as operator<<, just like the shift operator, but of course we don't call it shift operator, because we don't shift a stream.
  4. is called extraction operator [source: C++ 20 standard, chapter 29.7.4.6, [istream.rvalue], page 1413]

I've also heard the term chevron operator as the superordinate term for both, insertion operator and extraction operator.

  1. the whole thing (angle brackets plus type(s)) is called a template argument list [sources: C++ 20 standard, chapter 13.3, [temp.names], page 366, and chapter 13.4.1 (4), [temp.arg], page 369].
  2. the whole thing is a template parameter list [source: C++ 20 standard, chapter 13.1, [temp.pre], page 360]
  3. like 6
  4. this is also called a template parameter list [source: C++ 20 standard, chapter 7.5.5.1 (5), [expr.prim.lambda.general], page 103]

Regarding the last four: it's a parameter list in the declaration and an argument list when it's used.

  1. is an arrow or -> operator (probably pronounced arrow operator) [source: C++ 20 standard, chapter 7.6.1.5, [expr.ref], page 110].
  2. is a pointer to member operator [source: C++ 20 standard, chapter 7.6.4, [expr.mptr.oper], page 137].
  3. is called the three way comparison operator [source: C++ 20 standard, chapter 7.6.8, [expr.spaceship], page 140] or simply the spaceship operator.
  4. is called a trailing return type [source: C++ 20 standard, chapter 9.3.1, [dcl.decl.general], page 183]. For concepts, there's a similar thing called return type requirement [source: C++ 20 standard, chapter 7.5.7.4, [expr.prim.req.compound], page 115]
  5. is a header name [source: C++ 20 standard, chapter 5.8, [lex.header], page 16] and similar in [source: C++ 20 standard, chapter 15.2, [cpp.cond], page 462]
  6. the whole thing is a digraph [source: C++ 20 standard, chapter 5.5, [lex.digraph], page 15] or trigraph (until C++14) [source: C++ 20 standard, chapter C.2.2, [diff.cpp14.lex], page 1662]
Thomas Weller
  • 55,411
  • 20
  • 125
  • 222