From 8febad40ed065efafb1f742faf6eab5c0cf7d7e0 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 9 Jan 2026 21:44:26 +0200 Subject: [PATCH] Make string_generator support string-like types like uuid_from_string does --- include/boost/uuid/string_generator.hpp | 18 +++++++++++++----- test/test_string_generator_2.cpp | 12 ++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/include/boost/uuid/string_generator.hpp b/include/boost/uuid/string_generator.hpp index 314286e..f7a3cc7 100644 --- a/include/boost/uuid/string_generator.hpp +++ b/include/boost/uuid/string_generator.hpp @@ -183,16 +183,24 @@ public: return r; } - template - BOOST_CXX14_CONSTEXPR uuid operator()( std::basic_string const& s ) const + template + BOOST_CXX14_CONSTEXPR + uuid operator()( Str const& str ) const { - return operator()( s.begin(), s.end() ); + Ch const* first = str.data(); + Ch const* last = str.data() + str.size(); + + return operator()( first, last ); } template - BOOST_CXX14_CONSTEXPR uuid operator()( Ch const* s ) const + BOOST_CXX14_CONSTEXPR + uuid operator()( Ch const* str ) const { - return operator()( s, s + detail::strlen_cx( s ) ); + Ch const* first = str; + Ch const* last = str + detail::strlen_cx( str ); + + return operator()( first, last ); } }; diff --git a/test/test_string_generator_2.cpp b/test/test_string_generator_2.cpp index 879230a..4de6074 100644 --- a/test/test_string_generator_2.cpp +++ b/test/test_string_generator_2.cpp @@ -5,13 +5,25 @@ #include #include #include +#include #include +#include +#include + +#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) +# include +#endif using namespace boost::uuids; template void test( uuid const& expected, Ch const* str ) { BOOST_TEST_EQ( string_generator()( str ), expected ); + BOOST_TEST_EQ( string_generator()( std::basic_string( str ) ), expected ); + BOOST_TEST_EQ( string_generator()( boost::core::basic_string_view( str ) ), expected ); +#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) + BOOST_TEST_EQ( string_generator()( std::basic_string_view( str ) ), expected ); +#endif } int main()