fix breakage of string_ref logical ops, detabify, remove trailing whitespace

[SVN r83147]
This commit is contained in:
Eric Niebler 2013-02-25 06:30:00 +00:00
parent 9284a64936
commit e0e16be802
3 changed files with 234 additions and 169 deletions

View File

@ -34,8 +34,6 @@ namespace boost {
bool operator () ( charT val ) const { return traits::eq ( ch_, val ); }
charT ch_;
};
template<typename T> struct __identity { typedef T type; };
}
template<typename charT, typename traits> class basic_string_ref;
@ -215,7 +213,7 @@ namespace boost {
}
size_type find_first_not_of(basic_string_ref s) const {
const_iterator iter = find_not_of ( this->cbegin (), this->cend (), s );
const_iterator iter = find_not_of ( this->cbegin (), this->cend (), s );
return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
}
@ -227,7 +225,7 @@ namespace boost {
}
size_type find_last_not_of(basic_string_ref s) const {
const_reverse_iterator iter = find_not_of ( this->crbegin (), this->crend (), s );
const_reverse_iterator iter = find_not_of ( this->crbegin (), this->crend (), s );
return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter );
}
@ -246,11 +244,11 @@ namespace boost {
template <typename Iterator>
Iterator find_not_of ( Iterator first, Iterator last, basic_string_ref s ) const {
for ( ; first != last ; ++first )
if ( 0 == traits::find ( s.ptr_, s.len_, *first ))
return first;
return last;
}
for ( ; first != last ; ++first )
if ( 0 == traits::find ( s.ptr_, s.len_, *first ))
return first;
return last;
}
@ -259,22 +257,32 @@ namespace boost {
};
// Comparison operators (3 for each operation)
// Comparison operators
// Equality
template<typename charT, typename traits>
bool operator==(basic_string_ref<charT, traits> x, basic_string_ref<charT, traits> y) {
if ( x.size () != y.size ()) return false;
return x.compare(y) == 0;
}
template<typename charT, typename traits>
bool operator==(basic_string_ref<charT, traits> x, typename detail::__identity<basic_string_ref<charT, traits> >::type y) {
if ( x.size () != y.size ()) return false;
return x.compare(y) == 0;
template<typename charT, typename traits, typename Allocator>
bool operator==(basic_string_ref<charT, traits> x, const std::basic_string<charT, traits, Allocator> & y) {
return x == basic_string_ref<charT, traits>(y);
}
template<typename charT, typename traits, typename Allocator>
bool operator==(const std::basic_string<charT, traits, Allocator> & x, basic_string_ref<charT, traits> y) {
return basic_string_ref<charT, traits>(x) == y;
}
template<typename charT, typename traits>
bool operator==(typename detail::__identity<basic_string_ref<charT, traits> >::type x, basic_string_ref<charT, traits> y) {
if ( x.size () != y.size ()) return false;
return x.compare(y) == 0;
bool operator==(basic_string_ref<charT, traits> x, const charT * y) {
return x == basic_string_ref<charT, traits>(y);
}
template<typename charT, typename traits>
bool operator==(const charT * x, basic_string_ref<charT, traits> y) {
return basic_string_ref<charT, traits>(x) == y;
}
// Inequality
@ -283,15 +291,25 @@ namespace boost {
if ( x.size () != y.size ()) return true;
return x.compare(y) != 0;
}
template<typename charT, typename traits>
bool operator!=(basic_string_ref<charT, traits> x, typename detail::__identity<basic_string_ref<charT, traits> >::type y) {
if ( x.size () != y.size ()) return true;
return x.compare(y) != 0;
template<typename charT, typename traits, typename Allocator>
bool operator!=(basic_string_ref<charT, traits> x, const std::basic_string<charT, traits, Allocator> & y) {
return x != basic_string_ref<charT, traits>(y);
}
template<typename charT, typename traits, typename Allocator>
bool operator!=(const std::basic_string<charT, traits, Allocator> & x, basic_string_ref<charT, traits> y) {
return basic_string_ref<charT, traits>(x) != y;
}
template<typename charT, typename traits>
bool operator!=(typename detail::__identity<basic_string_ref<charT, traits> >::type x, basic_string_ref<charT, traits> y) {
if ( x.size () != y.size ()) return true;
return x.compare(y) != 0;
bool operator!=(basic_string_ref<charT, traits> x, const charT * y) {
return x != basic_string_ref<charT, traits>(y);
}
template<typename charT, typename traits>
bool operator!=(const charT * x, basic_string_ref<charT, traits> y) {
return basic_string_ref<charT, traits>(x) != y;
}
// Less than
@ -299,13 +317,25 @@ namespace boost {
bool operator<(basic_string_ref<charT, traits> x, basic_string_ref<charT, traits> y) {
return x.compare(y) < 0;
}
template<typename charT, typename traits>
bool operator<(basic_string_ref<charT, traits> x, typename detail::__identity<basic_string_ref<charT, traits> >::type y) {
return x.compare(y) < 0;
template<typename charT, typename traits, typename Allocator>
bool operator<(basic_string_ref<charT, traits> x, const std::basic_string<charT, traits, Allocator> & y) {
return x < basic_string_ref<charT, traits>(y);
}
template<typename charT, typename traits, typename Allocator>
bool operator<(const std::basic_string<charT, traits, Allocator> & x, basic_string_ref<charT, traits> y) {
return basic_string_ref<charT, traits>(x) < y;
}
template<typename charT, typename traits>
bool operator<(typename detail::__identity<basic_string_ref<charT, traits> >::type x, basic_string_ref<charT, traits> y) {
return x.compare(y) < 0;
bool operator<(basic_string_ref<charT, traits> x, const charT * y) {
return x < basic_string_ref<charT, traits>(y);
}
template<typename charT, typename traits>
bool operator<(const charT * x, basic_string_ref<charT, traits> y) {
return basic_string_ref<charT, traits>(x) < y;
}
// Greater than
@ -313,13 +343,25 @@ namespace boost {
bool operator>(basic_string_ref<charT, traits> x, basic_string_ref<charT, traits> y) {
return x.compare(y) > 0;
}
template<typename charT, typename traits>
bool operator>(basic_string_ref<charT, traits> x, typename detail::__identity<basic_string_ref<charT, traits> >::type y) {
return x.compare(y) > 0;
template<typename charT, typename traits, typename Allocator>
bool operator>(basic_string_ref<charT, traits> x, const std::basic_string<charT, traits, Allocator> & y) {
return x > basic_string_ref<charT, traits>(y);
}
template<typename charT, typename traits, typename Allocator>
bool operator>(const std::basic_string<charT, traits, Allocator> & x, basic_string_ref<charT, traits> y) {
return basic_string_ref<charT, traits>(x) > y;
}
template<typename charT, typename traits>
bool operator>(typename detail::__identity<basic_string_ref<charT, traits> >::type x, basic_string_ref<charT, traits> y) {
return x.compare(y) > 0;
bool operator>(basic_string_ref<charT, traits> x, const charT * y) {
return x > basic_string_ref<charT, traits>(y);
}
template<typename charT, typename traits>
bool operator>(const charT * x, basic_string_ref<charT, traits> y) {
return basic_string_ref<charT, traits>(x) > y;
}
// Less than or equal to
@ -327,13 +369,25 @@ namespace boost {
bool operator<=(basic_string_ref<charT, traits> x, basic_string_ref<charT, traits> y) {
return x.compare(y) <= 0;
}
template<typename charT, typename traits>
bool operator<=(basic_string_ref<charT, traits> x, typename detail::__identity<basic_string_ref<charT, traits> >::type y) {
return x.compare(y) <= 0;
template<typename charT, typename traits, typename Allocator>
bool operator<=(basic_string_ref<charT, traits> x, const std::basic_string<charT, traits, Allocator> & y) {
return x <= basic_string_ref<charT, traits>(y);
}
template<typename charT, typename traits, typename Allocator>
bool operator<=(const std::basic_string<charT, traits, Allocator> & x, basic_string_ref<charT, traits> y) {
return basic_string_ref<charT, traits>(x) <= y;
}
template<typename charT, typename traits>
bool operator<=(typename detail::__identity<basic_string_ref<charT, traits> >::type x, basic_string_ref<charT, traits> y) {
return x.compare(y) <= 0;
bool operator<=(basic_string_ref<charT, traits> x, const charT * y) {
return x <= basic_string_ref<charT, traits>(y);
}
template<typename charT, typename traits>
bool operator<=(const charT * x, basic_string_ref<charT, traits> y) {
return basic_string_ref<charT, traits>(x) <= y;
}
// Greater than or equal to
@ -341,16 +395,26 @@ namespace boost {
bool operator>=(basic_string_ref<charT, traits> x, basic_string_ref<charT, traits> y) {
return x.compare(y) >= 0;
}
template<typename charT, typename traits>
bool operator>=(basic_string_ref<charT, traits> x, typename detail::__identity<basic_string_ref<charT, traits> >::type y) {
return x.compare(y) >= 0;
}
template<typename charT, typename traits>
bool operator>=(typename detail::__identity<basic_string_ref<charT, traits> >::type x, basic_string_ref<charT, traits> y) {
return x.compare(y) >= 0;
template<typename charT, typename traits, typename Allocator>
bool operator>=(basic_string_ref<charT, traits> x, const std::basic_string<charT, traits, Allocator> & y) {
return x >= basic_string_ref<charT, traits>(y);
}
template<typename charT, typename traits, typename Allocator>
bool operator>=(const std::basic_string<charT, traits, Allocator> & x, basic_string_ref<charT, traits> y) {
return basic_string_ref<charT, traits>(x) >= y;
}
template<typename charT, typename traits>
bool operator>=(basic_string_ref<charT, traits> x, const charT * y) {
return x >= basic_string_ref<charT, traits>(y);
}
template<typename charT, typename traits>
bool operator>=(const charT * x, basic_string_ref<charT, traits> y) {
return basic_string_ref<charT, traits>(x) >= y;
}
// Inserter
template<class charT, class traits>

View File

@ -85,9 +85,9 @@ void reverse ( const char *arg ) {
// 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 );
}
BOOST_CHECK ( res >= base );
return static_cast<string_ref::size_type> ( res - base );
}
void find ( const char *arg ) {
string_ref sr1;
@ -115,12 +115,12 @@ void find ( const char *arg ) {
// Look for pairs on characters (searching from the start)
sr1 = arg;
p = arg;
while ( *p && *(p+1)) {
string_ref sr3 ( p, 2 );
string_ref::size_type pos = sr1.find ( sr3 );
BOOST_CHECK ( pos != string_ref::npos && pos <= static_cast<string_ref::size_type>( p - arg ));
p++;
}
while ( *p && *(p+1)) {
string_ref sr3 ( p, 2 );
string_ref::size_type pos = sr1.find ( sr3 );
BOOST_CHECK ( pos != string_ref::npos && pos <= static_cast<string_ref::size_type>( p - arg ));
p++;
}
sr1 = arg;
p = arg;
@ -244,50 +244,51 @@ void find ( const char *arg ) {
void to_string ( const char *arg ) {
string_ref sr1;
std::string str1;
std::string str2;
std::string str1;
std::string str2;
str1.assign ( arg );
sr1 = arg;
str1.assign ( arg );
sr1 = arg;
// str2 = sr1.to_string<std::allocator<char> > ();
str2 = sr1.to_string ();
BOOST_CHECK ( str1 == str2 );
str2 = sr1.to_string ();
BOOST_CHECK ( str1 == str2 );
#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
std::string str3 = static_cast<std::string> ( sr1 );
BOOST_CHECK ( str1 == str3 );
std::string str3 = static_cast<std::string> ( sr1 );
BOOST_CHECK ( str1 == str3 );
#endif
}
void compare ( const char *arg ) {
string_ref sr1;
std::string str1;
std::string str2 = str1;
std::string str1;
std::string str2 = str1;
str1.assign ( arg );
sr1 = arg;
BOOST_CHECK ( sr1 == str1); // compare string and string_ref
BOOST_CHECK ( str1 == sr1 ); // compare string_ref and string
BOOST_CHECK ( sr1 == arg ); // compare string_ref and pointer
BOOST_CHECK ( arg == sr1 ); // compare pointer and string_ref
str1.assign ( arg );
sr1 = arg;
BOOST_CHECK ( sr1 == sr1); // compare string_ref and string_ref
BOOST_CHECK ( sr1 == str1); // compare string and string_ref
BOOST_CHECK ( str1 == sr1 ); // compare string_ref and string
BOOST_CHECK ( sr1 == arg ); // compare string_ref and pointer
BOOST_CHECK ( arg == sr1 ); // compare pointer and string_ref
if ( sr1.size () > 0 ) {
(*str1.rbegin())++;
BOOST_CHECK ( sr1 != str1 );
BOOST_CHECK ( str1 != sr1 );
BOOST_CHECK ( sr1 < str1 );
BOOST_CHECK ( sr1 <= str1 );
BOOST_CHECK ( str1 > sr1 );
BOOST_CHECK ( str1 >= sr1 );
if ( sr1.size () > 0 ) {
(*str1.rbegin())++;
BOOST_CHECK ( sr1 != str1 );
BOOST_CHECK ( str1 != sr1 );
BOOST_CHECK ( sr1 < str1 );
BOOST_CHECK ( sr1 <= str1 );
BOOST_CHECK ( str1 > sr1 );
BOOST_CHECK ( str1 >= sr1 );
(*str1.rbegin()) -= 2;
BOOST_CHECK ( sr1 != str1 );
BOOST_CHECK ( str1 != sr1 );
BOOST_CHECK ( sr1 > str1 );
BOOST_CHECK ( sr1 >= str1 );
BOOST_CHECK ( str1 < sr1 );
BOOST_CHECK ( str1 <= sr1 );
}
(*str1.rbegin()) -= 2;
BOOST_CHECK ( sr1 != str1 );
BOOST_CHECK ( str1 != sr1 );
BOOST_CHECK ( sr1 > str1 );
BOOST_CHECK ( sr1 >= str1 );
BOOST_CHECK ( str1 < sr1 );
BOOST_CHECK ( str1 <= sr1 );
}
}
const char *test_strings [] = {
@ -310,7 +311,7 @@ BOOST_AUTO_TEST_CASE( test_main )
reverse ( *p );
find ( *p );
to_string ( *p );
compare ( *p );
compare ( *p );
p++;
}