mirror of
https://github.com/boostorg/uuid.git
synced 2026-01-19 04:42:16 +00:00
Make uuid::is_nil, swap, and relational operators constexpr
This commit is contained in:
@@ -57,9 +57,9 @@ rule test_headers
|
||||
|
||||
alias test_headers : [ test_headers ] ;
|
||||
|
||||
# test including all .hpp files in 2 translations units
|
||||
# test including all .hpp files in 2 translation units
|
||||
# to look for issues when using multiple translation units
|
||||
# e.g. missing inline on a global functionstate is not missing
|
||||
# e.g. missing inline on a global function
|
||||
|
||||
run test_include1.cpp test_include2.cpp ;
|
||||
|
||||
@@ -217,6 +217,9 @@ run test_constants.cpp ;
|
||||
|
||||
compile test_uuid_cx.cpp ;
|
||||
run test_uuid_cx2.cpp ;
|
||||
run test_uuid_cx3.cpp
|
||||
: : : <define>BOOST_UUID_REPORT_IMPLEMENTATION ;
|
||||
run test_uuid_cx3.cpp : : : <define>BOOST_UUID_NO_SIMD <define>BOOST_UUID_REPORT_IMPLEMENTATION : test_uuid_cx3_no_simd ;
|
||||
|
||||
run test_string_generator_cx.cpp ;
|
||||
run test_string_generator_cx2.cpp ;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2024 Peter Dimov
|
||||
// Copyright 2024, 2025 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
|
||||
65
test/test_uuid_cx3.cpp
Normal file
65
test/test_uuid_cx3.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
// Copyright 2025 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
# define TEST_EQ(x, y) BOOST_TEST_EQ(x, y)
|
||||
# define TEST_NE(x, y) BOOST_TEST_NE(x, y)
|
||||
# define TEST_LT(x, y) BOOST_TEST_LT(x, y)
|
||||
# define TEST(x) BOOST_TEST(x)
|
||||
#else
|
||||
# define TEST_EQ(x, y) STATIC_ASSERT((x)==(y)); BOOST_TEST_EQ(x, y)
|
||||
# define TEST_NE(x, y) STATIC_ASSERT((x)!=(y)); BOOST_TEST_NE(x, y)
|
||||
# define TEST_LT(x, y) STATIC_ASSERT((x)<(y)); BOOST_TEST_LT(x, y)
|
||||
# define TEST(x) STATIC_ASSERT(x); BOOST_TEST(x)
|
||||
#endif
|
||||
|
||||
using namespace boost::uuids;
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_CXX14_CONSTEXPR uuid u1;
|
||||
BOOST_CXX14_CONSTEXPR uuid u2 = {{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }};
|
||||
BOOST_CXX14_CONSTEXPR uuid u3 = {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }};
|
||||
|
||||
TEST_EQ( u1.is_nil(), true );
|
||||
TEST_EQ( u2.is_nil(), false );
|
||||
TEST_EQ( u3.is_nil(), false );
|
||||
|
||||
TEST_EQ( u1, u1 );
|
||||
TEST_EQ( u2, u2 );
|
||||
TEST_EQ( u3, u3 );
|
||||
|
||||
TEST_NE( u1, u2 );
|
||||
TEST_NE( u1, u3 );
|
||||
TEST_NE( u2, u3 );
|
||||
|
||||
TEST_LT( u1, u2 );
|
||||
TEST_LT( u1, u3 );
|
||||
TEST_LT( u3, u2 );
|
||||
|
||||
#if defined(BOOST_UUID_HAS_THREE_WAY_COMPARISON)
|
||||
|
||||
constexpr auto eq = std::strong_ordering::equal;
|
||||
constexpr auto lt = std::strong_ordering::less;
|
||||
constexpr auto gt = std::strong_ordering::greater;
|
||||
|
||||
TEST( ( u1 <=> u1 ) == eq );
|
||||
TEST( ( u2 <=> u2 ) == eq );
|
||||
TEST( ( u3 <=> u3 ) == eq );
|
||||
|
||||
TEST( ( u1 <=> u2 ) == lt );
|
||||
TEST( ( u1 <=> u3 ) == lt );
|
||||
TEST( ( u2 <=> u3 ) == gt );
|
||||
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in New Issue
Block a user