gpt4 book ai didi

c++ - 空结构是由 C++ 标准定义的吗?

转载 作者:IT老高 更新时间:2023-10-28 21:52:55 25 4
gpt4 key购买 nike

是否有任何 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 7

Runoff:
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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com