4 ms·
Why is std::unreachable a function, and why does it require including a header? It sounds like the functionality of unreachable is to inform the compiler of so
by Aardwolf 4y ago
Why is std::unreachable a function, and why does it require including a header?
It sounds like the functionality of unreachable is to inform the compiler of something, which is what a core language keyword, like "if" or "for", does. Of course then there could be name collisions with the new keyword, so being in std:: might be a solution for that. But that is inconsistent, sometimes they solve this with prepending/appending __ or _t instead, or using obscure enough names like "constexpr" or "nullptr" that probably don't clash
- gpderetta 4y agoWhy shouldn't it be a function? The global namespace is a scarce resource. constexpr can't be a function because it is not used a such. Nullptr could have been std::nullptr, but it is used often enough that it made sense to put it in the global namespace (but note that it had to be nullptr instead of null to avoid collisions, so only two chars saved). The type is still std::nullptr_t. The C++ standard doesn't really use __ as a prefix, it is a namespace reserved for the implementor. The _t suffix in the global namespace is from POSIX originally then adopted by C; C++ still puts _t names under std. std::unreachable is a very obscure functionality, polluting the global namespace for it wouldn't have been a good idea.