是否有任何 std::empty
结构或类似的结构,或者我需要自己定义:
struct empty{};
这可以很好地与 std::conditional
或其他新的 std 功能结合使用,我想知道标准是否定义了它。
最佳答案
有一个部分可以将这种结构添加为 Variant proposal (n4542) 的一部分。 .
经过投票,
What do we want to call the “empty_t” stand-in type?
empty_t 4
empty 4
one_t 1
blank 6
blank_t 7
monostate 7Runoff:
blank* 3
monostate 8
商定的名称是:std::monostate。
定义如下:
// 2.?, Explicitly default-constructed alternative
struct monostate {};
bool operator<(const monostate&, const monostate&) constexpr
{ return false; }
bool operator>(const monostate&, const monostate&) constexpr
{ return false; }
bool operator<=(const monostate&, const monostate&) constexpr
{ return true; }
bool operator>=(const monostate&, const monostate&) constexpr
{ return true; }
bool operator==(const monostate&, const monostate&) constexpr
{ return true; }
bool operator!=(const monostate&, const monostate&) constexpr
{ return false; }
关于c++ - 空结构是由 C++ 标准定义的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16666871/