I know the technical answer is: because the standard says so.
But I am confused regarding the motivation:
I see nothing "library" in the defaulting the <=>
: it may return some type that is technically defined in std
but it is a "fake library" type in a sense that compiler must know about it since it must be able to default operator <=>
with auto
return type (not to mention that error messages in good compilers specify <compare>
so it is clear that there is a language<=>library link here).
So I understand there is some library functionality that might require me to include <compare>
but I do not understand why defaulting <=>
requires me to include that header since compiler anyway has to know about everything needed to make the <=>
.
Note: I know most of the time some other standard headers will include the <compare>
, this is a question about language/library design, not that much about one extra line that C++ forces me to write without a good reason.
<new>
in order to use placement new syntax. – Seeker<typeinfo>
which is needed to simply usetypeid
. – Maidservant<new>
in order to use the default non-placementoperator new
. So it seems that there's no technical reason to force users to include the header for these built-in operations. – Oshinskinew
is a language keyword, so there is no header for it. Butplacement-new
can be overloaded by users, where<new>
defines the defaultplacement-new
– Ticktack