std::unit would be a bad name because it sounds like it’s part of the quantities and units library (which is one of my favourite proposed features for C++29).
std::nothing would be a bad name because you expect sizeof(std::nothing) to be zero. You can’t currently express a size-zero type in C++, but you can express a size-zero field using the no-unique-address attribute. There is a desire for a nothing for use with std::conditional_t so that you can have things like:
template<typename T = void>
class ClassWithSomeOptionalBit
{
// This takes no space and introduces no behaviour if T is void.
std::conditional_t<std::is_same_v<T, void>, std::nothing, T> optionalField;
...
};
std::monostate is a bad name because no one understands what it means, but it’s better than the alternatives where people think they know what it means but are wrong.
There was at one point a std::none factory function proposal that would have superseded all the issues we have with these various names. IIRC it was discarded/abandoned (last touched in 2018) in favor of a regular void proposal, which would let us treat void as an object, but I’m unsure what the current state of that is :(
The point is templates, right? because the
voidtype is pretty badly behaved, so you’d need to special case it.(finished reading the article) Yeah that’s basically it.
Yet another “billion dollar mistake?”
Is there a reason it couldn’t be named
std::nothing?Or better,
std::unit.std::unitwould be a bad name because it sounds like it’s part of the quantities and units library (which is one of my favourite proposed features for C++29).std::nothingwould be a bad name because you expectsizeof(std::nothing)to be zero. You can’t currently express a size-zero type in C++, but you can express a size-zero field using the no-unique-address attribute. There is a desire for a nothing for use withstd::conditional_tso that you can have things like:std::monostateis a bad name because no one understands what it means, but it’s better than the alternatives where people think they know what it means but are wrong.Naming things is hard.
There was at one point a
std::nonefactory function proposal that would have superseded all the issues we have with these various names. IIRC it was discarded/abandoned (last touched in 2018) in favor of a regularvoidproposal, which would let us treatvoidas an object, but I’m unsure what the current state of that is :(I think that “monostate” is not “nothing”; it is something, but it’s empty.