Under what circumstances are __rmul__ called?

When Python attempts to multiply two objects, it first tries to call the left object’s __mul__() method. If the left object doesn’t have a __mul__() method (or the method returns NotImplemented, indicating it doesn’t work with the right operand in question), then Python wants to know if the right object can do the multiplication. If … Read more

Why does the = operator work on structs without having been defined?

If you do not define these four methods (six in C++11) the compiler will generate them for you: Default Constructor Copy Constructor Assignment Operator Destructor Move Constructor (C++11) Move Assignment (C++11) If you want to know why? It is to maintain backward compatibility with C (because C structs are copyable using = and in declaration). … Read more

In PHP, what does “

That’s heredoc syntax. You start a heredoc string by putting <<< plus a token of your choice, and terminate it by putting only the token (and nothing else!) on a new line. As a convenience, there is one exception: you are allowed to add a single semicolon after the end delimiter. Example: echo <<<HEREDOC This … Read more

What needs to be overridden in a struct to ensure equality operates properly?

An example from msdn public struct Complex { double re, im; public override bool Equals(Object obj) { return obj is Complex c && this == c; } public override int GetHashCode() { return re.GetHashCode() ^ im.GetHashCode(); } public static bool operator ==(Complex x, Complex y) { return x.re == y.re && x.im == y.im; } … Read more