Is there some special null type and value in standard C++ library, e.g. defined as struct null_type_t {};?
I want to use it in different places to signify that there is no value passed.
E.g. to use in next template:
template <typename T = std::null_type_t>
struct S {};
Or in structure like next:
template <typename T>
struct Optional {
constexpr Optional() = delete;
constexpr Optional(std::null_type_t) {}
template <typename OT>
constexpr Optional(OT const & val)
: has_value(true), value(val) {}
bool const has_value = false;
T const value = T();
};
Basically if std::null_type_t type or value is passed as template or function parameter then my code will do some special handling, i.e. this null type signifies that there is no value.
Of cause I can define in my code my own struct like next:
struct NullType {};
But I did this kind of definition in code many times already. And maybe there exists special standard library type for this kind of thing, which I can use everywhere instead of my definition of null struct.
There is nullptr_t type and nullptr value, that I can use in some places. But not all, because if function or template parameter is a pointer type then sometimes I want to pass null pointer to signify real value of null pointer, not the absence of value. That's why for such pointer-typed cases would be good to have some separate type like struct null_type_t {}; which doesn't interfere with pointer or any other class or built-in type.