From 5496dd3bbea8b1cda8ab7bb72b56b5826d59849b Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 8 Sep 2025 21:49:23 +0300 Subject: [PATCH] Add boost/uuid/constants.hpp --- include/boost/uuid.hpp | 1 + include/boost/uuid/constants.hpp | 11 +++++++++++ include/boost/uuid/detail/nil_uuid.hpp | 20 ++++++++++++++++++++ include/boost/uuid/nil_generator.hpp | 6 +----- test/CMakeLists.txt | 2 ++ test/Jamfile.v2 | 4 ++++ test/test_constants.cpp | 23 +++++++++++++++++++++++ 7 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 include/boost/uuid/constants.hpp create mode 100644 include/boost/uuid/detail/nil_uuid.hpp create mode 100644 test/test_constants.cpp diff --git a/include/boost/uuid.hpp b/include/boost/uuid.hpp index 623336b..02dfa8c 100644 --- a/include/boost/uuid.hpp +++ b/include/boost/uuid.hpp @@ -8,5 +8,6 @@ #include #include #include +#include #endif // #ifndef BOOST_UUID_HPP_INCLUDED diff --git a/include/boost/uuid/constants.hpp b/include/boost/uuid/constants.hpp new file mode 100644 index 0000000..98ef6d0 --- /dev/null +++ b/include/boost/uuid/constants.hpp @@ -0,0 +1,11 @@ +#ifndef BOOST_UUID_CONSTANTS_HPP_INCLUDED +#define BOOST_UUID_CONSTANTS_HPP_INCLUDED + +// Copyright 2025 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +#endif // BOOST_UUID_CONSTANTS_HPP_INCLUDED diff --git a/include/boost/uuid/detail/nil_uuid.hpp b/include/boost/uuid/detail/nil_uuid.hpp new file mode 100644 index 0000000..2371823 --- /dev/null +++ b/include/boost/uuid/detail/nil_uuid.hpp @@ -0,0 +1,20 @@ +#ifndef BOOST_UUID_DETAIL_NIL_UUID_INCLUDED +#define BOOST_UUID_DETAIL_NIL_UUID_INCLUDED + +// Copyright 2025 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include + +namespace boost { +namespace uuids { + +inline uuid nil_uuid() noexcept +{ + return {{}}; +} + +}} // namespace boost::uuids + +#endif // #ifndef BOOST_UUID_DETAIL_NIL_UUID_INCLUDED diff --git a/include/boost/uuid/nil_generator.hpp b/include/boost/uuid/nil_generator.hpp index 5b3ace7..7323339 100644 --- a/include/boost/uuid/nil_generator.hpp +++ b/include/boost/uuid/nil_generator.hpp @@ -6,6 +6,7 @@ // https://www.boost.org/LICENSE_1_0.txt #include +#include namespace boost { namespace uuids { @@ -21,11 +22,6 @@ struct nil_generator } }; -inline uuid nil_uuid() noexcept -{ - return {{}}; -} - }} // namespace boost::uuids #endif // BOOST_UUID_NIL_GENERATOR_HPP_INCLUDED diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 74c4e35..996f73b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -81,6 +81,8 @@ boost_test(TYPE run SOURCES test_detail_random_provider.cpp LINK_LIBRARIES Boost boost_test(TYPE run SOURCES test_serialization.cpp LINK_LIBRARIES Boost::serialization) +boost_test(TYPE run SOURCES test_constants.cpp) + boost_test(TYPE compile SOURCES test_uuid_cx.cpp) boost_test(TYPE run SOURCES test_string_generator_cx.cpp) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 5e5c6cf..dcad707 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -203,6 +203,10 @@ run test_entropy_error.cpp ; run test_detail_random_provider.cpp : : : /boost/array//boost_array ; +# constants + +run test_constants.cpp ; + # constexpr tests compile test_uuid_cx.cpp ; diff --git a/test/test_constants.cpp b/test/test_constants.cpp new file mode 100644 index 0000000..946e410 --- /dev/null +++ b/test/test_constants.cpp @@ -0,0 +1,23 @@ +// Copyright 2025 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include +#include + +using namespace boost::uuids; + +int main() +{ + BOOST_TEST_EQ( ns::dns(), string_generator()("6ba7b810-9dad-11d1-80b4-00c04fd430c8")); + BOOST_TEST_EQ( ns::url(), string_generator()("6ba7b811-9dad-11d1-80b4-00c04fd430c8")); + BOOST_TEST_EQ( ns::oid(), string_generator()("6ba7b812-9dad-11d1-80b4-00c04fd430c8")); + BOOST_TEST_EQ( ns::x500dn(), string_generator()("6ba7b814-9dad-11d1-80b4-00c04fd430c8")); + + BOOST_TEST_EQ( nil_uuid(), string_generator()("00000000-0000-0000-0000-000000000000")); + + return boost::report_errors(); +}