mirror of
https://github.com/boostorg/uuid.git
synced 2026-01-19 04:42:16 +00:00
Make string_generator support string-like types like uuid_from_string does
This commit is contained in:
@@ -183,16 +183,24 @@ public:
|
||||
return r;
|
||||
}
|
||||
|
||||
template<class Ch, class Traits, class Alloc>
|
||||
BOOST_CXX14_CONSTEXPR uuid operator()( std::basic_string<Ch, Traits, Alloc> const& s ) const
|
||||
template<class Str, class Ch = typename Str::value_type, class Tr = typename Str::traits_type>
|
||||
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<class Ch>
|
||||
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 );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -5,13 +5,25 @@
|
||||
#include <boost/uuid/string_generator.hpp>
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
#include <boost/core/detail/string_view.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <string>
|
||||
|
||||
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
|
||||
# include <string_view>
|
||||
#endif
|
||||
|
||||
using namespace boost::uuids;
|
||||
|
||||
template<class Ch> void test( uuid const& expected, Ch const* str )
|
||||
{
|
||||
BOOST_TEST_EQ( string_generator()( str ), expected );
|
||||
BOOST_TEST_EQ( string_generator()( std::basic_string<Ch>( str ) ), expected );
|
||||
BOOST_TEST_EQ( string_generator()( boost::core::basic_string_view<Ch>( str ) ), expected );
|
||||
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
|
||||
BOOST_TEST_EQ( string_generator()( std::basic_string_view<Ch>( str ) ), expected );
|
||||
#endif
|
||||
}
|
||||
|
||||
int main()
|
||||
|
||||
Reference in New Issue
Block a user