Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82902 - in trunk: boost/utility libs/utility/test
From: marshall_at_[hidden]
Date: 2013-02-15 11:12:31


Author: marshall
Date: 2013-02-15 11:12:30 EST (Fri, 15 Feb 2013)
New Revision: 82902
URL: http://svn.boost.org/trac/boost/changeset/82902

Log:
Added to_string and better comparisons to Boost.StringRef
Text files modified:
   trunk/boost/utility/string_ref.hpp | 68 +++++++++++++++++++++++++++++++++++++++
   trunk/libs/utility/test/string_ref_test2.cpp | 9 ++--
   2 files changed, 71 insertions(+), 6 deletions(-)

Modified: trunk/boost/utility/string_ref.hpp
==============================================================================
--- trunk/boost/utility/string_ref.hpp (original)
+++ trunk/boost/utility/string_ref.hpp 2013-02-15 11:12:30 EST (Fri, 15 Feb 2013)
@@ -34,6 +34,8 @@
             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;
@@ -94,6 +96,10 @@
             }
 #endif
         
+ std::basic_string<charT, traits> to_string () const {
+ return std::basic_string<charT, traits> ( ptr_, len_ );
+ }
+
         // iterators
         BOOST_CONSTEXPR const_iterator begin() const { return ptr_; }
         BOOST_CONSTEXPR const_iterator cbegin() const { return ptr_; }
@@ -252,38 +258,98 @@
         std::size_t len_;
         };
     
- // Comparison operators
+
+// Comparison operators (3 for each operation)
+// 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>
+ 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;
+ }
     
+// Inequality
     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 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>
+ 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;
+ }
 
+// Less than
     template<typename charT, typename traits>
     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;
+ }
 
+// Greater than
     template<typename charT, typename traits>
     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;
+ }
 
+// Less than or equal to
     template<typename charT, typename traits>
     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;
+ }
 
+// Greater than or equal to
     template<typename charT, typename traits>
     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;
+ }
+
 
     
     // Inserter

Modified: trunk/libs/utility/test/string_ref_test2.cpp
==============================================================================
--- trunk/libs/utility/test/string_ref_test2.cpp (original)
+++ trunk/libs/utility/test/string_ref_test2.cpp 2013-02-15 11:12:30 EST (Fri, 15 Feb 2013)
@@ -118,7 +118,7 @@
         while ( *p && *(p+1)) {
                 string_ref sr3 ( p, 2 );
                 string_ref::size_type pos = sr1.find ( sr3 );
- BOOST_CHECK ( pos != string_ref::npos && pos <= ( p - arg ));
+ BOOST_CHECK ( pos != string_ref::npos && pos <= static_cast<string_ref::size_type>( p - arg ));
                 p++;
                 }
                 
@@ -241,7 +241,7 @@
 
     }
 
-#if 0
+
 void to_string ( const char *arg ) {
     string_ref sr1;
         std::string str1;
@@ -289,7 +289,6 @@
                 BOOST_CHECK ( str1 <= sr1 );
                 }
     }
-#endif
 
 const char *test_strings [] = {
     "",
@@ -310,8 +309,8 @@
         ends_with ( *p );
         reverse ( *p );
         find ( *p );
-// to_string ( *p );
-// compare ( *p );
+ to_string ( *p );
+ compare ( *p );
                 
         p++;
         }


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