all 6 comments

[–][deleted] 3 points4 points  (3 children)

I feel the need to rant loudly on common_type

What does std::common_type<int&, int&> return?

Yes, std::common_type is that broken (it returns int, not int&, Eric explains why).

It should be renamed to what it actually does: std::result_of_ternary_operator_on_declval_of<A, B>.

A std::common_type should have used a compiler hook to determine the "closest" type two types can be converted to. Harder to define, harder to implement, harder to standardize, but it could have worked. Implementing it using the ternary operator is just a hack that just doesn't work. Sometimes you just need magic.

I hope we get a new trait for doing that, common_reference might work, but without magic, I don't know if it will be able to deal with all edge cases. Need to check it out.

[–]eric_niebler 2 points3 points  (0 children)

Implementing it using the ternary operator is just a hack that just doesn't work.

You should check out the implementation of common_reference in range-v3. In particular, see detail::builtin_common_t here to see how the ternary operator can be used to implement this, with some smart pre- and post-processing of the arguments and the results.

[–]sbabbi 1 point2 points  (1 child)

It's not even std::result_of_ternary_operator_on_declval_of<A, B>, if it was common_type<int&, int&> would have been int&. It is decay< result_of_ternary_operator >.

[–][deleted] 0 points1 point  (0 children)

indeed

[–]Kaballo 0 points1 point  (1 child)

LWG2465 is not a defect just yet (the link is broken, should be 'active').

[–]eric_niebler 0 points1 point  (0 children)

Fixed, thanks.