[英]How to interpret this conditional statement with regard to std::errc
I was reading an example of how to use std::from_chars
function here , when I came by the following if statment:我在这里阅读了一个如何使用
std::from_chars
function的示例,当我得到以下 if 语句时:
if(auto [p, ec] = std::from_chars(str.data(), str.data()+str.size(), result);
ec == std::errc())
std::cout << result << "\n" "p -> \"" << p << "\"\n";
Unfortunately I can not understand what ec == std::errc()
means and how is it the condition.不幸的是,我无法理解
ec == std::errc()
是什么意思以及它的情况如何。 Does it mean that if ec
(the possible error) is equal to default value of enum class errc
the the following line should be executed?这是否意味着如果
ec
(可能的错误)等于枚举 class errc
的默认值,则应执行以下行? if so isn't that also an error?如果是这样,那不是一个错误吗?
Can someone please explain it to me?有人可以向我解释一下吗?
This这个
if(auto [p, ec] = std::from_chars(str.data(), str.data()+str.size(), result);
ec == std::errc())
std::cout << result << "\n" "p -> \"" << p << "\"\n";
is similar to类似于
auto [p, ec] = std::from_chars(str.data(), str.data()+str.size(), result);
if( ec == std::errc() )
std::cout << result << "\n" "p -> \"" << p << "\"\n";
Long answer.. based on manual reference the result for std::from_chars
is defined as长答案..基于手动参考
std::from_chars
的结果定义为
struct from_chars_result {
const char* ptr;
std::errc ec;
};
and based on errc manual std::errc()
is a condition for success
OTOH the individual errors can be compared using ec.code()
并且基于 errc手册
std::errc()
是success
的条件 OTOH 可以使用ec.code()
比较各个错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.