C++20 Concepts: The Definitive Guide
I feel like one of the things a &quot;Definitive Guide&quot; to this feature needs to make clear, and maybe even emphasise, is a key way these are different than say Rust type Traits.<p>Concepts, just like the SFINAE and constrexpr hacks you should discard in their favour, are about only what will <i>compile</i> and you, the C++ programmer, are always responsible for shouldering the burden of deciding whether that will do what you meant <i>even if you have no insight into the types involved</i>.<p>Example: In C++ the floating point type &quot;float&quot; matches a concept std::totally_ordered. You can, in fact, compile code that treats any container of floats as totally ordered. <i>But</i> of course if some of them are NaN that won&#x27;t work, because NaNs in fact don&#x27;t even compare equal to themselves. You, the C++ programmer were responsible for knowing not to use this with NaNs.<p>Whereas, Rust&#x27;s floating point type f32 implements PartialOrd (saying you can try to compare these) but not Ord (a claim that <i>all</i> of them are totally ordered). If you know you won&#x27;t use NaNs you can construct a wrapper type, and insist that is Ord and Rust will let you do that, because now <i>you</i> pointed the gun at your foot, and it&#x27;s clearly your fault if you pull the trigger.<p>This is a quite deliberate choice, it&#x27;s not as though C++ could have just dropped in Rust-style traits, but I think a &quot;Definitive Guide&quot; ought to spell this out so that programmers understand that the burden the concept seems to be taking on is in fact still resting firmly on their shoulders in C++.<p>The other side of this is, if you wrote a C++ type say Beachball that implements the necessary comparison operators the Beachball is std::totally_ordered in C++ 20 with no further work from you to clear up this fact. Your users might hope you&#x27;ll document whether Beachballs <i>are</i> actually totally ordered or not though...<p>I think this will likely prove to be a curse, obviously its proponents think it will work out OK or even a blessing.