Skip to content

使用c++新标准 #1

Description

@moegodot

我注意到README个段代码:

取值的同时判断类型
int n;
bool ret = j["boolean"].get_value(&n); // 若取值成功,ret 为 true

c++在新标准中已经对这种情况做出标准做法:使用std::optional.
修改成标准代码:

取值的同时判断类型
int n;
auto ret = j["boolean"].get_value(); // 若取值成功,ret 为 true
//get_value()应该返回std::optional<int>
if(ret.has_value()) n = ret.value();
else { /*do some thing*/}

如果没有什么特殊需求,都应该使用标准库中的方法.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions