|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r81361 - trunk/boost/algorithm
From: marshall_at_[hidden]
Date: 2012-11-15 17:16:48
Author: marshall
Date: 2012-11-15 17:16:48 EST (Thu, 15 Nov 2012)
New Revision: 81361
URL: http://svn.boost.org/trac/boost/changeset/81361
Log:
Partial fixes from Steven's code review
Text files modified:
trunk/boost/algorithm/string_ref.hpp | 33 +++++++++++++++------------------
1 files changed, 15 insertions(+), 18 deletions(-)
Modified: trunk/boost/algorithm/string_ref.hpp
==============================================================================
--- trunk/boost/algorithm/string_ref.hpp (original)
+++ trunk/boost/algorithm/string_ref.hpp 2012-11-15 17:16:48 EST (Thu, 15 Nov 2012)
@@ -68,11 +68,8 @@
// construct/copy
BOOST_CONSTEXPR basic_string_ref ()
-#ifdef BOOST_NO_CXX11_NULLPTR
: ptr_(NULL), len_(0) {}
-#else
- : ptr_(nullptr), len_(0) {}
-#endif
+
BOOST_CONSTEXPR basic_string_ref (const basic_string_ref &rhs)
: ptr_(rhs.ptr_), len_(rhs.len_) {}
@@ -83,7 +80,7 @@
}
basic_string_ref(const charT* str)
- : ptr_(str), len_(std::strlen(str)) {}
+ : ptr_(str), len_(traits::length(str)) {}
template<typename Allocator>
basic_string_ref(const std::basic_string<charT, traits, Allocator>& str)
@@ -105,14 +102,14 @@
#endif
// iterators
- BOOST_CONSTEXPR const_iterator begin() const { return ptr_; }
- BOOST_CONSTEXPR const_iterator cbegin() const { return ptr_; }
- BOOST_CONSTEXPR const_iterator end() const { return ptr_ + len_; }
- BOOST_CONSTEXPR const_iterator cend() const { return ptr_ + len_; }
- const_reverse_iterator rbegin() const { return const_reverse_iterator (end()); }
- const_reverse_iterator crbegin() const { return const_reverse_iterator (end()); }
- const_reverse_iterator rend() const { return const_reverse_iterator (begin()); }
- const_reverse_iterator crend() const { return const_reverse_iterator (begin()); }
+ BOOST_CONSTEXPR const_iterator begin() const { return ptr_; }
+ BOOST_CONSTEXPR const_iterator cbegin() const { return ptr_; }
+ BOOST_CONSTEXPR const_iterator end() const { return ptr_ + len_; }
+ BOOST_CONSTEXPR const_iterator cend() const { return ptr_ + len_; }
+ const_reverse_iterator rbegin() const { return const_reverse_iterator (end()); }
+ const_reverse_iterator crbegin() const { return const_reverse_iterator (end()); }
+ const_reverse_iterator rend() const { return const_reverse_iterator (begin()); }
+ const_reverse_iterator crend() const { return const_reverse_iterator (begin()); }
// capacity
BOOST_CONSTEXPR size_type size() const { return len_; }
@@ -160,24 +157,24 @@
}
int compare(basic_string_ref x) const {
- int cmp = std::memcmp ( ptr_, x.ptr_, std::min(len_, x.len_));
+ int cmp = traits::compare ( ptr_, x.ptr_, std::min(len_, x.len_));
return cmp != 0 ? cmp : ( len_ == x.len_ ? 0 : len_ < x.len_ ? -1 : 1 );
}
bool starts_with(charT c) const { return !empty() && front() == c; }
bool starts_with(basic_string_ref x) const {
- return len_ >= x.len_ && std::memcmp ( ptr_, x.ptr_, x.len_ ) == 0;
+ return len_ >= x.len_ && traits::compare ( ptr_, x.ptr_, x.len_ ) == 0;
}
bool ends_with(charT c) const { return !empty() && back() == c; }
bool ends_with(basic_string_ref x) const {
- return len_ >= x.len_ && std::memcmp ( ptr_ + len_ - x.len_, x.ptr_, x.len_ ) == 0;
+ return len_ >= x.len_ && traits::compare ( ptr_ + len_ - x.len_, x.ptr_, x.len_ ) == 0;
}
// Have to use traits here
size_type find(basic_string_ref s) const {
- const_iterator iter = std::find_if ( this->cbegin (), this->cend (),
+ const_iterator iter = std::search ( this->cbegin (), this->cend (),
s.cbegin (), s.cend (), traits::eq );
return iter = this->cend () ? npos : std::distance ( this->cbegin (), iter );
}
@@ -194,7 +191,7 @@
}
size_type rfind(basic_string_ref s) const {
- const_iterator iter = std::find_if ( this->crbegin (), this->crend (),
+ const_iterator iter = std::search ( this->crbegin (), this->crend (),
s.crbegin (), s.crend (), traits::eq );
return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter );
}
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