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

Change the type of pos to std::ptrdiff_t to avoid casts

This commit is contained in:
Peter Dimov
2026-01-08 22:57:00 +02:00
parent 517bfe6972
commit 095a47fe04
3 changed files with 7 additions and 7 deletions

View File

@@ -10,6 +10,7 @@
#include <boost/config.hpp>
#include <stdexcept>
#include <cstdio>
#include <cstddef>
namespace boost {
namespace uuids {
@@ -29,10 +30,10 @@ BOOST_CXX14_CONSTEXPR inline char const* fc_error_to_string( from_chars_error er
}
}
BOOST_NORETURN inline void throw_invalid_uuid( int pos, from_chars_error err )
BOOST_NORETURN inline void throw_invalid_uuid( std::ptrdiff_t pos, from_chars_error err )
{
char buffer[ 128 ];
std::snprintf( buffer, sizeof( buffer ), "Invalid UUID string at position %d: %s", pos, fc_error_to_string( err ) );
std::snprintf( buffer, sizeof( buffer ), "Invalid UUID string at position %td: %s", pos, fc_error_to_string( err ) );
BOOST_THROW_EXCEPTION( std::runtime_error( buffer ) );
}

View File

@@ -10,7 +10,6 @@
#include <boost/uuid/detail/throw_invalid_uuid.hpp>
#include <boost/uuid/detail/cstring.hpp>
#include <boost/config.hpp>
#include <string>
namespace boost {
namespace uuids {
@@ -27,12 +26,12 @@ uuid uuid_from_string( Ch const* first, Ch const* last )
if( r.ec != from_chars_error::none )
{
detail::throw_invalid_uuid( static_cast<int>( r.ptr - first ), r.ec );
detail::throw_invalid_uuid( r.ptr - first, r.ec );
}
if( r.ptr != last )
{
detail::throw_invalid_uuid( static_cast<int>( r.ptr - first ), from_chars_error::unexpected_extra_input );
detail::throw_invalid_uuid( r.ptr - first, from_chars_error::unexpected_extra_input );
}
return u;

View File

@@ -33,7 +33,7 @@ public:
using result_type = uuid;
template<class CharIterator>
BOOST_CXX14_CONSTEXPR uuid operator()( CharIterator first, CharIterator last, int& pos, from_chars_error& err ) const noexcept
BOOST_CXX14_CONSTEXPR uuid operator()( CharIterator first, CharIterator last, std::ptrdiff_t& pos, from_chars_error& err ) const noexcept
{
uuid u;
@@ -170,7 +170,7 @@ public:
template<class CharIterator>
BOOST_CXX14_CONSTEXPR uuid operator()( CharIterator first, CharIterator last ) const
{
int pos = 0;
std::ptrdiff_t pos = 0;
from_chars_error err = {};
uuid r = operator()( first, last, pos, err );