cppweeklynews
cppweeklynews copied to clipboard
群友讨论
各种exit https://learn.microsoft.com/en-us/previous-versions/6wdz5232(v=vs.140) https://stackoverflow.com/questions/9758495/what-is-the-difference-between-stdquick-exit-and-stdabort-and-why-was-stdq
工厂模式的几种做法
- static map
- 可以利用类来封装,利用宏生成多个static变量构造,来注册到map
- singleton模版注册也可以,利用模版实例化来调用注册到map 这两种都适合分散写法
- 直接注册也可以,比如
static std::unordered_map<std::string, OptionTypeInfo>
lru_cache_options_type_info = {
{"capacity",
{offsetof(struct LRUCacheOptions, capacity), OptionType::kSizeT,
OptionVerificationType::kNormal, OptionTypeFlags::kMutable}},
{"num_shard_bits",
{offsetof(struct LRUCacheOptions, num_shard_bits), OptionType::kInt,
OptionVerificationType::kNormal, OptionTypeFlags::kMutable}},
{"strict_capacity_limit",
{offsetof(struct LRUCacheOptions, strict_capacity_limit),
OptionType::kBoolean, OptionVerificationType::kNormal,
OptionTypeFlags::kMutable}},
{"high_pri_pool_ratio",
{offsetof(struct LRUCacheOptions, high_pri_pool_ratio),
OptionType::kDouble, OptionVerificationType::kNormal,
OptionTypeFlags::kMutable}},
{"low_pri_pool_ratio",
{offsetof(struct LRUCacheOptions, low_pri_pool_ratio),
OptionType::kDouble, OptionVerificationType::kNormal,
OptionTypeFlags::kMutable}},
};
直接注册也未尝不可,直观,适合聚集写法
依赖dlopen也可以,不过属于杀鸡牛刀
main函数返回相当于调用exit。最佳时间就是不要主动调用exit
如何判断一个数字是不是浮点数0?判断0正负 https://godbolt.org/z/jcqc38qqW