Why is inequality tested as (!(a==b)) in a lot of C++ standard library code?

前端 未结 6 1801
忘了有多久
忘了有多久 2021-02-01 11:24

This is the code from the C++ standard library remove code. Why is inequality tested as if (!(*first == val)) instead of if (*first != val)

6条回答
  •  无人共我
    2021-02-01 11:57

    The EqualityComparable concept only requires that operator== be defined.

    Consequently, any function that professes to work with types satisfying EqualityComparable cannot rely on the existence of operator!= for objects of that type. (unless there are additional requirements that imply the existence of operator!=).

提交回复
热议问题