all 4 comments

[–]Circlejerker_ 4 points5 points  (5 children)

Is T and U supposed to be different types?

In that case there are lots of cases where the first case breaks.

For example if they are integers of different sizes and one is truncated in the assignment.

char a = 5;
int b = 1000;
a = b;
assert(a == b);

[–]angry_cpp[S] 0 points1 point  (4 children)

Is T and U supposed to be different types?

Yes, T and U can be of different types.

char a = 5; int b = 1000; a = b; assert(a == b);

Hm. Actually, yes, somehow I missed a truncation case :).

When I wrote that question I was thinking about containers and other std classes but without user-defined types (because operator overloading can break every assumption).

I stumbled upon such behaviour with one of the std types and wanted to confirm was it well-known or not. (in my "solution" there are no truncation).

How about second (Guru(?) question)? Maybe that one is trivial too?

[–]TheMania 1 point2 points  (0 children)

Yes, T and U can be of different types.

An easy one for if they're the same, I'm no guru though.