boost 是否有按特殊类型值编码状态"compact optional"?
Does boost have an "compact optional" where presence is encoded by special value of type?
我正在寻找可选的(sizeof small_optional<T> == sizeof (T)
(的节省空间的实现。 因此,空性是使用T的一些特殊值进行编码的,例如
small_optional<int, -1>
要求我从不将 -1 存储在small_optional因此 -1 可以用作魔术值来确定可选是否为空。
可标记的库就是为了这个目的而创建的:
可标记 1.0.0
boost::optional<T>
的替代方法,它不存储额外的bool
标志,而是使用特殊的指示值对T
内部的"空"状态进行编码。用法
是否要存储可能丢失的
int
?你能节省有价值的-1
吗? 你可以像这样使用它:using namespace ak_toolkit; typedef markable<mark_int<int, -1>> opt_int; opt_int oi; opt_int o2 (2); assert (!oi.has_value()); assert (o2.has_value()); assert (o2.value() == 2); static_assert (sizeof(opt_int) == sizeof(int), "");
是否要存储可能丢失的
std::string
,其中"丢失" !="空"?你能省出一些包含空值的字符串值吗 里面的性格,像std::string("