summaryrefslogtreecommitdiff
path: root/boost/utility
diff options
context:
space:
mode:
Diffstat (limited to 'boost/utility')
-rw-r--r--boost/utility/base_from_member.hpp13
-rw-r--r--boost/utility/string_ref.hpp50
-rw-r--r--boost/utility/string_view.hpp103
3 files changed, 100 insertions, 66 deletions
diff --git a/boost/utility/base_from_member.hpp b/boost/utility/base_from_member.hpp
index fc0e13c0d7..604541d19a 100644
--- a/boost/utility/base_from_member.hpp
+++ b/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/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;
diff --git a/boost/utility/string_view.hpp b/boost/utility/string_view.hpp
index 9de32ccc56..f5d5eb9060 100644
--- a/boost/utility/string_view.hpp
+++ b/boost/utility/string_view.hpp
@@ -30,6 +30,11 @@
#include <cstring>
#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_VIEW_NO_CXX11_DEFAULTED_NOEXCEPT_FUNCTIONS
+#endif
+
namespace boost {
namespace detail {
@@ -65,14 +70,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_STRING_VIEW_NO_CXX11_DEFAULTED_NOEXCEPT_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_STRING_VIEW_NO_CXX11_DEFAULTED_NOEXCEPT_FUNCTIONS
+ = default;
+#else
+ {
ptr_ = rhs.ptr_;
len_ = rhs.len_;
return *this;
}
+#endif
template<typename Allocator>
basic_string_view(const std::basic_string<charT, traits,
@@ -146,13 +162,18 @@ namespace boost {
#ifndef BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS
template<typename Allocator = std::allocator<charT> >
- std::basic_string<charT, traits> to_string(const Allocator& a = Allocator()) const {
+ std::basic_string<charT, traits, Allocator> to_string(const Allocator& a = Allocator()) const {
return std::basic_string<charT, traits, Allocator>(begin(), end(), a);
}
#else
std::basic_string<charT, traits> to_string() const {
return std::basic_string<charT, traits>(begin(), end());
}
+
+ template<typename Allocator>
+ std::basic_string<charT, traits, Allocator> to_string(const Allocator& a) const {
+ return std::basic_string<charT, traits, Allocator>(begin(), end(), a);
+ }
#endif
size_type copy(charT* s, size_type n, size_type pos=0) const {
@@ -204,7 +225,7 @@ namespace boost {
// Searches
BOOST_CONSTEXPR bool starts_with(charT c) const BOOST_NOEXCEPT { // Boost extension
return !empty() && traits::eq(c, front());
- }
+ }
BOOST_CONSTEXPR bool starts_with(basic_string_view x) const BOOST_NOEXCEPT { // Boost extension
return len_ >= x.len_ && traits::compare(ptr_, x.ptr_, x.len_) == 0;
@@ -215,7 +236,7 @@ namespace boost {
}
BOOST_CONSTEXPR bool ends_with(basic_string_view x) const BOOST_NOEXCEPT { // Boost extension
- return len_ >= x.len_ &&
+ return len_ >= x.len_ &&
traits::compare(ptr_ + len_ - x.len_, x.ptr_, x.len_) == 0;
}
@@ -240,11 +261,11 @@ namespace boost {
BOOST_CXX14_CONSTEXPR size_type rfind(basic_string_view s, size_type pos = npos) const BOOST_NOEXCEPT {
if (len_ < s.len_)
return npos;
- if (pos > len_ - s.len_)
+ if (pos > len_ - s.len_)
pos = len_ - s.len_;
if (s.len_ == 0u) // an empty string is always found
return pos;
- for (const charT* cur = ptr_ + pos;; --cur) {
+ for (const charT* cur = ptr_ + pos; ; --cur) {
if (traits::compare(cur, s.ptr_, s.len_) == 0)
return cur - ptr_;
if (cur == ptr_)
@@ -311,7 +332,7 @@ namespace boost {
// find_last_not_of
BOOST_CXX14_CONSTEXPR size_type find_last_not_of(basic_string_view s, size_type pos = npos) const BOOST_NOEXCEPT {
if (pos >= len_)
- pos = len_ - 1;;
+ pos = len_ - 1;
if (s.len_ == 0u)
return pos;
pos = len_ - (pos+1);
@@ -357,7 +378,7 @@ namespace boost {
// Inequality
template<typename charT, typename traits>
inline bool operator!=(basic_string_view<charT, traits> x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
if ( x.size () != y.size ()) return true;
return x.compare(y) != 0;
}
@@ -365,180 +386,180 @@ namespace boost {
// Less than
template<typename charT, typename traits>
inline bool operator<(basic_string_view<charT, traits> x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
return x.compare(y) < 0;
}
// Greater than
template<typename charT, typename traits>
inline bool operator>(basic_string_view<charT, traits> x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
return x.compare(y) > 0;
}
// Less than or equal to
template<typename charT, typename traits>
inline bool operator<=(basic_string_view<charT, traits> x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
return x.compare(y) <= 0;
}
// Greater than or equal to
template<typename charT, typename traits>
inline bool operator>=(basic_string_view<charT, traits> x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
return x.compare(y) >= 0;
}
// "sufficient additional overloads of comparison functions"
template<typename charT, typename traits, typename Allocator>
inline bool operator==(basic_string_view<charT, traits> x,
- const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
+ const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
return x == basic_string_view<charT, traits>(y);
}
template<typename charT, typename traits, typename Allocator>
inline bool operator==(const std::basic_string<charT, traits, Allocator> & x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
return basic_string_view<charT, traits>(x) == y;
}
template<typename charT, typename traits>
inline bool operator==(basic_string_view<charT, traits> x,
- const charT * y) BOOST_NOEXCEPT {
+ const charT * y) BOOST_NOEXCEPT {
return x == basic_string_view<charT, traits>(y);
}
template<typename charT, typename traits>
inline bool operator==(const charT * x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
return basic_string_view<charT, traits>(x) == y;
}
template<typename charT, typename traits, typename Allocator>
inline bool operator!=(basic_string_view<charT, traits> x,
- const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
+ const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
return x != basic_string_view<charT, traits>(y);
}
template<typename charT, typename traits, typename Allocator>
inline bool operator!=(const std::basic_string<charT, traits, Allocator> & x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
return basic_string_view<charT, traits>(x) != y;
}
template<typename charT, typename traits>
inline bool operator!=(basic_string_view<charT, traits> x,
- const charT * y) BOOST_NOEXCEPT {
+ const charT * y) BOOST_NOEXCEPT {
return x != basic_string_view<charT, traits>(y);
}
template<typename charT, typename traits>
inline bool operator!=(const charT * x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
return basic_string_view<charT, traits>(x) != y;
}
template<typename charT, typename traits, typename Allocator>
inline bool operator<(basic_string_view<charT, traits> x,
- const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
+ const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
return x < basic_string_view<charT, traits>(y);
}
template<typename charT, typename traits, typename Allocator>
inline bool operator<(const std::basic_string<charT, traits, Allocator> & x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
return basic_string_view<charT, traits>(x) < y;
}
template<typename charT, typename traits>
inline bool operator<(basic_string_view<charT, traits> x,
- const charT * y) BOOST_NOEXCEPT {
+ const charT * y) BOOST_NOEXCEPT {
return x < basic_string_view<charT, traits>(y);
}
template<typename charT, typename traits>
inline bool operator<(const charT * x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
return basic_string_view<charT, traits>(x) < y;
}
template<typename charT, typename traits, typename Allocator>
inline bool operator>(basic_string_view<charT, traits> x,
- const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
+ const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
return x > basic_string_view<charT, traits>(y);
}
template<typename charT, typename traits, typename Allocator>
inline bool operator>(const std::basic_string<charT, traits, Allocator> & x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
return basic_string_view<charT, traits>(x) > y;
}
template<typename charT, typename traits>
inline bool operator>(basic_string_view<charT, traits> x,
- const charT * y) BOOST_NOEXCEPT {
+ const charT * y) BOOST_NOEXCEPT {
return x > basic_string_view<charT, traits>(y);
}
template<typename charT, typename traits>
inline bool operator>(const charT * x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
return basic_string_view<charT, traits>(x) > y;
}
template<typename charT, typename traits, typename Allocator>
inline bool operator<=(basic_string_view<charT, traits> x,
- const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
+ const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
return x <= basic_string_view<charT, traits>(y);
}
template<typename charT, typename traits, typename Allocator>
inline bool operator<=(const std::basic_string<charT, traits, Allocator> & x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
return basic_string_view<charT, traits>(x) <= y;
}
template<typename charT, typename traits>
inline bool operator<=(basic_string_view<charT, traits> x,
- const charT * y) BOOST_NOEXCEPT {
+ const charT * y) BOOST_NOEXCEPT {
return x <= basic_string_view<charT, traits>(y);
}
template<typename charT, typename traits>
inline bool operator<=(const charT * x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
return basic_string_view<charT, traits>(x) <= y;
}
template<typename charT, typename traits, typename Allocator>
inline bool operator>=(basic_string_view<charT, traits> x,
- const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
+ const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
return x >= basic_string_view<charT, traits>(y);
}
template<typename charT, typename traits, typename Allocator>
inline bool operator>=(const std::basic_string<charT, traits, Allocator> & x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
return basic_string_view<charT, traits>(x) >= y;
}
template<typename charT, typename traits>
inline bool operator>=(basic_string_view<charT, traits> x,
- const charT * y) BOOST_NOEXCEPT {
+ const charT * y) BOOST_NOEXCEPT {
return x >= basic_string_view<charT, traits>(y);
}
template<typename charT, typename traits>
inline bool operator>=(const charT * x,
- basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
+ basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
return basic_string_view<charT, traits>(x) >= y;
}
namespace detail {
template<class charT, class traits>
- inline void insert_fill_chars(std::basic_ostream<charT, traits>& os, std::size_t n) {
+ inline void sv_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());
@@ -549,19 +570,19 @@ namespace boost {
}
template<class charT, class traits>
- void insert_aligned(std::basic_ostream<charT, traits>& os, const basic_string_view<charT,traits>& str) {
+ void sv_insert_aligned(std::basic_ostream<charT, traits>& os, const basic_string_view<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::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 +599,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;