from_chars_result.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2023 Matt Borland
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // https://www.boost.org/LICENSE_1_0.txt
  4. #ifndef BOOST_CHARCONV_DETAIL_FROM_CHARS_RESULT_HPP
  5. #define BOOST_CHARCONV_DETAIL_FROM_CHARS_RESULT_HPP
  6. #include <system_error>
  7. namespace boost { namespace charconv {
  8. // 22.13.3, Primitive numerical input conversion
  9. template <typename UC>
  10. struct from_chars_result_t
  11. {
  12. const UC* ptr;
  13. // Values:
  14. // 0 = no error
  15. // EINVAL = invalid_argument
  16. // ERANGE = result_out_of_range
  17. std::errc ec;
  18. friend constexpr bool operator==(const from_chars_result_t<UC>& lhs, const from_chars_result_t<UC>& rhs) noexcept
  19. {
  20. return lhs.ptr == rhs.ptr && lhs.ec == rhs.ec;
  21. }
  22. friend constexpr bool operator!=(const from_chars_result_t<UC>& lhs, const from_chars_result_t<UC>& rhs) noexcept
  23. {
  24. return !(lhs == rhs); // NOLINT : Expression can not be simplified since this is the definition
  25. }
  26. constexpr explicit operator bool() const noexcept { return ec == std::errc{}; }
  27. };
  28. using from_chars_result = from_chars_result_t<char>;
  29. }} // Namespaces
  30. #endif // BOOST_CHARCONV_DETAIL_FROM_CHARS_RESULT_HPP