diff --git a/include/boost/utility/base_from_member.hpp b/include/boost/utility/base_from_member.hpp index fc0e13c..604541d 100644 --- a/include/boost/utility/base_from_member.hpp +++ b/include/boost/utility/base_from_member.hpp @@ -47,11 +47,11 @@ // {} // This macro should only persist within this file. -#define BOOST_PRIVATE_CTR_DEF( z, n, data ) \ - template < BOOST_PP_ENUM_PARAMS(n, typename T) > \ - explicit base_from_member( BOOST_PP_ENUM_BINARY_PARAMS(n, T, x) ) \ - : member( BOOST_PP_ENUM_PARAMS(n, x) ) \ - {} \ +#define BOOST_PRIVATE_CTR_DEF( z, n, data ) \ + template < BOOST_PP_ENUM_PARAMS(n, typename T) > \ + base_from_member( BOOST_PP_ENUM_BINARY_PARAMS(n, T, x) ) \ + : member( BOOST_PP_ENUM_PARAMS(n, x) ) \ + {} \ /**/ @@ -142,7 +142,8 @@ protected: : member() {} - BOOST_PP_REPEAT_FROM_TO( 1, BOOST_PP_INC(BOOST_BASE_FROM_MEMBER_MAX_ARITY), + template < typename T0 > explicit base_from_member( T0 x0 ) : member( x0 ) {} + BOOST_PP_REPEAT_FROM_TO( 2, BOOST_PP_INC(BOOST_BASE_FROM_MEMBER_MAX_ARITY), BOOST_PRIVATE_CTR_DEF, _ ) #endif diff --git a/include/boost/utility/string_ref.hpp b/include/boost/utility/string_ref.hpp index 8707157..447d3cc 100644 --- a/include/boost/utility/string_ref.hpp +++ b/include/boost/utility/string_ref.hpp @@ -57,26 +57,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_NO_CXX11_DEFAULTED_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_NO_CXX11_DEFAULTED_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 basic_string_ref(const std::basic_string& 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 +185,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 ( 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 +206,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 +223,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 - size_type reverse_distance ( r_iter first, r_iter last ) const { - return len_ - 1 - std::distance ( first, last ); - } template Iterator find_not_of ( Iterator first, Iterator last, basic_string_ref s ) const { @@ -405,7 +412,7 @@ namespace boost { namespace detail { template - inline void insert_fill_chars(std::basic_ostream& os, std::size_t n) { + inline void sr_insert_fill_chars(std::basic_ostream& 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 +423,19 @@ namespace boost { } template - void insert_aligned(std::basic_ostream& os, const basic_string_ref& str) { + void sr_insert_aligned(std::basic_ostream& os, const basic_string_ref& 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::adjustfield) == std::basic_ostream::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 +451,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; diff --git a/include/boost/utility/string_view.hpp b/include/boost/utility/string_view.hpp index 9de32cc..e3cb0ae 100644 --- a/include/boost/utility/string_view.hpp +++ b/include/boost/utility/string_view.hpp @@ -65,14 +65,25 @@ namespace boost { BOOST_CONSTEXPR basic_string_view() BOOST_NOEXCEPT : ptr_(NULL), len_(0) {} + // by defaulting these functions, basic_string_ref becomes + // trivially copy/move constructible. BOOST_CONSTEXPR basic_string_view(const basic_string_view &rhs) BOOST_NOEXCEPT +#ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS + = default; +#else : ptr_(rhs.ptr_), len_(rhs.len_) {} +#endif - basic_string_view& operator=(const basic_string_view &rhs) BOOST_NOEXCEPT { + basic_string_view& operator=(const basic_string_view &rhs) BOOST_NOEXCEPT +#ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS + = default; +#else + { ptr_ = rhs.ptr_; len_ = rhs.len_; return *this; } +#endif template basic_string_view(const std::basic_string= len_) - pos = len_ - 1;; + pos = len_ - 1; if (s.len_ == 0u) return pos; pos = len_ - (pos+1); @@ -538,7 +549,7 @@ namespace boost { namespace detail { template - inline void insert_fill_chars(std::basic_ostream& os, std::size_t n) { + inline void sv_insert_fill_chars(std::basic_ostream& 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()); @@ -549,19 +560,19 @@ namespace boost { } template - void insert_aligned(std::basic_ostream& os, const basic_string_view& str) { + void sv_insert_aligned(std::basic_ostream& os, const basic_string_view& 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::adjustfield) == std::basic_ostream::left; if (!align_left) { - detail::insert_fill_chars(os, alignment_size); + detail::sv_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::sv_insert_fill_chars(os, alignment_size); } } @@ -578,7 +589,7 @@ namespace boost { if (w <= size) os.write(str.data(), size); else - detail::insert_aligned(os, str); + detail::sv_insert_aligned(os, str); os.width(0); } return os;