1. 11
    1. 5

      The point is templates, right? because the void type is pretty badly behaved, so you’d need to special case it.

      (finished reading the article) Yeah that’s basically it.

      1. 2

        Yet another “billion dollar mistake?”

        1. 2

          Is there a reason it couldn’t be named std::nothing?

          1. 13

            Or better, std::unit.

            1. 7

              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.

              Naming things is hard.

              1. 3

                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 :(

            2. 4

              Is there a reason it couldn’t be named std::nothing?

              I think that “monostate” is not “nothing”; it is something, but it’s empty.