Request Short Link
C++ 98
C++ 11
C++ 14
C++ 17
C++ 20
C++ 23
C++ 2c
for-loops as while-loops
array subscription
Show all implicit casts
Show all template parameters of a CallExpr
Use libc++
Transform std::initializer_list
Show noexcept internals
Show padding information
Show coroutine transformation
Show C++ to C transformation
Show object lifetime
Default
15
18
20
22
26
More
GitHub
Patreon
Issues
About
Policies
Examples
C++ Insights @ YouTube
Settings
Version
None
×
Made by
Andreas Fertig
Powered by
Flask
and
CodeMirror
Source:
#include <string> #if __has_include(<compare>) #include <compare> #else namespace std { class weak_ordering { public: // valid values static const weak_ordering less; static const weak_ordering equivalent; static const weak_ordering greater; }; } // namespace std #endif std::weak_ordering ci_compare(const char*, const char*) { return std::weak_ordering::equivalent; } class CIString { std::string s; public: auto operator<=>(const CIString& b) const // 1/ spaceship implementation { return ci_compare(s.c_str(), b.s.c_str()); } auto operator<=>(const char* b) const { return ci_compare(s.c_str(), b); } bool operator==(const CIString& b) const = default; // 2/ opt-in for == and != bool operator==(const char* b) const { return *this <=> b == 0; } }; int main() { CIString a{}, b{}; const char* ac = nullptr; if(a == b) {} if(a != b) {} if(a > b) {} if(a < b) {} if(a >= b) {} if(a <= b) {} if(a == ac) {} if(a != ac) {} if(ac == a) {} if(ac != a) {} }
Insight:
Console: