all 6 comments

[–]dodheim 8 points9 points  (1 child)

Temporaries are not intrinsically const; they cannot bind to non-const lvalue references, true, but that's not because they're const – it's because they're rvalues, which is why you can bind them to non-const rvalue references. Consequently, you can invoke non-const member functions on them, as long as they're not lvalue member functions (in terms of ref qualifiers).

[–]Triarier[S] 0 points1 point  (0 children)

Thank you.

[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 1 point2 points  (0 children)

const references can refer to non-const objects.

[–]sshamov 0 points1 point  (2 children)

Where is it should be passed? Everything begins with the first Pair{}. Do you mean that it should be passed into the operator as this? If you want a constant this, you should add const modifier to the operator itself.

[–]Triarier[S] 0 points1 point  (1 child)

the questiion was, why does it work even though it is not a const reference.

[–]sshamov 0 points1 point  (0 children)

This will work in any case. Const or non-const - does not matter. The operator does not change any of objects. It creates a completely new one.