diff options
Diffstat (limited to 'boost/utility/string_ref.hpp')
-rw-r--r-- | boost/utility/string_ref.hpp | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/boost/utility/string_ref.hpp b/boost/utility/string_ref.hpp index 8707157c62..5acf346fba 100644 --- a/boost/utility/string_ref.hpp +++ b/boost/utility/string_ref.hpp @@ -27,6 +27,11 @@ #include <string> #include <iosfwd> +#if defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || (defined(BOOST_GCC) && ((BOOST_GCC+0) / 100) <= 406) +// GCC 4.6 cannot handle a defaulted function with noexcept specifier +#define BOOST_STRING_REF_NO_CXX11_DEFAULTED_NOEXCEPT_FUNCTIONS +#endif + namespace boost { namespace detail { @@ -57,26 +62,37 @@ namespace boost { static BOOST_CONSTEXPR_OR_CONST size_type npos = size_type(-1); // construct/copy - BOOST_CONSTEXPR basic_string_ref () + BOOST_CONSTEXPR basic_string_ref () BOOST_NOEXCEPT : ptr_(NULL), len_(0) {} - BOOST_CONSTEXPR basic_string_ref (const basic_string_ref &rhs) + // by defaulting these functions, basic_string_ref becomes + // trivially copy/move constructible. + BOOST_CONSTEXPR basic_string_ref (const basic_string_ref &rhs) BOOST_NOEXCEPT +#ifndef BOOST_STRING_REF_NO_CXX11_DEFAULTED_NOEXCEPT_FUNCTIONS + = default; +#else : ptr_(rhs.ptr_), len_(rhs.len_) {} +#endif - basic_string_ref& operator=(const basic_string_ref &rhs) { + basic_string_ref& operator=(const basic_string_ref &rhs) BOOST_NOEXCEPT +#ifndef BOOST_STRING_REF_NO_CXX11_DEFAULTED_NOEXCEPT_FUNCTIONS + = default; +#else + { ptr_ = rhs.ptr_; len_ = rhs.len_; return *this; } +#endif - basic_string_ref(const charT* str) + basic_string_ref(const charT* str) BOOST_NOEXCEPT : ptr_(str), len_(traits::length(str)) {} template<typename Allocator> basic_string_ref(const std::basic_string<charT, traits, Allocator>& str) : ptr_(str.data()), len_(str.length()) {} - BOOST_CONSTEXPR basic_string_ref(const charT* str, size_type len) + BOOST_CONSTEXPR basic_string_ref(const charT* str, size_type len) BOOST_NOEXCEPT : ptr_(str), len_(len) {} #ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS @@ -174,13 +190,13 @@ namespace boost { size_type rfind(basic_string_ref s) const { const_reverse_iterator iter = std::search ( this->crbegin (), this->crend (), s.crbegin (), s.crend (), traits::eq ); - return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter ); + return iter == this->crend () ? npos : (std::distance(iter, this->crend()) - s.size()); } size_type rfind(charT c) const { const_reverse_iterator iter = std::find_if ( this->crbegin (), this->crend (), detail::string_ref_traits_eq<charT, traits> ( c )); - return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter ); + return iter == this->crend () ? npos : (this->size() - 1 - std::distance(this->crbegin(), iter)); } size_type find_first_of(charT c) const { return find (c); } @@ -195,7 +211,7 @@ namespace boost { size_type find_last_of(basic_string_ref s) const { const_reverse_iterator iter = std::find_first_of ( this->crbegin (), this->crend (), s.cbegin (), s.cend (), traits::eq ); - return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter); + return iter == this->crend () ? npos : (this->size() - 1 - std::distance(this->crbegin(), iter)); } size_type find_first_not_of(basic_string_ref s) const { @@ -212,21 +228,17 @@ 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 ); - return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter ); + return iter == this->crend () ? npos : (this->size() - 1 - std::distance(this->crbegin(), iter)); } size_type find_last_not_of(charT c) const { for ( const_reverse_iterator iter = this->crbegin (); iter != this->crend (); ++iter ) if ( !traits::eq ( c, *iter )) - return reverse_distance ( this->crbegin (), iter ); + return this->size() - 1 - std::distance(this->crbegin(), iter); return npos; } private: - template <typename r_iter> - size_type reverse_distance ( r_iter first, r_iter last ) const { - return len_ - 1 - std::distance ( first, last ); - } template <typename Iterator> Iterator find_not_of ( Iterator first, Iterator last, basic_string_ref s ) const { @@ -405,7 +417,7 @@ namespace boost { namespace detail { template<class charT, class traits> - inline void insert_fill_chars(std::basic_ostream<charT, traits>& os, std::size_t n) { + inline void sr_insert_fill_chars(std::basic_ostream<charT, traits>& os, std::size_t n) { enum { chunk_size = 8 }; charT fill_chars[chunk_size]; std::fill_n(fill_chars, static_cast< std::size_t >(chunk_size), os.fill()); @@ -416,19 +428,19 @@ namespace boost { } template<class charT, class traits> - void insert_aligned(std::basic_ostream<charT, traits>& os, const basic_string_ref<charT,traits>& str) { + void sr_insert_aligned(std::basic_ostream<charT, traits>& os, const basic_string_ref<charT,traits>& str) { const std::size_t size = str.size(); const std::size_t alignment_size = static_cast< std::size_t >(os.width()) - size; const bool align_left = (os.flags() & std::basic_ostream<charT, traits>::adjustfield) == std::basic_ostream<charT, traits>::left; if (!align_left) { - detail::insert_fill_chars(os, alignment_size); + detail::sr_insert_fill_chars(os, alignment_size); if (os.good()) os.write(str.data(), size); } else { os.write(str.data(), size); if (os.good()) - detail::insert_fill_chars(os, alignment_size); + detail::sr_insert_fill_chars(os, alignment_size); } } @@ -444,7 +456,7 @@ namespace boost { if (w <= size) os.write(str.data(), size); else - detail::insert_aligned(os, str); + detail::sr_insert_aligned(os, str); os.width(0); } return os; |