2
0
mirror of https://github.com/boostorg/uuid.git synced 2026-01-19 04:42:16 +00:00

Make hash_value constexpr

This commit is contained in:
Peter Dimov
2025-12-25 12:11:08 +02:00
parent bd765b558c
commit 09dd0dd608
5 changed files with 52 additions and 6 deletions

View File

@@ -221,6 +221,8 @@ 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_hash_value_cx.cpp ;
run test_string_generator_cx.cpp ;
run test_string_generator_cx2.cpp ;

View File

@@ -0,0 +1,33 @@
// Copyright 2024, 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>
#include <cstddef>
#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)
#else
# define TEST_EQ(x, y) STATIC_ASSERT((x)==(y)); BOOST_TEST_EQ(x, y)
#endif
using namespace boost::uuids;
int main()
{
BOOST_CXX14_CONSTEXPR uuid u1;
TEST_EQ( hash_value( u1 ), 0 );
BOOST_CXX14_CONSTEXPR uuid u2 = {{ 0x01, 0x02, 0x03, 0x04 }};
TEST_EQ( hash_value( u2 ), static_cast<std::size_t>( 7362128010791177377ull ) );
BOOST_CXX14_CONSTEXPR uuid u3 = {{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10 }};
TEST_EQ( hash_value( u3 ), static_cast<std::size_t>( 18416781058927374793ull ) );
return boost::report_errors();
}