mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 23:14:02 +00:00
Added another overload of to_string when default function template arguments are not supported.
The additional overload more closely emulates the official interface and allows to construct strings with custom allocators.
This commit is contained in:
parent
e5932ebb08
commit
4814d1ebfe
@ -164,6 +164,11 @@ namespace boost {
|
|||||||
std::basic_string<charT, traits> to_string() const {
|
std::basic_string<charT, traits> to_string() const {
|
||||||
return std::basic_string<charT, traits>(begin(), end());
|
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
|
#endif
|
||||||
|
|
||||||
size_type copy(charT* s, size_type n, size_type pos=0) const {
|
size_type copy(charT* s, size_type n, size_type pos=0) const {
|
||||||
@ -215,7 +220,7 @@ namespace boost {
|
|||||||
// Searches
|
// Searches
|
||||||
BOOST_CONSTEXPR bool starts_with(charT c) const BOOST_NOEXCEPT { // Boost extension
|
BOOST_CONSTEXPR bool starts_with(charT c) const BOOST_NOEXCEPT { // Boost extension
|
||||||
return !empty() && traits::eq(c, front());
|
return !empty() && traits::eq(c, front());
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_CONSTEXPR bool starts_with(basic_string_view x) const BOOST_NOEXCEPT { // Boost extension
|
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;
|
return len_ >= x.len_ && traits::compare(ptr_, x.ptr_, x.len_) == 0;
|
||||||
@ -226,7 +231,7 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BOOST_CONSTEXPR bool ends_with(basic_string_view x) const BOOST_NOEXCEPT { // Boost extension
|
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;
|
traits::compare(ptr_ + len_ - x.len_, x.ptr_, x.len_) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,7 +256,7 @@ namespace boost {
|
|||||||
BOOST_CXX14_CONSTEXPR size_type rfind(basic_string_view s, size_type pos = npos) const BOOST_NOEXCEPT {
|
BOOST_CXX14_CONSTEXPR size_type rfind(basic_string_view s, size_type pos = npos) const BOOST_NOEXCEPT {
|
||||||
if (len_ < s.len_)
|
if (len_ < s.len_)
|
||||||
return npos;
|
return npos;
|
||||||
if (pos > len_ - s.len_)
|
if (pos > len_ - s.len_)
|
||||||
pos = len_ - s.len_;
|
pos = len_ - s.len_;
|
||||||
if (s.len_ == 0u) // an empty string is always found
|
if (s.len_ == 0u) // an empty string is always found
|
||||||
return pos;
|
return pos;
|
||||||
@ -368,7 +373,7 @@ namespace boost {
|
|||||||
// Inequality
|
// Inequality
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator!=(basic_string_view<charT, traits> x,
|
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;
|
if ( x.size () != y.size ()) return true;
|
||||||
return x.compare(y) != 0;
|
return x.compare(y) != 0;
|
||||||
}
|
}
|
||||||
@ -376,173 +381,173 @@ namespace boost {
|
|||||||
// Less than
|
// Less than
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator<(basic_string_view<charT, traits> x,
|
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;
|
return x.compare(y) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greater than
|
// Greater than
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator>(basic_string_view<charT, traits> x,
|
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;
|
return x.compare(y) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Less than or equal to
|
// Less than or equal to
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator<=(basic_string_view<charT, traits> x,
|
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;
|
return x.compare(y) <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greater than or equal to
|
// Greater than or equal to
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator>=(basic_string_view<charT, traits> x,
|
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;
|
return x.compare(y) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// "sufficient additional overloads of comparison functions"
|
// "sufficient additional overloads of comparison functions"
|
||||||
template<typename charT, typename traits, typename Allocator>
|
template<typename charT, typename traits, typename Allocator>
|
||||||
inline bool operator==(basic_string_view<charT, traits> x,
|
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);
|
return x == basic_string_view<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits, typename Allocator>
|
template<typename charT, typename traits, typename Allocator>
|
||||||
inline bool operator==(const std::basic_string<charT, traits, Allocator> & x,
|
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;
|
return basic_string_view<charT, traits>(x) == y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator==(basic_string_view<charT, traits> x,
|
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);
|
return x == basic_string_view<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator==(const charT * x,
|
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;
|
return basic_string_view<charT, traits>(x) == y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits, typename Allocator>
|
template<typename charT, typename traits, typename Allocator>
|
||||||
inline bool operator!=(basic_string_view<charT, traits> x,
|
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);
|
return x != basic_string_view<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits, typename Allocator>
|
template<typename charT, typename traits, typename Allocator>
|
||||||
inline bool operator!=(const std::basic_string<charT, traits, Allocator> & x,
|
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;
|
return basic_string_view<charT, traits>(x) != y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator!=(basic_string_view<charT, traits> x,
|
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);
|
return x != basic_string_view<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator!=(const charT * x,
|
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;
|
return basic_string_view<charT, traits>(x) != y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits, typename Allocator>
|
template<typename charT, typename traits, typename Allocator>
|
||||||
inline bool operator<(basic_string_view<charT, traits> x,
|
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);
|
return x < basic_string_view<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits, typename Allocator>
|
template<typename charT, typename traits, typename Allocator>
|
||||||
inline bool operator<(const std::basic_string<charT, traits, Allocator> & x,
|
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;
|
return basic_string_view<charT, traits>(x) < y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator<(basic_string_view<charT, traits> x,
|
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);
|
return x < basic_string_view<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator<(const charT * x,
|
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;
|
return basic_string_view<charT, traits>(x) < y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits, typename Allocator>
|
template<typename charT, typename traits, typename Allocator>
|
||||||
inline bool operator>(basic_string_view<charT, traits> x,
|
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);
|
return x > basic_string_view<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits, typename Allocator>
|
template<typename charT, typename traits, typename Allocator>
|
||||||
inline bool operator>(const std::basic_string<charT, traits, Allocator> & x,
|
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;
|
return basic_string_view<charT, traits>(x) > y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator>(basic_string_view<charT, traits> x,
|
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);
|
return x > basic_string_view<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator>(const charT * x,
|
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;
|
return basic_string_view<charT, traits>(x) > y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits, typename Allocator>
|
template<typename charT, typename traits, typename Allocator>
|
||||||
inline bool operator<=(basic_string_view<charT, traits> x,
|
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);
|
return x <= basic_string_view<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits, typename Allocator>
|
template<typename charT, typename traits, typename Allocator>
|
||||||
inline bool operator<=(const std::basic_string<charT, traits, Allocator> & x,
|
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;
|
return basic_string_view<charT, traits>(x) <= y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator<=(basic_string_view<charT, traits> x,
|
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);
|
return x <= basic_string_view<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator<=(const charT * x,
|
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;
|
return basic_string_view<charT, traits>(x) <= y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits, typename Allocator>
|
template<typename charT, typename traits, typename Allocator>
|
||||||
inline bool operator>=(basic_string_view<charT, traits> x,
|
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);
|
return x >= basic_string_view<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits, typename Allocator>
|
template<typename charT, typename traits, typename Allocator>
|
||||||
inline bool operator>=(const std::basic_string<charT, traits, Allocator> & x,
|
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;
|
return basic_string_view<charT, traits>(x) >= y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator>=(basic_string_view<charT, traits> x,
|
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);
|
return x >= basic_string_view<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
inline bool operator>=(const charT * x,
|
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;
|
return basic_string_view<charT, traits>(x) >= y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user