Why is operator!= removed in C++20 for many standard library types?

前端 未结 2 863
轻奢々
轻奢々 2020-12-03 04:20

According to cppreference, std::type_info::operator!= gets removed with C++20, however, std::type_info::operator== apparently remains.

What

2条回答
  •  不知归路
    2020-12-03 04:53

    We don't need a library provided operator!= anymore. Providing operator== allows the compiler to do some juggling and evaluate a != b in terms of a == b, all on its own.

    [over.match.oper]

    3 For a unary operator @ with an operand of a type whose cv-unqualified version is T1, and for a binary operator @ with a left operand of a type whose cv-unqualified version is T1 and a right operand of a type whose cv-unqualified version is T2, four sets of candidate functions, designated member candidates, non-member candidates, built-in candidates, and rewritten candidates, are constructed as follows:

    3.4.3 For the != operator ([expr.eq]), the rewritten candidates include all non-rewritten candidates for the expression x == y.

    std::type_info and many more library types had their operator!= removed as part of P1614 - The Mothership has Landed.

提交回复
热议问题