Questions tagged [default-comparisons]

For questions related to C++20's compiler-generated comparisons, either implicitly generated from hand-written operator<=>, or explicitly requested with = default.

4 questions
4
votes
3 answers

c++20 default comparison operator and empty base class

c++20 default comparison operator is a very convenient feature. But I find it less useful if the class has an empty base class. The default operator<=> performs lexicographical comparison by successively comparing the base (left-to-right…
wanghan02
  • 1,227
  • 7
  • 14
3
votes
0 answers

Three-Way comparison operator(<=>) not defined for std::string

I am attempting to make use of c++20's new Three-Way operator(<=>) capabilities in my programs, but it appears that this operator is not defined for strings, as this program #include #include using namespace std; int main() { …
3
votes
1 answer

Why C++20 allows defaulted comparison to compile even when it is deleted?

Consider the following code: struct A { }; struct B { A a; bool operator == (const B& other) const = default; }; clang gives a nice warning : warning: explicitly defaulted equality comparison operator is implicitly deleted…
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277
2
votes
1 answer

Equivalent of std::less for default comparsons operator (<=>)

Does c++20 defines something similar to std::less for default comparsons operator (<=>). I would like define some datasructure with customizable comparator as map or unordered_map do. template , struct…
Dewfy
  • 23,277
  • 13
  • 73
  • 121