On OS X, simple C++ program gives incorrect results (which are a result of command-line options ‘c++03’ vs ‘c++11’)

Firstly, the expected difference in behaviour is because the operator<<(std::ostream&, const char*) overload (it’s actually a function template specialization, but nevermind for now) has a parameter of type std::ostream& and an lvalue reference can only bind to an lvalue, and in your example the stream is an rvalue so that overload can’t be used. In … Read more

Concatenating strings doesn’t work as expected [closed]

Your code, as written, works. You’re probably trying to achieve something unrelated, but similar: std::string c = “hello” + “world”; This doesn’t work because for C++ this seems like you’re trying to add two char pointers. Instead, you need to convert at least one of the char* literals to a std::string. Either you can do … Read more

Haskell operator vs function precedence

Firstly, application (whitespace) is the highest precedence “operator”. Secondly, in Haskell, there’s really no distinction between operators and functions, other than that operators are infix by default, while functions aren’t. You can convert functions to infix with backticks 2 `f` x and convert operators to prefix with parens: (+) 2 3 So, your question is … Read more

Scala’s ‘::’ operator, how does it work?

From the Spec: 6.12.3 InfixOperations An infix operator can be an arbitrary identifier. Infix operators have precedence and associativity defined as follows. … The associativity of an operator is determined by the operator’s last character. Operators ending in a colon ‘:’ are right-associative. All other operators are left- associative. You can always see how these … Read more

What do >> and

The >> operator in your example is used for two different purposes. In C++ terms, this operator is overloaded. In the first example, it is used as a bitwise operator (right shift), 2 << 5 # shift left by 5 bits # 0b10 -> 0b1000000 1000 >> 2 # shift right by 2 bits # … Read more