*/
_GLIBCXX20_CONSTEXPR
int
- compare(size_type __pos, size_type __n, const basic_string& __str) const;
+ compare(size_type __pos, size_type __n, const basic_string& __str) const
+ {
+ _M_check(__pos, "basic_string::compare");
+ __n = _M_limit(__pos, __n);
+ const size_type __osize = __str.size();
+ const size_type __len = std::min(__n, __osize);
+ int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len);
+ if (!__r)
+ __r = _S_compare(__n, __osize);
+ return __r;
+ }
/**
* @brief Compare substring to a substring.
_GLIBCXX20_CONSTEXPR
int
compare(size_type __pos1, size_type __n1, const basic_string& __str,
- size_type __pos2, size_type __n2 = npos) const;
+ size_type __pos2, size_type __n2 = npos) const
+ {
+ _M_check(__pos1, "basic_string::compare");
+ __str._M_check(__pos2, "basic_string::compare");
+ __n1 = _M_limit(__pos1, __n1);
+ __n2 = __str._M_limit(__pos2, __n2);
+ const size_type __len = std::min(__n1, __n2);
+ int __r = traits_type::compare(_M_data() + __pos1,
+ __str.data() + __pos2, __len);
+ if (!__r)
+ __r = _S_compare(__n1, __n2);
+ return __r;
+ }
/**
* @brief Compare to a C string.
*/
_GLIBCXX20_CONSTEXPR
int
- compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT;
+ compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT
+ {
+ __glibcxx_requires_string(__s);
+ const size_type __size = this->size();
+ const size_type __osize = traits_type::length(__s);
+ const size_type __len = std::min(__size, __osize);
+ int __r = traits_type::compare(_M_data(), __s, __len);
+ if (!__r)
+ __r = _S_compare(__size, __osize);
+ return __r;
+ }
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 5 String::compare specification questionable
*/
_GLIBCXX20_CONSTEXPR
int
- compare(size_type __pos, size_type __n1, const _CharT* __s) const;
+ compare(size_type __pos, size_type __n1, const _CharT* __s) const
+ {
+ __glibcxx_requires_string(__s);
+ _M_check(__pos, "basic_string::compare");
+ __n1 = _M_limit(__pos, __n1);
+ const size_type __osize = traits_type::length(__s);
+ const size_type __len = std::min(__n1, __osize);
+ int __r = traits_type::compare(_M_data() + __pos, __s, __len);
+ if (!__r)
+ __r = _S_compare(__n1, __osize);
+ return __r;
+ }
/**
* @brief Compare substring against a character %array.
_GLIBCXX20_CONSTEXPR
int
compare(size_type __pos, size_type __n1, const _CharT* __s,
- size_type __n2) const;
+ size_type __n2) const
+ {
+ __glibcxx_requires_string_len(__s, __n2);
+ _M_check(__pos, "basic_string::compare");
+ __n1 = _M_limit(__pos, __n1);
+ const size_type __len = std::min(__n1, __n2);
+ int __r = traits_type::compare(_M_data() + __pos, __s, __len);
+ if (!__r)
+ __r = _S_compare(__n1, __n2);
+ return __r;
+ }
#if __cplusplus >= 202002L
constexpr bool
return npos;
}
- template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX_STRING_CONSTEXPR
- int
- basic_string<_CharT, _Traits, _Alloc>::
- compare(size_type __pos, size_type __n, const basic_string& __str) const
- {
- _M_check(__pos, "basic_string::compare");
- __n = _M_limit(__pos, __n);
- const size_type __osize = __str.size();
- const size_type __len = std::min(__n, __osize);
- int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len);
- if (!__r)
- __r = _S_compare(__n, __osize);
- return __r;
- }
-
- template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX_STRING_CONSTEXPR
- int
- basic_string<_CharT, _Traits, _Alloc>::
- compare(size_type __pos1, size_type __n1, const basic_string& __str,
- size_type __pos2, size_type __n2) const
- {
- _M_check(__pos1, "basic_string::compare");
- __str._M_check(__pos2, "basic_string::compare");
- __n1 = _M_limit(__pos1, __n1);
- __n2 = __str._M_limit(__pos2, __n2);
- const size_type __len = std::min(__n1, __n2);
- int __r = traits_type::compare(_M_data() + __pos1,
- __str.data() + __pos2, __len);
- if (!__r)
- __r = _S_compare(__n1, __n2);
- return __r;
- }
-
- template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX_STRING_CONSTEXPR
- int
- basic_string<_CharT, _Traits, _Alloc>::
- compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT
- {
- __glibcxx_requires_string(__s);
- const size_type __size = this->size();
- const size_type __osize = traits_type::length(__s);
- const size_type __len = std::min(__size, __osize);
- int __r = traits_type::compare(_M_data(), __s, __len);
- if (!__r)
- __r = _S_compare(__size, __osize);
- return __r;
- }
-
- template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX_STRING_CONSTEXPR
- int
- basic_string <_CharT, _Traits, _Alloc>::
- compare(size_type __pos, size_type __n1, const _CharT* __s) const
- {
- __glibcxx_requires_string(__s);
- _M_check(__pos, "basic_string::compare");
- __n1 = _M_limit(__pos, __n1);
- const size_type __osize = traits_type::length(__s);
- const size_type __len = std::min(__n1, __osize);
- int __r = traits_type::compare(_M_data() + __pos, __s, __len);
- if (!__r)
- __r = _S_compare(__n1, __osize);
- return __r;
- }
-
- template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX_STRING_CONSTEXPR
- int
- basic_string <_CharT, _Traits, _Alloc>::
- compare(size_type __pos, size_type __n1, const _CharT* __s,
- size_type __n2) const
- {
- __glibcxx_requires_string_len(__s, __n2);
- _M_check(__pos, "basic_string::compare");
- __n1 = _M_limit(__pos, __n1);
- const size_type __len = std::min(__n1, __n2);
- int __r = traits_type::compare(_M_data() + __pos, __s, __len);
- if (!__r)
- __r = _S_compare(__n1, __n2);
- return __r;
- }
-
#undef _GLIBCXX_STRING_CONSTEXPR
// 21.3.7.9 basic_string::getline and operators
* the shorter one is ordered first.
*/
int
- compare(size_type __pos, size_type __n, const basic_string& __str) const;
+ compare(size_type __pos, size_type __n, const basic_string& __str) const
+ {
+ _M_check(__pos, "basic_string::compare");
+ __n = _M_limit(__pos, __n);
+ const size_type __osize = __str.size();
+ const size_type __len = std::min(__n, __osize);
+ int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len);
+ if (!__r)
+ __r = _S_compare(__n, __osize);
+ return __r;
+ }
/**
* @brief Compare substring to a substring.
*/
int
compare(size_type __pos1, size_type __n1, const basic_string& __str,
- size_type __pos2, size_type __n2 = npos) const;
+ size_type __pos2, size_type __n2 = npos) const
+ {
+ _M_check(__pos1, "basic_string::compare");
+ __str._M_check(__pos2, "basic_string::compare");
+ __n1 = _M_limit(__pos1, __n1);
+ __n2 = __str._M_limit(__pos2, __n2);
+ const size_type __len = std::min(__n1, __n2);
+ int __r = traits_type::compare(_M_data() + __pos1,
+ __str.data() + __pos2, __len);
+ if (!__r)
+ __r = _S_compare(__n1, __n2);
+ return __r;
+ }
/**
* @brief Compare to a C string.
* ordered first.
*/
int
- compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT;
+ compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT
+ {
+ __glibcxx_requires_string(__s);
+ const size_type __size = this->size();
+ const size_type __osize = traits_type::length(__s);
+ const size_type __len = std::min(__size, __osize);
+ int __r = traits_type::compare(_M_data(), __s, __len);
+ if (!__r)
+ __r = _S_compare(__size, __osize);
+ return __r;
+ }
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 5 String::compare specification questionable
* one is ordered first.
*/
int
- compare(size_type __pos, size_type __n1, const _CharT* __s) const;
+ compare(size_type __pos, size_type __n1, const _CharT* __s) const
+ {
+ __glibcxx_requires_string(__s);
+ _M_check(__pos, "basic_string::compare");
+ __n1 = _M_limit(__pos, __n1);
+ const size_type __osize = traits_type::length(__s);
+ const size_type __len = std::min(__n1, __osize);
+ int __r = traits_type::compare(_M_data() + __pos, __s, __len);
+ if (!__r)
+ __r = _S_compare(__n1, __osize);
+ return __r;
+ }
/**
* @brief Compare substring against a character %array.
*/
int
compare(size_type __pos, size_type __n1, const _CharT* __s,
- size_type __n2) const;
+ size_type __n2) const
+ {
+ __glibcxx_requires_string_len(__s, __n2);
+ _M_check(__pos, "basic_string::compare");
+ __n1 = _M_limit(__pos, __n1);
+ const size_type __len = std::min(__n1, __n2);
+ int __r = traits_type::compare(_M_data() + __pos, __s, __len);
+ if (!__r)
+ __r = _S_compare(__n1, __n2);
+ return __r;
+ }
#if __cplusplus > 201703L
bool
--- /dev/null
+// { dg-options "-O1 -g0" }
+// { dg-do compile }
+// { dg-final { scan-assembler-not "12basic_stringIcSt11char_traitsIcESaIcEE7compare" } }
+
+#include <string>
+bool eq() { return std::string("blah") == "literal"; }
+bool lt() { return std::string("blah") < "literal"; }