std::stoi alternatives for boolean

Viewed 418

Are there a std::stoi for bool type in C++? I can only find this conversion for double, float, int and long

the input is coming from a std::to_string(some_bool_value)

1 Answers

No there isn't. I guess it's down to somebody to convince the C++ standards committee of its necessity.

It could be consistent with the built-in

bool b;
std::istringstream("true") >> std::boolalpha >> b;

so the possible string contents (probably the most contentious point) could be limited to that.

Related