Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81970 - in trunk: boost/algorithm libs/algorithm/test
From: marshall_at_[hidden]
Date: 2012-12-15 11:14:21


Author: marshall
Date: 2012-12-15 11:14:21 EST (Sat, 15 Dec 2012)
New Revision: 81970
URL: http://svn.boost.org/trac/boost/changeset/81970

Log:
Kill some signed v unsigned warnings in the string_ref tests.
Text files modified:
   trunk/boost/algorithm/string_ref.hpp | 3 -
   trunk/libs/algorithm/test/string_ref_test2.cpp | 93 +++++++++++++++++++++------------------
   2 files changed, 49 insertions(+), 47 deletions(-)

Modified: trunk/boost/algorithm/string_ref.hpp
==============================================================================
--- trunk/boost/algorithm/string_ref.hpp (original)
+++ trunk/boost/algorithm/string_ref.hpp 2012-12-15 11:14:21 EST (Sat, 15 Dec 2012)
@@ -22,9 +22,6 @@
 #include <algorithm>
 #include <functional>
 #include <string>
-#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
-#include <initializer_list>
-#endif
 
 namespace boost {
     

Modified: trunk/libs/algorithm/test/string_ref_test2.cpp
==============================================================================
--- trunk/libs/algorithm/test/string_ref_test2.cpp (original)
+++ trunk/libs/algorithm/test/string_ref_test2.cpp 2012-12-15 11:14:21 EST (Sat, 15 Dec 2012)
@@ -82,6 +82,11 @@
     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;
@@ -92,42 +97,42 @@
   p = arg;
   sr1 = arg;
   while ( *p ) {
- string_ref::size_type pos = sr1.find(*p);
- BOOST_CHECK ( pos != string_ref::npos && ( pos <= p - arg ));
+ string_ref::size_type pos = sr1.find(*p);
+ BOOST_CHECK ( pos != string_ref::npos && ( pos <= ptr_diff ( p, arg )));
     ++p;
     }
   
 // Look for each character in the string (searching from the end)
     p = 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 ));
+ while ( *p ) {
+ string_ref::size_type pos = sr1.rfind(*p);
+ BOOST_CHECK ( pos != string_ref::npos && pos < sr1.size () && ( pos >= ptr_diff ( p, arg )));
     ++p;
     }
 
- sr1 = arg;
- p = arg;
+ sr1 = arg;
+ p = arg;
 // for all possible chars, see if we find them in the right place.
 // Note that strchr will/might do the _wrong_ thing if we search for NULL
- for ( int ch = 1; ch < 256; ++ch ) {
+ for ( int ch = 1; ch < 256; ++ch ) {
         string_ref::size_type pos = sr1.find(ch);
         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;
- p = arg;
+ sr1 = arg;
+ p = arg;
 // for all possible chars, see if we find them in the right place.
 // Note that strchr will/might do the _wrong_ thing if we search for NULL
- for ( int ch = 1; ch < 256; ++ch ) {
+ for ( int ch = 1; ch < 256; ++ch ) {
         string_ref::size_type pos = sr1.rfind(ch);
         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 );
     }
 
 
@@ -173,56 +178,56 @@
         }
         
 // Basic sanity checking for "find_first_of / find_first_not_of"
- sr1 = arg;
- sr2 = arg;
- while ( !sr1.empty() ) {
- BOOST_CHECK ( sr1.find_first_of ( sr2 ) == 0 );
- BOOST_CHECK ( sr1.find_first_not_of ( sr2 ) == string_ref::npos );
- sr1.remove_prefix ( 1 );
- }
+ sr1 = arg;
+ sr2 = arg;
+ while ( !sr1.empty() ) {
+ BOOST_CHECK ( sr1.find_first_of ( sr2 ) == 0 );
+ BOOST_CHECK ( sr1.find_first_not_of ( sr2 ) == string_ref::npos );
+ sr1.remove_prefix ( 1 );
+ }
 
- p = arg;
- sr1 = arg;
- while ( *p ) {
+ p = arg;
+ sr1 = 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 );
- BOOST_CHECK ( sr1 [ pos2 ] != *p );
- }
+ for ( size_t i = 0 ; i < pos2; ++i )
+ BOOST_CHECK ( sr1[i] == *p );
+ BOOST_CHECK ( sr1 [ pos2 ] != *p );
+ }
 
         BOOST_CHECK ( pos2 != pos1 );
         ++p;
         }
         
 // Basic sanity checking for "find_last_of / find_last_not_of"
- sr1 = arg;
- sr2 = arg;
- while ( !sr1.empty() ) {
- BOOST_CHECK ( sr1.find_last_of ( sr2 ) == ( sr1.size () - 1 ));
- BOOST_CHECK ( sr1.find_last_not_of ( sr2 ) == string_ref::npos );
- sr1.remove_suffix ( 1 );
- }
+ sr1 = arg;
+ sr2 = arg;
+ while ( !sr1.empty() ) {
+ BOOST_CHECK ( sr1.find_last_of ( sr2 ) == ( sr1.size () - 1 ));
+ BOOST_CHECK ( sr1.find_last_not_of ( sr2 ) == string_ref::npos );
+ sr1.remove_suffix ( 1 );
+ }
 
- p = arg;
- sr1 = arg;
- while ( *p ) {
+ p = arg;
+ sr1 = 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 )
- BOOST_CHECK ( sr1[i] == *p );
- BOOST_CHECK ( sr1 [ pos2 ] != *p );
- }
+ for ( size_t i = sr1.size () -1 ; i > pos2; --i )
+ BOOST_CHECK ( sr1[i] == *p );
+ BOOST_CHECK ( sr1 [ pos2 ] != *p );
+ }
          
         BOOST_CHECK ( pos2 != pos1 );
         ++p;
         }
-
+
     }
 
 const char *test_strings [] = {


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk