diff --git a/doc/uuid/uuid_io.adoc b/doc/uuid/uuid_io.adoc index c3cf97f..8c4bb7b 100644 --- a/doc/uuid/uuid_io.adoc +++ b/doc/uuid/uuid_io.adoc @@ -55,6 +55,8 @@ template struct from_chars_result { Ch const* ptr; from_chars_error ec; + + constexpr explicit operator bool() const noexcept; }; template @@ -233,6 +235,17 @@ std::string s1 = to_string( u ); std::wstring s2 = to_wstring( u ); ``` +=== from_chars_result + +The `from_chars_result` structure contains the result of a `from_chars` call, where the `ptr` member points to the first character that was +not consumed during parsing and `ec` is `from_chars_error::none`, if parsing succeeded, otherwise the error code returned by the parser. + +``` +constexpr explicit operator bool() const noexcept; +``` + +Returns: :: `this->ec == from_chars_error::none`. + === from_chars ``` diff --git a/include/boost/uuid/detail/from_chars.hpp b/include/boost/uuid/detail/from_chars.hpp index d8d2f53..e3b039c 100644 --- a/include/boost/uuid/detail/from_chars.hpp +++ b/include/boost/uuid/detail/from_chars.hpp @@ -103,6 +103,8 @@ template struct from_chars_result { Ch const* ptr; from_chars_error ec; + + constexpr explicit operator bool() const noexcept { return ec == from_chars_error::none; } }; template diff --git a/test/test_from_chars.cpp b/test/test_from_chars.cpp index b7b2812..5b333a9 100644 --- a/test/test_from_chars.cpp +++ b/test/test_from_chars.cpp @@ -22,6 +22,8 @@ template void test( uuid const& expected, Ch const* str ) BOOST_TEST( r.ec == from_chars_error::none ); BOOST_TEST_EQ( static_cast( r.ec ), 0 ); + BOOST_TEST( static_cast( r ) ); + BOOST_TEST( !!r ); BOOST_TEST_EQ( u, expected ); } diff --git a/test/test_from_chars_2.cpp b/test/test_from_chars_2.cpp index 29a745a..d07d7a4 100644 --- a/test/test_from_chars_2.cpp +++ b/test/test_from_chars_2.cpp @@ -22,6 +22,7 @@ template void test( Ch const* str, int pos, from_chars_error err ) BOOST_TEST( r.ec == err ); BOOST_TEST_EQ( static_cast( r.ec ), static_cast( err ) ); + BOOST_TEST_EQ( static_cast( r ), ( err == from_chars_error::none ) ); } int main()