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

Add RFC-9562 compliant Max UUID (section 5.10)

This commit is contained in:
James E. King III
2025-07-03 16:50:34 -04:00
committed by Jim King
parent 434329f8dc
commit bf16d95746
4 changed files with 72 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
#ifndef BOOST_UUID_MAX_GENERATOR_HPP_INCLUDED
#define BOOST_UUID_MAX_GENERATOR_HPP_INCLUDED
// Copyright 2025 James E. King III
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
// RFC 9562 section 5.10
#include <boost/uuid/uuid.hpp>
namespace boost {
namespace uuids {
// generate a max uuid
struct max_generator
{
using result_type = uuid;
uuid operator()() const noexcept
{
return {{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
}};
}
};
inline uuid max_uuid() noexcept
{
return {{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
}};
}
}} // namespace boost::uuids
#endif // BOOST_UUID_MAX_GENERATOR_HPP_INCLUDED

View File

@@ -36,6 +36,7 @@ boost_test(TYPE run SOURCES test_to_chars_2.cpp)
boost_test(TYPE run SOURCES test_uuid_clock.cpp)
boost_test(TYPE run SOURCES test_max_generator.cpp)
boost_test(TYPE run SOURCES test_nil_generator.cpp)
boost_test(TYPE run SOURCES test_string_generator.cpp)
boost_test(TYPE run SOURCES test_random_generator.cpp LINK_LIBRARIES Boost::random Boost::predef)

View File

@@ -100,6 +100,7 @@ run test_uuid_clock.cpp ;
# test generators
run test_max_generator.cpp ;
run test_nil_generator.cpp ;
run test_string_generator.cpp ;

View File

@@ -0,0 +1,31 @@
// Copyright (C) 2025 James E. King III
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
// libs/uuid/test/test_max_generator.cpp -------------------------------//
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/max_generator.hpp>
#include <boost/uuid/nil_generator.hpp>
#include <boost/detail/lightweight_test.hpp>
int main(int, char*[])
{
using namespace boost::uuids;
uuid uunil = nil_generator()();
uuid uumax = max_generator()();
uuid expected = {{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
}};
BOOST_TEST_EQ(uumax, expected);
BOOST_TEST_LT(uunil, uumax);
uuid u3 = max_uuid();
BOOST_TEST_EQ(u3, expected);
return boost::report_errors();
}