Kill some signed v unsigned warnings in the string_ref tests.

[SVN r81970]
This commit is contained in:
Marshall Clow
2012-12-15 16:14:21 +00:00
parent 20c9bad06d
commit 922afd98c4
2 changed files with 49 additions and 47 deletions

View File

@ -22,9 +22,6 @@
#include <algorithm>
#include <functional>
#include <string>
#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
#include <initializer_list>
#endif
namespace boost {

View File

@ -82,6 +82,11 @@ void reverse ( const char *arg ) {
BOOST_CHECK ( std::equal ( sr1.begin (), sr1.end (), string2.begin ()));
}
// This helper function eliminates signed vs. unsigned warnings
string_ref::size_type ptr_diff ( const char *res, const char *base ) {
BOOST_CHECK ( res >= base );
return static_cast<string_ref::size_type> ( res - base );
}
void find ( const char *arg ) {
string_ref sr1;
@ -93,7 +98,7 @@ void find ( const char *arg ) {
sr1 = arg;
while ( *p ) {
string_ref::size_type pos = sr1.find(*p);
BOOST_CHECK ( pos != string_ref::npos && ( pos <= p - arg ));
BOOST_CHECK ( pos != string_ref::npos && ( pos <= ptr_diff ( p, arg )));
++p;
}
@ -102,7 +107,7 @@ void find ( const char *arg ) {
sr1 = arg;
while ( *p ) {
string_ref::size_type pos = sr1.rfind(*p);
BOOST_CHECK ( pos != string_ref::npos && pos < sr1.size () && ( pos >= p - arg ));
BOOST_CHECK ( pos != string_ref::npos && pos < sr1.size () && ( pos >= ptr_diff ( p, arg )));
++p;
}
@ -115,7 +120,7 @@ void find ( const char *arg ) {
const char *strp = std::strchr ( arg, ch );
BOOST_CHECK (( strp == NULL ) == ( pos == string_ref::npos ));
if ( strp != NULL )
BOOST_CHECK (( strp - arg ) == pos );
BOOST_CHECK ( ptr_diff ( strp, arg ) == pos );
}
sr1 = arg;
@ -127,7 +132,7 @@ void find ( const char *arg ) {
const char *strp = std::strrchr ( arg, ch );
BOOST_CHECK (( strp == NULL ) == ( pos == string_ref::npos ));
if ( strp != NULL )
BOOST_CHECK (( strp - arg ) == pos );
BOOST_CHECK ( ptr_diff ( strp, arg ) == pos );
}
@ -186,7 +191,7 @@ void find ( const char *arg ) {
while ( *p ) {
string_ref::size_type pos1 = sr1.find_first_of(*p);
string_ref::size_type pos2 = sr1.find_first_not_of(*p);
BOOST_CHECK ( pos1 != string_ref::npos && pos1 < sr1.size () && pos1 <= ( p - arg ));
BOOST_CHECK ( pos1 != string_ref::npos && pos1 < sr1.size () && pos1 <= ptr_diff ( p, arg ));
if ( pos2 != string_ref::npos ) {
for ( size_t i = 0 ; i < pos2; ++i )
BOOST_CHECK ( sr1[i] == *p );
@ -211,7 +216,7 @@ void find ( const char *arg ) {
while ( *p ) {
string_ref::size_type pos1 = sr1.find_last_of(*p);
string_ref::size_type pos2 = sr1.find_last_not_of(*p);
BOOST_CHECK ( pos1 != string_ref::npos && pos1 < sr1.size () && pos1 >= ( p - arg ));
BOOST_CHECK ( pos1 != string_ref::npos && pos1 < sr1.size () && pos1 >= ptr_diff ( p, arg ));
BOOST_CHECK ( pos2 == string_ref::npos || pos1 < sr1.size ());
if ( pos2 != string_ref::npos ) {
for ( size_t i = sr1.size () -1 ; i > pos2; --i )