uuid_uint128.ipp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef BOOST_UUID_DETAIL_UUID_UINT128_IPP_INCLUDED
  2. #define BOOST_UUID_DETAIL_UUID_UINT128_IPP_INCLUDED
  3. // Copyright 2024 Peter Dimov
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. #include <boost/uuid/detail/endian.hpp>
  7. #if defined(BOOST_UUID_REPORT_IMPLEMENTATION)
  8. #include <boost/config/pragma_message.hpp>
  9. BOOST_PRAGMA_MESSAGE( "Using uuid_uint128.ipp" )
  10. #endif
  11. namespace boost {
  12. namespace uuids {
  13. inline bool uuid::is_nil() const noexcept
  14. {
  15. __uint128_t v = detail::load_native_u128( this->data );
  16. return v == 0;
  17. }
  18. inline void uuid::swap( uuid& rhs ) noexcept
  19. {
  20. __uint128_t v1 = detail::load_native_u128( this->data );
  21. __uint128_t v2 = detail::load_native_u128( rhs.data );
  22. detail::store_native_u128( this->data, v2 );
  23. detail::store_native_u128( rhs.data, v1 );
  24. }
  25. inline bool operator==( uuid const& lhs, uuid const& rhs ) noexcept
  26. {
  27. __uint128_t v1 = detail::load_native_u128( lhs.data );
  28. __uint128_t v2 = detail::load_native_u128( rhs.data );
  29. return v1 == v2;
  30. }
  31. inline bool operator<( uuid const& lhs, uuid const& rhs ) noexcept
  32. {
  33. __uint128_t v1 = detail::load_big_u128( lhs.data );
  34. __uint128_t v2 = detail::load_big_u128( rhs.data );
  35. return v1 < v2;
  36. }
  37. #if defined(BOOST_UUID_HAS_THREE_WAY_COMPARISON)
  38. inline std::strong_ordering operator<=> (uuid const& lhs, uuid const& rhs) noexcept
  39. {
  40. __uint128_t v1 = detail::load_big_u128( lhs.data );
  41. __uint128_t v2 = detail::load_big_u128( rhs.data );
  42. return v1 <=> v2;
  43. }
  44. #endif
  45. } // namespace uuids
  46. } // namespace boost
  47. #endif // BOOST_UUID_DETAIL_UUID_UINT128_IPP_INCLUDED