* @brief Set value to string constructed from a string_view.
* @param __sv A string_view.
*/
- basic_string& operator=(__sv_type __sv)
+ basic_string&
+ operator=(__sv_type __sv)
{ return this->assign(__sv); }
/**
* @param __sv The string_view to be appended.
* @return Reference to this string.
*/
- basic_string& append(__sv_type __sv)
+ basic_string&
+ append(__sv_type __sv)
{ return this->append(__sv.data(), __sv.size()); }
+ template<typename _Tp, typename _Res>
+ using _If_sv = enable_if_t<
+ __and_<is_convertible<const _Tp&, __sv_type>,
+ __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
+ _Res>;
+
/**
* @brief Append a range of characters from a string_view.
* @param __sv The string_view to be appended from.
* @param __n The number of characters to append from the string_view.
* @return Reference to this string.
*/
- template <typename _Tp,
- enable_if_t<is_convertible_v<const _Tp&, __sv_type>,
- bool> = true>
- basic_string& append(const _Tp& __svt,
- size_type __pos, size_type __n = npos)
- {
- __sv_type __sv = __svt;
- return _M_append(__sv.data()
- + __sv._M_check(__pos, "basic_string::append"),
- __sv._M_limit(__pos, __n));
- }
+ template <typename _Tp>
+ _If_sv<_Tp, basic_string&>
+ append(const _Tp& __svt, size_type __pos, size_type __n = npos)
+ {
+ __sv_type __sv = __svt;
+ return _M_append(__sv.data()
+ + __sv._M_check(__pos, "basic_string::append"),
+ __sv._M_limit(__pos, __n));
+ }
#endif // C++17
/**
* @param __sv The source string_view.
* @return Reference to this string.
*/
- basic_string& assign(__sv_type __sv)
+ basic_string&
+ assign(__sv_type __sv)
{ return this->assign(__sv.data(), __sv.size()); }
/**
* @param __n The number of characters to assign.
* @return Reference to this string.
*/
- template <typename _Tp,
- enable_if_t<is_convertible_v<const _Tp&, __sv_type>,
- bool> = true>
- basic_string&
- assign(const _Tp& __svt,
- size_type __pos, size_type __n = npos)
- {
- __sv_type __sv = __svt;
- return _M_replace(size_type(0), this->size(), __sv.data()
- + __sv._M_check(__pos, "basic_string::assign"),
- __sv._M_limit(__pos, __n));
- }
+ template <typename _Tp>
+ _If_sv<_Tp, basic_string&>
+ assign(const _Tp& __svt, size_type __pos, size_type __n = npos)
+ {
+ __sv_type __sv = __svt;
+ return _M_replace(size_type(0), this->size(), __sv.data()
+ + __sv._M_check(__pos, "basic_string::assign"),
+ __sv._M_limit(__pos, __n));
+ }
#endif // C++17
#if __cplusplus >= 201103L
* @param __sv The string_view to insert.
* @return Reference to this string.
*/
- basic_string& insert(size_type __pos,
- __sv_type __sv)
+ basic_string&
+ insert(size_type __pos, __sv_type __sv)
{ return this->insert(__pos, __sv.data(), __sv.size()); }
/**
* @param __n The number of characters to insert.
* @return Reference to this string.
*/
- template <typename _Tp,
- enable_if_t<is_convertible_v<const _Tp&, __sv_type>,
- bool> = true>
- basic_string& insert(size_type __pos1, const _Tp& __svt,
- size_type __pos2, size_type __n = npos)
- {
- __sv_type __sv = __svt;
- return this->replace(__pos1, size_type(0), __sv.data()
- + __sv._M_check(__pos2, "basic_string::insert"),
- __sv._M_limit(__pos2, __n));
- }
+ template <typename _Tp>
+ _If_sv<_Tp, basic_string&>
+ insert(size_type __pos1, const _Tp& __svt,
+ size_type __pos2, size_type __n = npos)
+ {
+ __sv_type __sv = __svt;
+ return this->replace(__pos1, size_type(0), __sv.data()
+ + __sv._M_check(__pos2, "basic_string::insert"),
+ __sv._M_limit(__pos2, __n));
+ }
#endif // C++17
/**
* @param __sv The string_view to insert.
* @return Reference to this string.
*/
- basic_string& replace(size_type __pos, size_type __n,
- __sv_type __sv)
+ basic_string&
+ replace(size_type __pos, size_type __n, __sv_type __sv)
{ return this->replace(__pos, __n, __sv.data(), __sv.size()); }
/**
* @param __n2 The number of characters to insert.
* @return Reference to this string.
*/
- template <typename _Tp,
- enable_if_t<is_convertible_v<const _Tp&, __sv_type>,
- bool> = true>
- basic_string& replace(size_type __pos1, size_type __n1,
- const _Tp& __svt,
- size_type __pos2, size_type __n2 = npos)
- {
- __sv_type __sv = __svt;
- return this->replace(__pos1, __n1, __sv.data()
- + __sv._M_check(__pos2, "basic_string::replace"),
- __sv._M_limit(__pos2, __n2));
- }
+ template <typename _Tp>
+ _If_sv<_Tp, basic_string&>
+ replace(size_type __pos1, size_type __n1, const _Tp& __svt,
+ size_type __pos2, size_type __n2 = npos)
+ {
+ __sv_type __sv = __svt;
+ return this->replace(__pos1, __n1, __sv.data()
+ + __sv._M_check(__pos2, "basic_string::replace"),
+ __sv._M_limit(__pos2, __n2));
+ }
/**
* @brief Replace range of characters with string_view.
* @param __sv The string_view to insert from.
* @return Reference to this string.
*/
- basic_string& replace(const_iterator __i1, const_iterator __i2,
- __sv_type __sv)
+ basic_string&
+ replace(const_iterator __i1, const_iterator __i2, __sv_type __sv)
{ return this->replace(__i1 - begin(), __i2 - __i1, __sv); }
#endif // C++17
* @return Index of start of first occurrence.
*/
size_type
- find(__sv_type __sv,
- size_type __pos = 0) const noexcept
+ find(__sv_type __sv, size_type __pos = 0) const noexcept
{ return this->find(__sv.data(), __pos, __sv.size()); }
#endif // C++17
* @return Index of start of last occurrence.
*/
size_type
- rfind (__sv_type __sv,
- size_type __pos = npos) const noexcept
+ rfind(__sv_type __sv, size_type __pos = npos) const noexcept
{ return this->rfind(__sv.data(), __pos, __sv.size()); }
#endif // C++17
* @return Integer < 0, 0, or > 0.
*/
int
- compare(size_type __pos, size_type __n,
- __sv_type __sv) const
- {
- return __sv_type(*this).substr(__pos, __n).compare(__sv);
- }
+ compare(size_type __pos, size_type __n, __sv_type __sv) const
+ { return __sv_type(*this).substr(__pos, __n).compare(__sv); }
/**
* @brief Compare to a string_view.
* @param __n2 The number of characters to compare.
* @return Integer < 0, 0, or > 0.
*/
- template <typename _Tp,
- enable_if_t<is_convertible_v<const _Tp&, __sv_type>,
- bool> = true>
- int compare(size_type __pos1, size_type __n1,
- const _Tp& __svt,
- size_type __pos2, size_type __n2 = npos) const
- {
- __sv_type __sv = __svt;
- return __sv_type(*this)
- .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
- }
+ template <typename _Tp>
+ _If_sv<_Tp, int>
+ compare(size_type __pos1, size_type __n1, const _Tp& __svt,
+ size_type __pos2, size_type __n2 = npos) const
+ {
+ __sv_type __sv = __svt;
+ return __sv_type(*this)
+ .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
+ }
#endif // C++17
/**