Do all C++ operators return something?

No, not all operators return something. Although they are probably not exactly what you are thinking about, note that the delete and delete[] C++ ‘keywords’ are actually operators; and they are defined as having the void return type – which means they evaluate to nothing (which is not ‘something’). From cppreference: void operator delete ( … Read more

Is x += a quicker than x = x + a?

Any compiler worth its salt will generate exactly the same machine-language sequence for both constructs for any built-in type (int, float, etc) as long as the statement really is as simple as x = x + a; and optimization is enabled. (Notably, GCC’s -O0, which is the default mode, performs anti-optimizations, such as inserting completely … Read more

Why are bitwise shifts (>) used for cout and cin?

According to §8.3.1 of The Design and Evolution of C++: The idea of providing an output operator rather than a named output function was suggested by Doug McIlroy by analogy with the I/O redirection operators in the UNIX shell (>, >>, |, etc.) […] Several operators were considered for input and output operations: the assignment … Read more

~= operator in Swift

Simply use as a shortcut to “range”: you can construct a range and “~=” means “contains”. (other can add more theoretical details, but the sense is this). Read it as “contains” let n: Int = 100 // verify if n is in a range, say: 10 to 100 (included) if n>=10 && n<=100 { print(“inside!”) … Read more