<< operator for arrays

f(x) = x << 3

What does this code do when you read it in a file? How would you document f?

Taking from another language that abused <<:

C.163: Overload only for operations that are roughly equivalent

Reason Having the same name for logically different functions is confusing and leads to errors when using generic programming. Example > Consider:

void open_gate(Gate& g);   // remove obstacle from garage exit lane
void fopen(const char* name, const char* mode);   // open file

The two operations are fundamentally different (and unrelated) so it is good that their names differ.

void open(Gate& g);   // remove obstacle from garage exit lane
void open(const char* name, const char* mode ="r");   // open file

The two operations are still fundamentally different (and unrelated) but the names have been reduced to their (common) minimum, opening opportunities for confusion.

9 Likes