PR libstdc++/70483 make std::string_view fully constexpr
PR libstdc++/70483 * include/bits/string_view.tcc (basic_string_view::find) (basic_string_view::rfind, basic_string_view::find_first_of) (basic_string_view::find_last_of, basic_string_view::find_first_not_of) (basic_string_view::find_last_not_of): Add constexpr specifier. * include/std/string_view (basic_string_view::operator=) (basic_string_view::rbegin, basic_string_view::rend) (basic_string_view::crbegin, basic_string_view::crend) (basic_string_view::remove_prefix, basic_string_view::remove_suffix) (basic_string_view::swap, basic_string_view::compare) (basic_string_view::find, basic_string_view::rfind) (basic_string_view::find_first_of, basic_string_view::find_last_of) (basic_string_view::find_first_not_of) (basic_string_view::find_last_not_of, basic_string_view::_M_check) (basic_string_view::_M_limit, operator==, operator!=, operator<) (operator>, operator<=, operator>=): Likewise. * testsuite/21_strings/basic_string_view/modifiers/remove_prefix/ char/1.cc: Repeat tests in constexpr context. * testsuite/21_strings/basic_string_view/modifiers/remove_prefix/ wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/modifiers/remove_suffix/ char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/modifiers/remove_suffix/ wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/find/char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/find/char/2.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/find/char/3.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/find/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/find/wchar_t/2.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/find/wchar_t/3.cc: Likewise. * testsuite/21_strings/basic_string_view/operators/char/2.cc: Likewise. * testsuite/21_strings/basic_string_view/operators/wchar_t/2.cc: Likewise. * testsuite/21_strings/basic_string_view/range_access/char/1.cc: Test cbegin, cend, rbegin, rend, crbegin and crend. * testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/compare/char/1.cc: Remove trailing whitespace. * testsuite/21_strings/basic_string_view/operations/compare/wchar_t/ 1.cc: Likewise. * testsuite/21_strings/basic_string_view/modifiers/swap/char/1.cc: New. * testsuite/21_strings/basic_string_view/modifiers/swap/wchar_t/1.cc: New. * testsuite/21_strings/basic_string_view/operations/compare/char/2.cc: New. * testsuite/21_strings/basic_string_view/operations/compare/wchar_t/ 2.cc: New. From-SVN: r251988
This commit is contained in:
parent
738ae6eeee
commit
c5ae1a27bd
|
@ -1,3 +1,62 @@
|
|||
2017-09-11 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
PR libstdc++/70483
|
||||
* include/bits/string_view.tcc (basic_string_view::find)
|
||||
(basic_string_view::rfind, basic_string_view::find_first_of)
|
||||
(basic_string_view::find_last_of, basic_string_view::find_first_not_of)
|
||||
(basic_string_view::find_last_not_of): Add constexpr specifier.
|
||||
* include/std/string_view (basic_string_view::operator=)
|
||||
(basic_string_view::rbegin, basic_string_view::rend)
|
||||
(basic_string_view::crbegin, basic_string_view::crend)
|
||||
(basic_string_view::remove_prefix, basic_string_view::remove_suffix)
|
||||
(basic_string_view::swap, basic_string_view::compare)
|
||||
(basic_string_view::find, basic_string_view::rfind)
|
||||
(basic_string_view::find_first_of, basic_string_view::find_last_of)
|
||||
(basic_string_view::find_first_not_of)
|
||||
(basic_string_view::find_last_not_of, basic_string_view::_M_check)
|
||||
(basic_string_view::_M_limit, operator==, operator!=, operator<)
|
||||
(operator>, operator<=, operator>=): Likewise.
|
||||
* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/
|
||||
char/1.cc: Repeat tests in constexpr context.
|
||||
* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/
|
||||
wchar_t/1.cc: Likewise.
|
||||
* testsuite/21_strings/basic_string_view/modifiers/remove_suffix/
|
||||
char/1.cc: Likewise.
|
||||
* testsuite/21_strings/basic_string_view/modifiers/remove_suffix/
|
||||
wchar_t/1.cc: Likewise.
|
||||
* testsuite/21_strings/basic_string_view/operations/find/char/1.cc:
|
||||
Likewise.
|
||||
* testsuite/21_strings/basic_string_view/operations/find/char/2.cc:
|
||||
Likewise.
|
||||
* testsuite/21_strings/basic_string_view/operations/find/char/3.cc:
|
||||
Likewise.
|
||||
* testsuite/21_strings/basic_string_view/operations/find/wchar_t/1.cc:
|
||||
Likewise.
|
||||
* testsuite/21_strings/basic_string_view/operations/find/wchar_t/2.cc:
|
||||
Likewise.
|
||||
* testsuite/21_strings/basic_string_view/operations/find/wchar_t/3.cc:
|
||||
Likewise.
|
||||
* testsuite/21_strings/basic_string_view/operators/char/2.cc:
|
||||
Likewise.
|
||||
* testsuite/21_strings/basic_string_view/operators/wchar_t/2.cc:
|
||||
Likewise.
|
||||
* testsuite/21_strings/basic_string_view/range_access/char/1.cc: Test
|
||||
cbegin, cend, rbegin, rend, crbegin and crend.
|
||||
* testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc:
|
||||
Likewise.
|
||||
* testsuite/21_strings/basic_string_view/operations/compare/char/1.cc:
|
||||
Remove trailing whitespace.
|
||||
* testsuite/21_strings/basic_string_view/operations/compare/wchar_t/
|
||||
1.cc: Likewise.
|
||||
* testsuite/21_strings/basic_string_view/modifiers/swap/char/1.cc:
|
||||
New.
|
||||
* testsuite/21_strings/basic_string_view/modifiers/swap/wchar_t/1.cc:
|
||||
New.
|
||||
* testsuite/21_strings/basic_string_view/operations/compare/char/2.cc:
|
||||
New.
|
||||
* testsuite/21_strings/basic_string_view/operations/compare/wchar_t/
|
||||
2.cc: New.
|
||||
|
||||
2017-09-11 Tim Shen <timshen@google.com>
|
||||
|
||||
PR libstdc++/71500
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
|
|||
_GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
typename basic_string_view<_CharT, _Traits>::size_type
|
||||
constexpr typename basic_string_view<_CharT, _Traits>::size_type
|
||||
basic_string_view<_CharT, _Traits>::
|
||||
find(const _CharT* __str, size_type __pos, size_type __n) const noexcept
|
||||
{
|
||||
|
@ -66,7 +66,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
}
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
typename basic_string_view<_CharT, _Traits>::size_type
|
||||
constexpr typename basic_string_view<_CharT, _Traits>::size_type
|
||||
basic_string_view<_CharT, _Traits>::
|
||||
find(_CharT __c, size_type __pos) const noexcept
|
||||
{
|
||||
|
@ -82,7 +82,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
}
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
typename basic_string_view<_CharT, _Traits>::size_type
|
||||
constexpr typename basic_string_view<_CharT, _Traits>::size_type
|
||||
basic_string_view<_CharT, _Traits>::
|
||||
rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept
|
||||
{
|
||||
|
@ -102,7 +102,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
}
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
typename basic_string_view<_CharT, _Traits>::size_type
|
||||
constexpr typename basic_string_view<_CharT, _Traits>::size_type
|
||||
basic_string_view<_CharT, _Traits>::
|
||||
rfind(_CharT __c, size_type __pos) const noexcept
|
||||
{
|
||||
|
@ -119,7 +119,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
}
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
typename basic_string_view<_CharT, _Traits>::size_type
|
||||
constexpr typename basic_string_view<_CharT, _Traits>::size_type
|
||||
basic_string_view<_CharT, _Traits>::
|
||||
find_first_of(const _CharT* __str, size_type __pos, size_type __n) const
|
||||
{
|
||||
|
@ -135,7 +135,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
}
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
typename basic_string_view<_CharT, _Traits>::size_type
|
||||
constexpr typename basic_string_view<_CharT, _Traits>::size_type
|
||||
basic_string_view<_CharT, _Traits>::
|
||||
find_last_of(const _CharT* __str, size_type __pos, size_type __n) const
|
||||
{
|
||||
|
@ -156,7 +156,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
}
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
typename basic_string_view<_CharT, _Traits>::size_type
|
||||
constexpr typename basic_string_view<_CharT, _Traits>::size_type
|
||||
basic_string_view<_CharT, _Traits>::
|
||||
find_first_not_of(const _CharT* __str, size_type __pos, size_type __n) const
|
||||
{
|
||||
|
@ -168,7 +168,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
}
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
typename basic_string_view<_CharT, _Traits>::size_type
|
||||
constexpr typename basic_string_view<_CharT, _Traits>::size_type
|
||||
basic_string_view<_CharT, _Traits>::
|
||||
find_first_not_of(_CharT __c, size_type __pos) const noexcept
|
||||
{
|
||||
|
@ -179,7 +179,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
}
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
typename basic_string_view<_CharT, _Traits>::size_type
|
||||
constexpr typename basic_string_view<_CharT, _Traits>::size_type
|
||||
basic_string_view<_CharT, _Traits>::
|
||||
find_last_not_of(const _CharT* __str, size_type __pos, size_type __n) const
|
||||
{
|
||||
|
@ -200,7 +200,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
}
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
typename basic_string_view<_CharT, _Traits>::size_type
|
||||
constexpr typename basic_string_view<_CharT, _Traits>::size_type
|
||||
basic_string_view<_CharT, _Traits>::
|
||||
find_last_not_of(_CharT __c, size_type __pos) const noexcept
|
||||
{
|
||||
|
|
|
@ -106,7 +106,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
_M_str{__str}
|
||||
{ }
|
||||
|
||||
basic_string_view&
|
||||
constexpr basic_string_view&
|
||||
operator=(const basic_string_view&) noexcept = default;
|
||||
|
||||
// [string.view.iterators], iterators
|
||||
|
@ -127,19 +127,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
cend() const noexcept
|
||||
{ return this->_M_str + this->_M_len; }
|
||||
|
||||
const_reverse_iterator
|
||||
constexpr const_reverse_iterator
|
||||
rbegin() const noexcept
|
||||
{ return const_reverse_iterator(this->end()); }
|
||||
|
||||
const_reverse_iterator
|
||||
constexpr const_reverse_iterator
|
||||
rend() const noexcept
|
||||
{ return const_reverse_iterator(this->begin()); }
|
||||
|
||||
const_reverse_iterator
|
||||
constexpr const_reverse_iterator
|
||||
crbegin() const noexcept
|
||||
{ return const_reverse_iterator(this->end()); }
|
||||
|
||||
const_reverse_iterator
|
||||
constexpr const_reverse_iterator
|
||||
crend() const noexcept
|
||||
{ return const_reverse_iterator(this->begin()); }
|
||||
|
||||
|
@ -208,7 +208,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
|
||||
// [string.view.modifiers], modifiers:
|
||||
|
||||
void
|
||||
constexpr void
|
||||
remove_prefix(size_type __n)
|
||||
{
|
||||
__glibcxx_assert(this->_M_len >= __n);
|
||||
|
@ -216,15 +216,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
this->_M_len -= __n;
|
||||
}
|
||||
|
||||
void
|
||||
constexpr void
|
||||
remove_suffix(size_type __n)
|
||||
{ this->_M_len -= __n; }
|
||||
|
||||
void
|
||||
constexpr void
|
||||
swap(basic_string_view& __sv) noexcept
|
||||
{
|
||||
std::swap(this->_M_len, __sv._M_len);
|
||||
std::swap(this->_M_str, __sv._M_str);
|
||||
auto __tmp = *this;
|
||||
*this = __sv;
|
||||
__sv = __tmp;
|
||||
}
|
||||
|
||||
|
||||
|
@ -261,7 +262,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
__pos, this->size()), basic_string_view{});
|
||||
}
|
||||
|
||||
int
|
||||
constexpr int
|
||||
compare(basic_string_view __str) const noexcept
|
||||
{
|
||||
int __ret = traits_type::compare(this->_M_str, __str._M_str,
|
||||
|
@ -271,24 +272,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
return __ret;
|
||||
}
|
||||
|
||||
int
|
||||
constexpr int
|
||||
compare(size_type __pos1, size_type __n1, basic_string_view __str) const
|
||||
{ return this->substr(__pos1, __n1).compare(__str); }
|
||||
|
||||
int
|
||||
constexpr int
|
||||
compare(size_type __pos1, size_type __n1,
|
||||
basic_string_view __str, size_type __pos2, size_type __n2) const
|
||||
{ return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2)); }
|
||||
|
||||
int
|
||||
constexpr int
|
||||
compare(const _CharT* __str) const noexcept
|
||||
{ return this->compare(basic_string_view{__str}); }
|
||||
|
||||
int
|
||||
constexpr int
|
||||
compare(size_type __pos1, size_type __n1, const _CharT* __str) const
|
||||
{ return this->substr(__pos1, __n1).compare(basic_string_view{__str}); }
|
||||
|
||||
int
|
||||
constexpr int
|
||||
compare(size_type __pos1, size_type __n1,
|
||||
const _CharT* __str, size_type __n2) const
|
||||
{
|
||||
|
@ -296,97 +297,97 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
.compare(basic_string_view(__str, __n2));
|
||||
}
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find(basic_string_view __str, size_type __pos = 0) const noexcept
|
||||
{ return this->find(__str._M_str, __pos, __str._M_len); }
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find(_CharT __c, size_type __pos=0) const noexcept;
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find(const _CharT* __str, size_type __pos=0) const noexcept
|
||||
{ return this->find(__str, __pos, traits_type::length(__str)); }
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
rfind(basic_string_view __str, size_type __pos = npos) const noexcept
|
||||
{ return this->rfind(__str._M_str, __pos, __str._M_len); }
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
rfind(_CharT __c, size_type __pos = npos) const noexcept;
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
rfind(const _CharT* __str, size_type __pos = npos) const noexcept
|
||||
{ return this->rfind(__str, __pos, traits_type::length(__str)); }
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find_first_of(basic_string_view __str, size_type __pos = 0) const noexcept
|
||||
{ return this->find_first_of(__str._M_str, __pos, __str._M_len); }
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find_first_of(_CharT __c, size_type __pos = 0) const noexcept
|
||||
{ return this->find(__c, __pos); }
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find_first_of(const _CharT* __str, size_type __pos, size_type __n) const;
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find_first_of(const _CharT* __str, size_type __pos = 0) const noexcept
|
||||
{ return this->find_first_of(__str, __pos, traits_type::length(__str)); }
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find_last_of(basic_string_view __str,
|
||||
size_type __pos = npos) const noexcept
|
||||
{ return this->find_last_of(__str._M_str, __pos, __str._M_len); }
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find_last_of(_CharT __c, size_type __pos=npos) const noexcept
|
||||
{ return this->rfind(__c, __pos); }
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find_last_of(const _CharT* __str, size_type __pos, size_type __n) const;
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find_last_of(const _CharT* __str, size_type __pos = npos) const noexcept
|
||||
{ return this->find_last_of(__str, __pos, traits_type::length(__str)); }
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find_first_not_of(basic_string_view __str,
|
||||
size_type __pos = 0) const noexcept
|
||||
{ return this->find_first_not_of(__str._M_str, __pos, __str._M_len); }
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find_first_not_of(_CharT __c, size_type __pos = 0) const noexcept;
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find_first_not_of(const _CharT* __str,
|
||||
size_type __pos, size_type __n) const;
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find_first_not_of(const _CharT* __str, size_type __pos = 0) const noexcept
|
||||
{
|
||||
return this->find_first_not_of(__str, __pos,
|
||||
traits_type::length(__str));
|
||||
}
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find_last_not_of(basic_string_view __str,
|
||||
size_type __pos = npos) const noexcept
|
||||
{ return this->find_last_not_of(__str._M_str, __pos, __str._M_len); }
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find_last_not_of(_CharT __c, size_type __pos = npos) const noexcept;
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find_last_not_of(const _CharT* __str,
|
||||
size_type __pos, size_type __n) const;
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
find_last_not_of(const _CharT* __str,
|
||||
size_type __pos = npos) const noexcept
|
||||
{
|
||||
|
@ -394,7 +395,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
traits_type::length(__str));
|
||||
}
|
||||
|
||||
size_type
|
||||
constexpr size_type
|
||||
_M_check(size_type __pos, const char* __s) const
|
||||
{
|
||||
if (__pos > this->size())
|
||||
|
@ -405,7 +406,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
}
|
||||
|
||||
// NB: _M_limit doesn't check for a bad __pos value.
|
||||
size_type
|
||||
constexpr size_type
|
||||
_M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT
|
||||
{
|
||||
const bool __testoff = __off < this->size() - __pos;
|
||||
|
@ -440,109 +441,109 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
}
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator==(basic_string_view<_CharT, _Traits> __x,
|
||||
basic_string_view<_CharT, _Traits> __y) noexcept
|
||||
{ return __x.size() == __y.size() && __x.compare(__y) == 0; }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator==(basic_string_view<_CharT, _Traits> __x,
|
||||
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
|
||||
{ return __x.size() == __y.size() && __x.compare(__y) == 0; }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator==(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
|
||||
basic_string_view<_CharT, _Traits> __y) noexcept
|
||||
{ return __x.size() == __y.size() && __x.compare(__y) == 0; }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator!=(basic_string_view<_CharT, _Traits> __x,
|
||||
basic_string_view<_CharT, _Traits> __y) noexcept
|
||||
{ return !(__x == __y); }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator!=(basic_string_view<_CharT, _Traits> __x,
|
||||
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
|
||||
{ return !(__x == __y); }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator!=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
|
||||
basic_string_view<_CharT, _Traits> __y) noexcept
|
||||
{ return !(__x == __y); }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator< (basic_string_view<_CharT, _Traits> __x,
|
||||
basic_string_view<_CharT, _Traits> __y) noexcept
|
||||
{ return __x.compare(__y) < 0; }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator< (basic_string_view<_CharT, _Traits> __x,
|
||||
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
|
||||
{ return __x.compare(__y) < 0; }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator< (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
|
||||
basic_string_view<_CharT, _Traits> __y) noexcept
|
||||
{ return __x.compare(__y) < 0; }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator> (basic_string_view<_CharT, _Traits> __x,
|
||||
basic_string_view<_CharT, _Traits> __y) noexcept
|
||||
{ return __x.compare(__y) > 0; }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator> (basic_string_view<_CharT, _Traits> __x,
|
||||
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
|
||||
{ return __x.compare(__y) > 0; }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator> (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
|
||||
basic_string_view<_CharT, _Traits> __y) noexcept
|
||||
{ return __x.compare(__y) > 0; }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator<=(basic_string_view<_CharT, _Traits> __x,
|
||||
basic_string_view<_CharT, _Traits> __y) noexcept
|
||||
{ return __x.compare(__y) <= 0; }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator<=(basic_string_view<_CharT, _Traits> __x,
|
||||
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
|
||||
{ return __x.compare(__y) <= 0; }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator<=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
|
||||
basic_string_view<_CharT, _Traits> __y) noexcept
|
||||
{ return __x.compare(__y) <= 0; }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator>=(basic_string_view<_CharT, _Traits> __x,
|
||||
basic_string_view<_CharT, _Traits> __y) noexcept
|
||||
{ return __x.compare(__y) >= 0; }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator>=(basic_string_view<_CharT, _Traits> __x,
|
||||
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
|
||||
{ return __x.compare(__y) >= 0; }
|
||||
|
||||
template<typename _CharT, typename _Traits>
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator>=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
|
||||
basic_string_view<_CharT, _Traits> __y) noexcept
|
||||
{ return __x.compare(__y) >= 0; }
|
||||
|
|
|
@ -33,10 +33,29 @@ test01()
|
|||
VERIFY( str0 == string_view{"pus mons"} );
|
||||
}
|
||||
|
||||
constexpr bool
|
||||
test02()
|
||||
{
|
||||
using std::string_view;
|
||||
|
||||
string_view str0{"olympus mons"};
|
||||
string_view::pointer p = str0.data();
|
||||
str0.remove_prefix(4);
|
||||
if ( str0.data() != p + 4)
|
||||
return false;
|
||||
if ( str0.length() != 8 )
|
||||
return false;
|
||||
if ( str0 != string_view{"pus mons"} )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
static_assert( test02() );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -33,10 +33,29 @@ test01()
|
|||
VERIFY( str0 == wstring_view{L"pus mons"} );
|
||||
}
|
||||
|
||||
constexpr bool
|
||||
test02()
|
||||
{
|
||||
using std::wstring_view;
|
||||
|
||||
wstring_view str0{L"olympus mons"};
|
||||
wstring_view::pointer p = str0.data();
|
||||
str0.remove_prefix(4);
|
||||
if ( str0.data() != p + 4)
|
||||
return false;
|
||||
if ( str0.length() != 8 )
|
||||
return false;
|
||||
if ( str0 != wstring_view{L"pus mons"} )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
static_assert( test02() );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -33,10 +33,29 @@ test01()
|
|||
VERIFY( str0 == string_view{"olympus mo"} );
|
||||
}
|
||||
|
||||
constexpr bool
|
||||
test02()
|
||||
{
|
||||
using std::string_view;
|
||||
|
||||
string_view str0{"olympus mons"};
|
||||
string_view::pointer p = str0.data();
|
||||
str0.remove_suffix(2);
|
||||
if ( str0.data() != p)
|
||||
return false;
|
||||
if ( str0.length() != 10 )
|
||||
return false;
|
||||
if ( str0 != string_view{"olympus mo"} )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
static_assert( test02() );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -33,10 +33,29 @@ test01()
|
|||
VERIFY( str0 == wstring_view{L"olympus mo"} );
|
||||
}
|
||||
|
||||
constexpr bool
|
||||
test02()
|
||||
{
|
||||
using std::wstring_view;
|
||||
|
||||
wstring_view str0{L"olympus mons"};
|
||||
wstring_view::pointer p = str0.data();
|
||||
str0.remove_suffix(2);
|
||||
if ( str0.data() != p)
|
||||
return false;
|
||||
if ( str0.length() != 10 )
|
||||
return false;
|
||||
if ( str0 != wstring_view{L"olympus mo"} )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
static_assert( test02() );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2017 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do compile { target c++1z } }
|
||||
|
||||
#include <string_view>
|
||||
|
||||
constexpr bool
|
||||
test01()
|
||||
{
|
||||
using std::string_view;
|
||||
|
||||
string_view s1{"last"};
|
||||
string_view s2{"first"};
|
||||
|
||||
s1.swap(s2);
|
||||
return s1 == "first" && s2 == "last";
|
||||
}
|
||||
|
||||
static_assert( test01() );
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2017 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do compile { target c++1z } }
|
||||
|
||||
#include <string_view>
|
||||
|
||||
constexpr bool
|
||||
test01()
|
||||
{
|
||||
using std::wstring_view;
|
||||
|
||||
wstring_view s1{L"last"};
|
||||
wstring_view s2{L"first"};
|
||||
|
||||
s1.swap(s2);
|
||||
return s1 == L"first" && s2 == L"last";
|
||||
}
|
||||
|
||||
static_assert( test01() );
|
|
@ -62,9 +62,8 @@ test_value(int result, want_value expected)
|
|||
VERIFY(pass);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
int
|
||||
test01()
|
||||
{
|
||||
using std::string_view;
|
||||
|
@ -74,7 +73,7 @@ test01()
|
|||
string_view str_2;
|
||||
|
||||
//sanity check
|
||||
test_value(strcmp("costa marbella", "costa rica"), lt);
|
||||
test_value(strcmp("costa marbella", "costa rica"), lt);
|
||||
test_value(strcmp("costa rica", "costa rica"), z);
|
||||
test_value(strcmp(str_1.data(), str_0.data()), lt);
|
||||
test_value(strcmp(str_0.data(), str_1.data()), gt);
|
||||
|
@ -100,8 +99,8 @@ test01()
|
|||
test_value(str_1.compare(0, 4, str_2), z);
|
||||
test_value(str_1.compare(0, 5, str_2), gt);
|
||||
|
||||
// int compare(size_type pos1, size_type n1, const basic_string_view& str,
|
||||
// size_type pos2, size_type n2) const;
|
||||
// int compare(size_type pos1, size_type n1, const basic_string_view& str,
|
||||
// size_type pos2, size_type n2) const;
|
||||
test_value(str_1.compare(0, 6, str_0, 0, 6), z);
|
||||
test_value(str_1.compare(0, 7, str_0, 0, 7), lt);
|
||||
test_value(str_0.compare(0, 7, str_1, 0, 7), gt);
|
||||
|
@ -111,21 +110,21 @@ test01()
|
|||
test_value(str_1.compare("costa rica"), lt);
|
||||
str_2 = str_0;
|
||||
test_value(str_2.compare("costa rica"), z);
|
||||
test_value(str_2.compare("cost"), gt);
|
||||
test_value(str_2.compare("costa ricans"), lt);
|
||||
test_value(str_2.compare("cost"), gt);
|
||||
test_value(str_2.compare("costa ricans"), lt);
|
||||
|
||||
// int compare(size_type pos, size_type n1, const charT* str,
|
||||
// size_type n2 = npos) const;
|
||||
test_value(str_1.compare(0, 6, "costa rica", 0, 6), z);
|
||||
test_value(str_1.compare(0, 7, "costa rica", 0, 7), lt);
|
||||
test_value(str_0.compare(0, 7, "costa marbella", 0, 7), gt);
|
||||
test_value(str_1.compare(0, 6, "costa rica", 0, 6), z);
|
||||
test_value(str_1.compare(0, 7, "costa rica", 0, 7), lt);
|
||||
test_value(str_0.compare(0, 7, "costa marbella", 0, 7), gt);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main()
|
||||
int
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (C) 2017 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do compile { target c++1z } }
|
||||
|
||||
#include <string_view>
|
||||
|
||||
constexpr char c1[] = "one";
|
||||
constexpr char c2[] = "two";
|
||||
|
||||
constexpr std::string_view s1{c1};
|
||||
constexpr std::string_view s2{c2};
|
||||
|
||||
constexpr int n1 = s1.compare(s1);
|
||||
constexpr int n2 = s1.compare(s2);
|
|
@ -0,0 +1,89 @@
|
|||
// Copyright (C) 2017 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do compile { target c++1z } }
|
||||
|
||||
#include <string_view>
|
||||
|
||||
struct constexpr_char_traits : std::char_traits<char>
|
||||
{
|
||||
static constexpr size_t
|
||||
length(const char* val)
|
||||
{
|
||||
size_t res = 0;
|
||||
for (; val[res] != '\0'; ++res)
|
||||
;
|
||||
return res;
|
||||
}
|
||||
|
||||
static constexpr int
|
||||
compare(const char* lhs, const char* rhs, std::size_t count)
|
||||
{
|
||||
for (size_t pos = 0; pos < count; ++pos)
|
||||
{
|
||||
if (lhs[pos] != rhs[pos])
|
||||
return lhs[pos] - rhs[pos];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
using string_view = std::basic_string_view<char, constexpr_char_traits>;
|
||||
|
||||
constexpr
|
||||
string_view get()
|
||||
{
|
||||
string_view res = "x::";
|
||||
string_view start_pattern = "x";
|
||||
res = res.substr(res.find(start_pattern) + start_pattern.size());
|
||||
res = res.substr(0, res.find_first_of(";]"));
|
||||
res = res.substr(res.rfind("::"));
|
||||
return res;
|
||||
}
|
||||
|
||||
static_assert( get() == get() );
|
||||
|
||||
using std::u16string_view;
|
||||
|
||||
constexpr
|
||||
u16string_view get16()
|
||||
{
|
||||
u16string_view res = u"x::";
|
||||
u16string_view start_pattern = u"x";
|
||||
res = res.substr(res.find(start_pattern) + start_pattern.size());
|
||||
res = res.substr(0, res.find_first_of(u";]"));
|
||||
res = res.substr(res.rfind(u"::"));
|
||||
return res;
|
||||
}
|
||||
|
||||
static_assert( get16() == get16() );
|
||||
|
||||
using std::u32string_view;
|
||||
|
||||
constexpr
|
||||
u32string_view get32()
|
||||
{
|
||||
u32string_view res = U"x::";
|
||||
u32string_view start_pattern = U"x";
|
||||
res = res.substr(res.find(start_pattern) + start_pattern.size());
|
||||
res = res.substr(0, res.find_first_of(U";]"));
|
||||
res = res.substr(res.rfind(U"::"));
|
||||
return res;
|
||||
}
|
||||
|
||||
static_assert( get32() == get32() );
|
|
@ -62,9 +62,9 @@ test_value(int result, want_value expected)
|
|||
VERIFY(pass);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
|
||||
int
|
||||
test01()
|
||||
{
|
||||
using std::wstring_view;
|
||||
|
@ -74,7 +74,7 @@ test01()
|
|||
wstring_view str_2;
|
||||
|
||||
//sanity check
|
||||
test_value(wcscmp(L"costa marbella", L"costa rica"), lt);
|
||||
test_value(wcscmp(L"costa marbella", L"costa rica"), lt);
|
||||
test_value(wcscmp(L"costa rica", L"costa rica"), z);
|
||||
test_value(wcscmp(str_1.data(), str_0.data()), lt);
|
||||
test_value(wcscmp(str_0.data(), str_1.data()), gt);
|
||||
|
@ -100,8 +100,8 @@ test01()
|
|||
test_value(str_1.compare(0, 4, str_2), z);
|
||||
test_value(str_1.compare(0, 5, str_2), gt);
|
||||
|
||||
// int compare(size_type pos1, size_type n1, const basic_string_view& str,
|
||||
// size_type pos2, size_type n2) const;
|
||||
// int compare(size_type pos1, size_type n1, const basic_string_view& str,
|
||||
// size_type pos2, size_type n2) const;
|
||||
test_value(str_1.compare(0, 6, str_0, 0, 6), z);
|
||||
test_value(str_1.compare(0, 7, str_0, 0, 7), lt);
|
||||
test_value(str_0.compare(0, 7, str_1, 0, 7), gt);
|
||||
|
@ -111,21 +111,21 @@ test01()
|
|||
test_value(str_1.compare(L"costa rica"), lt);
|
||||
str_2 = str_0;
|
||||
test_value(str_2.compare(L"costa rica"), z);
|
||||
test_value(str_2.compare(L"cost"), gt);
|
||||
test_value(str_2.compare(L"costa ricans"), lt);
|
||||
test_value(str_2.compare(L"cost"), gt);
|
||||
test_value(str_2.compare(L"costa ricans"), lt);
|
||||
|
||||
// int compare(size_type pos, size_type n1, const charT* str,
|
||||
// size_type n2 = npos) const;
|
||||
test_value(str_1.compare(0, 6, L"costa rica", 0, 6), z);
|
||||
test_value(str_1.compare(0, 7, L"costa rica", 0, 7), lt);
|
||||
test_value(str_0.compare(0, 7, L"costa marbella", 0, 7), gt);
|
||||
test_value(str_1.compare(0, 6, L"costa rica", 0, 6), z);
|
||||
test_value(str_1.compare(0, 7, L"costa rica", 0, 7), lt);
|
||||
test_value(str_0.compare(0, 7, L"costa marbella", 0, 7), gt);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main()
|
||||
int
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (C) 2017 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do compile { target c++1z } }
|
||||
|
||||
#include <string_view>
|
||||
|
||||
constexpr wchar_t c1[] = L"one";
|
||||
constexpr wchar_t c2[] = L"two";
|
||||
|
||||
constexpr std::wstring_view s1{c1};
|
||||
constexpr std::wstring_view s2{c2};
|
||||
|
||||
constexpr int n1 = s1.compare(s1);
|
||||
constexpr int n2 = s1.compare(s2);
|
|
@ -61,10 +61,10 @@ test01()
|
|||
csz01 = str01.find(str04, 5);
|
||||
VERIFY( csz01 == 5 );
|
||||
csz01 = str01.find(str04, str01.size());
|
||||
VERIFY( csz01 == str01.size() );
|
||||
VERIFY( csz01 == str01.size() );
|
||||
csz01 = str01.find(str04, str01.size()+1);
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
// size_type find(const char* s, size_type pos, size_type n) const;
|
||||
csz01 = str01.find(str_lit01, 0, 3);
|
||||
VERIFY( csz01 == 0 );
|
||||
|
@ -85,10 +85,80 @@ test01()
|
|||
VERIFY( csz01 == npos );
|
||||
}
|
||||
|
||||
constexpr bool
|
||||
test02()
|
||||
{
|
||||
typedef std::string_view::size_type csize_type;
|
||||
typedef std::string_view::const_reference cref;
|
||||
typedef std::string_view::reference ref;
|
||||
csize_type npos = std::string_view::npos;
|
||||
csize_type csz01 = 0, csz02 = 0;
|
||||
|
||||
const char str_lit01[] = "mave";
|
||||
const std::string_view str01("mavericks, santa cruz");
|
||||
std::string_view str02(str_lit01);
|
||||
std::string_view str03("s, s");
|
||||
std::string_view str04;
|
||||
|
||||
#undef VERIFY
|
||||
#define VERIFY(x) if(!(x)) return false
|
||||
|
||||
// size_type find(const string_view&, size_type pos = 0) const;
|
||||
csz01 = str01.find(str01);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find(str01, 4);
|
||||
VERIFY( csz01 == npos );
|
||||
csz01 = str01.find(str02, 0);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find(str02, 3);
|
||||
VERIFY( csz01 == npos );
|
||||
csz01 = str01.find(str03, 0);
|
||||
VERIFY( csz01 == 8 );
|
||||
csz01 = str01.find(str03, 3);
|
||||
VERIFY( csz01 == 8 );
|
||||
csz01 = str01.find(str03, 12);
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
// An empty string_view consists of no characters
|
||||
// therefore it should be found at every point in a string_view,
|
||||
// except beyond the end
|
||||
csz01 = str01.find(str04, 0);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find(str04, 5);
|
||||
VERIFY( csz01 == 5 );
|
||||
csz01 = str01.find(str04, str01.size());
|
||||
VERIFY( csz01 == str01.size() );
|
||||
csz01 = str01.find(str04, str01.size()+1);
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
// size_type find(const char* s, size_type pos, size_type n) const;
|
||||
csz01 = str01.find(str_lit01, 0, 3);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find(str_lit01, 3, 0);
|
||||
VERIFY( csz01 == 3 );
|
||||
|
||||
// size_type find(const char* s, size_type pos = 0) const;
|
||||
csz01 = str01.find(str_lit01);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find(str_lit01, 3);
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
// size_type find(char c, size_type pos = 0) const;
|
||||
csz01 = str01.find('z');
|
||||
csz02 = str01.size() - 1;
|
||||
VERIFY( csz01 == csz02 );
|
||||
csz01 = str01.find('/');
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
{
|
||||
test01();
|
||||
static_assert( test02() );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -59,13 +59,13 @@ test02()
|
|||
// An empty string_view consists of no characters
|
||||
// therefore it should be found at every point in a string_view,
|
||||
// except beyond the end
|
||||
// However, str1.find_first_of(str2,pos) finds the first character in
|
||||
// However, str1.find_first_of(str2,pos) finds the first character in
|
||||
// str1 (starting at pos) that exists in str2, which is none for empty str2
|
||||
csz01 = str01.find_first_of(str04, 0);
|
||||
VERIFY( csz01 == npos );
|
||||
csz01 = str01.find_first_of(str04, 5);
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
|
||||
// size_type find_first_of(const char* s, size_type pos, size_type n) const;
|
||||
csz01 = str01.find_first_of(str_lit01, 0, 3);
|
||||
VERIFY( csz01 == 0 );
|
||||
|
@ -84,10 +84,78 @@ test02()
|
|||
VERIFY( csz01 == csz02 );
|
||||
}
|
||||
|
||||
constexpr bool
|
||||
test03()
|
||||
{
|
||||
typedef std::string_view::size_type csize_type;
|
||||
csize_type npos = std::string_view::npos;
|
||||
csize_type csz01 = 0, csz02 = 0;
|
||||
|
||||
const char str_lit01[] = "mave";
|
||||
const std::string_view str01("mavericks, santa cruz");
|
||||
std::string_view str02(str_lit01);
|
||||
std::string_view str03("s, s");
|
||||
std::string_view str04;
|
||||
|
||||
#undef VERIFY
|
||||
#define VERIFY(x) if(!(x)) return false
|
||||
|
||||
// size_type find_first_of(const string_view&, size_type pos = 0) const;
|
||||
std::string_view str05("xena rulez");
|
||||
csz01 = str01.find_first_of(str01);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find_first_of(str01, 4);
|
||||
VERIFY( csz01 == 4 );
|
||||
csz01 = str01.find_first_of(str02, 0);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find_first_of(str02, 3);
|
||||
VERIFY( csz01 == 3 );
|
||||
csz01 = str01.find_first_of(str03, 0);
|
||||
VERIFY( csz01 == 8 );
|
||||
csz01 = str01.find_first_of(str03, 3);
|
||||
VERIFY( csz01 == 8 );
|
||||
csz01 = str01.find_first_of(str03, 12);
|
||||
VERIFY( csz01 == 16 );
|
||||
csz01 = str01.find_first_of(str05, 0);
|
||||
VERIFY( csz01 == 1 );
|
||||
csz01 = str01.find_first_of(str05, 4);
|
||||
VERIFY( csz01 == 4 );
|
||||
|
||||
// An empty string_view consists of no characters
|
||||
// therefore it should be found at every point in a string_view,
|
||||
// except beyond the end
|
||||
// However, str1.find_first_of(str2,pos) finds the first character in
|
||||
// str1 (starting at pos) that exists in str2, which is none for empty str2
|
||||
csz01 = str01.find_first_of(str04, 0);
|
||||
VERIFY( csz01 == npos );
|
||||
csz01 = str01.find_first_of(str04, 5);
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
// size_type find_first_of(const char* s, size_type pos, size_type n) const;
|
||||
csz01 = str01.find_first_of(str_lit01, 0, 3);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find_first_of(str_lit01, 3, 0);
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
// size_type find_first_of(const char* s, size_type pos = 0) const;
|
||||
csz01 = str01.find_first_of(str_lit01);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find_first_of(str_lit01, 3);
|
||||
VERIFY( csz01 == 3 );
|
||||
|
||||
// size_type find_first_of(char c, size_type pos = 0) const;
|
||||
csz01 = str01.find_first_of('z');
|
||||
csz02 = str01.size() - 1;
|
||||
VERIFY( csz01 == csz02 );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
{
|
||||
test02();
|
||||
static_assert( test03() );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -84,10 +84,78 @@ test03()
|
|||
VERIFY( csz01 == npos );
|
||||
}
|
||||
|
||||
constexpr bool
|
||||
test04()
|
||||
{
|
||||
typedef std::string_view::size_type csize_type;
|
||||
csize_type npos = std::string_view::npos;
|
||||
csize_type csz01 = 0;
|
||||
|
||||
const std::string_view str01("Bob Rock, per me");
|
||||
const char str_lit01[] = "Bob Rock";
|
||||
std::string_view str02("ovvero Trivi");
|
||||
std::string_view str03(str_lit01);
|
||||
std::string_view str04;
|
||||
|
||||
#undef VERIFY
|
||||
#define VERIFY(x) if(!(x)) return false
|
||||
|
||||
// size_type find_first_not_of(const string_view&, size_type pos = 0) const;
|
||||
csz01 = str01.find_first_not_of(str01);
|
||||
VERIFY( csz01 == npos );
|
||||
csz01 = str01.find_first_not_of(str02, 0);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find_first_not_of(str02, 10);
|
||||
VERIFY( csz01 == 10 );
|
||||
csz01 = str01.find_first_not_of(str02, 12);
|
||||
VERIFY( csz01 == 14 );
|
||||
csz01 = str01.find_first_not_of(str03, 0);
|
||||
VERIFY( csz01 == 8 );
|
||||
csz01 = str01.find_first_not_of(str03, 15);
|
||||
VERIFY( csz01 == 15 );
|
||||
csz01 = str01.find_first_not_of(str03, 16);
|
||||
VERIFY( csz01 == npos );
|
||||
csz01 = str01.find_first_not_of(str04, 0);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find_first_not_of(str04, 12);
|
||||
VERIFY( csz01 == 12 );
|
||||
csz01 = str03.find_first_not_of(str01, 0);
|
||||
VERIFY( csz01 == npos );
|
||||
csz01 = str04.find_first_not_of(str02, 0);
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
// size_type find_first_not_of(const char* s, size_type pos, size_type n) const;
|
||||
csz01 = str01.find_first_not_of(str_lit01, 0, 0);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find_first_not_of(str_lit01, 0, 8);
|
||||
VERIFY( csz01 == 8 );
|
||||
csz01 = str01.find_first_not_of(str_lit01, 10, 0);
|
||||
VERIFY( csz01 == 10 );
|
||||
|
||||
// size_type find_first_not_of(const char* s, size_type pos = 0) const;
|
||||
csz01 = str01.find_first_not_of(str_lit01);
|
||||
VERIFY( csz01 == 8 );
|
||||
csz01 = str02.find_first_not_of(str_lit01, 2);
|
||||
VERIFY( csz01 == 2 );
|
||||
|
||||
// size_type find_first_not_of(char c, size_type pos = 0) const;
|
||||
csz01 = str01.find_first_not_of('B');
|
||||
VERIFY( csz01 == 1 );
|
||||
csz01 = str01.find_first_not_of('o', 1);
|
||||
VERIFY( csz01 == 2 );
|
||||
csz01 = str02.find_first_not_of('z');
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str04.find_first_not_of('S');
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
{
|
||||
test03();
|
||||
static_assert( test04() );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -61,10 +61,10 @@ test01()
|
|||
csz01 = str01.find(str04, 5);
|
||||
VERIFY( csz01 == 5 );
|
||||
csz01 = str01.find(str04, str01.size());
|
||||
VERIFY( csz01 == str01.size() );
|
||||
VERIFY( csz01 == str01.size() );
|
||||
csz01 = str01.find(str04, str01.size()+1);
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
// size_type find(const wchar_t* s, size_type pos, size_type n) const;
|
||||
csz01 = str01.find(str_lit01, 0, 3);
|
||||
VERIFY( csz01 == 0 );
|
||||
|
@ -85,10 +85,79 @@ test01()
|
|||
VERIFY( csz01 == npos );
|
||||
}
|
||||
|
||||
constexpr bool
|
||||
test02()
|
||||
{
|
||||
typedef std::wstring_view::size_type csize_type;
|
||||
typedef std::wstring_view::const_reference cref;
|
||||
typedef std::wstring_view::reference ref;
|
||||
csize_type npos = std::wstring_view::npos;
|
||||
csize_type csz01 = 0, csz02 = 0;
|
||||
|
||||
const wchar_t str_lit01[] = L"mave";
|
||||
const std::wstring_view str01(L"mavericks, santa cruz");
|
||||
std::wstring_view str02(str_lit01);
|
||||
std::wstring_view str03(L"s, s");
|
||||
std::wstring_view str04;
|
||||
|
||||
#undef VERIFY
|
||||
#define VERIFY(x) if(!(x)) return false
|
||||
|
||||
// size_type find(const wstring_view&, size_type pos = 0) const;
|
||||
csz01 = str01.find(str01);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find(str01, 4);
|
||||
VERIFY( csz01 == npos );
|
||||
csz01 = str01.find(str02, 0);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find(str02, 3);
|
||||
VERIFY( csz01 == npos );
|
||||
csz01 = str01.find(str03, 0);
|
||||
VERIFY( csz01 == 8 );
|
||||
csz01 = str01.find(str03, 3);
|
||||
VERIFY( csz01 == 8 );
|
||||
csz01 = str01.find(str03, 12);
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
// An empty string_view consists of no characters
|
||||
// therefore it should be found at every point in a string_view,
|
||||
// except beyond the end
|
||||
csz01 = str01.find(str04, 0);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find(str04, 5);
|
||||
VERIFY( csz01 == 5 );
|
||||
csz01 = str01.find(str04, str01.size());
|
||||
VERIFY( csz01 == str01.size() );
|
||||
csz01 = str01.find(str04, str01.size()+1);
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
// size_type find(const wchar_t* s, size_type pos, size_type n) const;
|
||||
csz01 = str01.find(str_lit01, 0, 3);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find(str_lit01, 3, 0);
|
||||
VERIFY( csz01 == 3 );
|
||||
|
||||
// size_type find(const wchar_t* s, size_type pos = 0) const;
|
||||
csz01 = str01.find(str_lit01);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find(str_lit01, 3);
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
// size_type find(wchar_t c, size_type pos = 0) const;
|
||||
csz01 = str01.find(L'z');
|
||||
csz02 = str01.size() - 1;
|
||||
VERIFY( csz01 == csz02 );
|
||||
csz01 = str01.find(L'/');
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
{
|
||||
test01();
|
||||
static_assert( test02() );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -59,13 +59,13 @@ test02()
|
|||
// An empty string_view consists of no characters
|
||||
// therefore it should be found at every point in a string_view,
|
||||
// except beyond the end
|
||||
// However, str1.find_first_of(str2,pos) finds the first character in
|
||||
// However, str1.find_first_of(str2,pos) finds the first character in
|
||||
// str1 (starting at pos) that exists in str2, which is none for empty str2
|
||||
csz01 = str01.find_first_of(str04, 0);
|
||||
VERIFY( csz01 == npos );
|
||||
csz01 = str01.find_first_of(str04, 5);
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
|
||||
// size_type find_first_of(const wchar_t* s, size_type pos, size_type n) const;
|
||||
csz01 = str01.find_first_of(str_lit01, 0, 3);
|
||||
VERIFY( csz01 == 0 );
|
||||
|
@ -84,10 +84,78 @@ test02()
|
|||
VERIFY( csz01 == csz02 );
|
||||
}
|
||||
|
||||
constexpr bool
|
||||
test04()
|
||||
{
|
||||
typedef std::wstring_view::size_type csize_type;
|
||||
csize_type npos = std::wstring_view::npos;
|
||||
csize_type csz01 = 0, csz02 = 0;
|
||||
|
||||
const wchar_t str_lit01[] = L"mave";
|
||||
const std::wstring_view str01(L"mavericks, santa cruz");
|
||||
std::wstring_view str02(str_lit01);
|
||||
std::wstring_view str03(L"s, s");
|
||||
std::wstring_view str04;
|
||||
|
||||
#undef VERIFY
|
||||
#define VERIFY(x) if(!(x)) return false
|
||||
|
||||
// size_type find_first_of(const wstring_view&, size_type pos = 0) const;
|
||||
std::wstring_view str05(L"xena rulez");
|
||||
csz01 = str01.find_first_of(str01);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find_first_of(str01, 4);
|
||||
VERIFY( csz01 == 4 );
|
||||
csz01 = str01.find_first_of(str02, 0);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find_first_of(str02, 3);
|
||||
VERIFY( csz01 == 3 );
|
||||
csz01 = str01.find_first_of(str03, 0);
|
||||
VERIFY( csz01 == 8 );
|
||||
csz01 = str01.find_first_of(str03, 3);
|
||||
VERIFY( csz01 == 8 );
|
||||
csz01 = str01.find_first_of(str03, 12);
|
||||
VERIFY( csz01 == 16 );
|
||||
csz01 = str01.find_first_of(str05, 0);
|
||||
VERIFY( csz01 == 1 );
|
||||
csz01 = str01.find_first_of(str05, 4);
|
||||
VERIFY( csz01 == 4 );
|
||||
|
||||
// An empty string_view consists of no characters
|
||||
// therefore it should be found at every point in a string_view,
|
||||
// except beyond the end
|
||||
// However, str1.find_first_of(str2,pos) finds the first character in
|
||||
// str1 (starting at pos) that exists in str2, which is none for empty str2
|
||||
csz01 = str01.find_first_of(str04, 0);
|
||||
VERIFY( csz01 == npos );
|
||||
csz01 = str01.find_first_of(str04, 5);
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
// size_type find_first_of(const wchar_t* s, size_type pos, size_type n) const;
|
||||
csz01 = str01.find_first_of(str_lit01, 0, 3);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find_first_of(str_lit01, 3, 0);
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
// size_type find_first_of(const wchar_t* s, size_type pos = 0) const;
|
||||
csz01 = str01.find_first_of(str_lit01);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find_first_of(str_lit01, 3);
|
||||
VERIFY( csz01 == 3 );
|
||||
|
||||
// size_type find_first_of(wchar_t c, size_type pos = 0) const;
|
||||
csz01 = str01.find_first_of(L'z');
|
||||
csz02 = str01.size() - 1;
|
||||
VERIFY( csz01 == csz02 );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
{
|
||||
test02();
|
||||
static_assert( test04() );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -84,10 +84,78 @@ test03()
|
|||
VERIFY( csz01 == npos );
|
||||
}
|
||||
|
||||
constexpr bool
|
||||
test04()
|
||||
{
|
||||
typedef std::wstring_view::size_type csize_type;
|
||||
csize_type npos = std::wstring_view::npos;
|
||||
csize_type csz01 = 0;
|
||||
|
||||
const std::wstring_view str01(L"Bob Rock, per me");
|
||||
const wchar_t str_lit01[] = L"Bob Rock";
|
||||
std::wstring_view str02(L"ovvero Trivi");
|
||||
std::wstring_view str03(str_lit01);
|
||||
std::wstring_view str04;
|
||||
|
||||
#undef VERIFY
|
||||
#define VERIFY(x) if(!(x)) return false
|
||||
|
||||
// size_type find_first_not_of(const string_view&, size_type pos = 0) const;
|
||||
csz01 = str01.find_first_not_of(str01);
|
||||
VERIFY( csz01 == npos );
|
||||
csz01 = str01.find_first_not_of(str02, 0);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find_first_not_of(str02, 10);
|
||||
VERIFY( csz01 == 10 );
|
||||
csz01 = str01.find_first_not_of(str02, 12);
|
||||
VERIFY( csz01 == 14 );
|
||||
csz01 = str01.find_first_not_of(str03, 0);
|
||||
VERIFY( csz01 == 8 );
|
||||
csz01 = str01.find_first_not_of(str03, 15);
|
||||
VERIFY( csz01 == 15 );
|
||||
csz01 = str01.find_first_not_of(str03, 16);
|
||||
VERIFY( csz01 == npos );
|
||||
csz01 = str01.find_first_not_of(str04, 0);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find_first_not_of(str04, 12);
|
||||
VERIFY( csz01 == 12 );
|
||||
csz01 = str03.find_first_not_of(str01, 0);
|
||||
VERIFY( csz01 == npos );
|
||||
csz01 = str04.find_first_not_of(str02, 0);
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
// size_type find_first_not_of(const char* s, size_type pos, size_type n) const;
|
||||
csz01 = str01.find_first_not_of(str_lit01, 0, 0);
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str01.find_first_not_of(str_lit01, 0, 8);
|
||||
VERIFY( csz01 == 8 );
|
||||
csz01 = str01.find_first_not_of(str_lit01, 10, 0);
|
||||
VERIFY( csz01 == 10 );
|
||||
|
||||
// size_type find_first_not_of(const char* s, size_type pos = 0) const;
|
||||
csz01 = str01.find_first_not_of(str_lit01);
|
||||
VERIFY( csz01 == 8 );
|
||||
csz01 = str02.find_first_not_of(str_lit01, 2);
|
||||
VERIFY( csz01 == 2 );
|
||||
|
||||
// size_type find_first_not_of(char c, size_type pos = 0) const;
|
||||
csz01 = str01.find_first_not_of(L'B');
|
||||
VERIFY( csz01 == 1 );
|
||||
csz01 = str01.find_first_not_of(L'o', 1);
|
||||
VERIFY( csz01 == 2 );
|
||||
csz01 = str02.find_first_not_of(L'z');
|
||||
VERIFY( csz01 == 0 );
|
||||
csz01 = str04.find_first_not_of(L'S');
|
||||
VERIFY( csz01 == npos );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
{
|
||||
test03();
|
||||
static_assert( test04() );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ template<class charT, class traits, class Allocator>
|
|||
#include <string_view>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
int
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::string_view str_0("costa rica");
|
||||
|
@ -120,7 +120,7 @@ test01()
|
|||
std::string_view str_2("cost");
|
||||
std::string_view str_3("costa ricans");
|
||||
std::string_view str_4;
|
||||
|
||||
|
||||
str_4 = str_0;
|
||||
//comparisons between string objects
|
||||
VERIFY( !(str_0 == str_1) );
|
||||
|
@ -140,7 +140,131 @@ test01()
|
|||
VERIFY( str_3 != str_0 );
|
||||
VERIFY( !(str_0 != str_4) );
|
||||
VERIFY( !(str_4 != str_0) );
|
||||
|
||||
|
||||
VERIFY( str_0 > str_1 ); //true cuz r>m
|
||||
VERIFY( str_0 > str_2 );
|
||||
VERIFY( !(str_0 > str_3) );
|
||||
VERIFY( !(str_1 > str_0) ); //false cuz m<r
|
||||
VERIFY( !(str_2 > str_0) );
|
||||
VERIFY( str_3 > str_0 );
|
||||
VERIFY( !(str_0 > str_4) );
|
||||
VERIFY( !(str_4 > str_0) );
|
||||
|
||||
VERIFY( !(str_0 < str_1) ); //false cuz r>m
|
||||
VERIFY( !(str_0 < str_2) );
|
||||
VERIFY( str_0 < str_3 );
|
||||
VERIFY( str_1 < str_0 ); //true cuz m<r
|
||||
VERIFY( str_2 < str_0 );
|
||||
VERIFY( !(str_3 < str_0) );
|
||||
VERIFY( !(str_0 < str_4) );
|
||||
VERIFY( !(str_4 < str_0) );
|
||||
|
||||
VERIFY( str_0 >= str_1 ); //true cuz r>m
|
||||
VERIFY( str_0 >= str_2 );
|
||||
VERIFY( !(str_0 >= str_3) );
|
||||
VERIFY( !(str_1 >= str_0) );//false cuz m<r
|
||||
VERIFY( !(str_2 >= str_0) );
|
||||
VERIFY( str_3 >= str_0 );
|
||||
VERIFY( str_0 >= str_4 );
|
||||
VERIFY( str_4 >= str_0 );
|
||||
|
||||
VERIFY( !(str_0 <= str_1) );//false cuz r>m
|
||||
VERIFY( !(str_0 <= str_2) );
|
||||
VERIFY( str_0 <= str_3 );
|
||||
VERIFY( str_1 <= str_0 );//true cuz m<r
|
||||
VERIFY( str_2 <= str_0 );
|
||||
VERIFY( !(str_3 <= str_0) );
|
||||
VERIFY( str_0 <= str_4 );
|
||||
VERIFY( str_4 <= str_0 );
|
||||
|
||||
//comparisons between string object and string literal
|
||||
VERIFY( !(str_0 == "costa marbella") );
|
||||
VERIFY( !(str_0 == "cost") );
|
||||
VERIFY( !(str_0 == "costa ricans") );
|
||||
VERIFY( !("costa marbella" == str_0) );
|
||||
VERIFY( !("cost" == str_0) );
|
||||
VERIFY( !("costa ricans" == str_0) );
|
||||
VERIFY( "costa rica" == str_0 );
|
||||
VERIFY( str_0 == "costa rica" );
|
||||
|
||||
VERIFY( str_0 != "costa marbella" );
|
||||
VERIFY( str_0 != "cost" );
|
||||
VERIFY( str_0 != "costa ricans" );
|
||||
VERIFY( "costa marbella" != str_0 );
|
||||
VERIFY( "cost" != str_0 );
|
||||
VERIFY( "costa ricans" != str_0 );
|
||||
VERIFY( !("costa rica" != str_0) );
|
||||
VERIFY( !(str_0 != "costa rica") );
|
||||
|
||||
VERIFY( str_0 > "costa marbella" ); //true cuz r>m
|
||||
VERIFY( str_0 > "cost" );
|
||||
VERIFY( !(str_0 > "costa ricans") );
|
||||
VERIFY( !("costa marbella" > str_0) );//false cuz m<r
|
||||
VERIFY( !("cost" > str_0) );
|
||||
VERIFY( "costa ricans" > str_0 );
|
||||
VERIFY( !("costa rica" > str_0) );
|
||||
VERIFY( !(str_0 > "costa rica") );
|
||||
|
||||
VERIFY( !(str_0 < "costa marbella") );//false cuz r>m
|
||||
VERIFY( !(str_0 < "cost") );
|
||||
VERIFY( str_0 < "costa ricans" );
|
||||
VERIFY( "costa marbella" < str_0 );//true cuz m<r
|
||||
VERIFY( "cost" < str_0 );
|
||||
VERIFY( !("costa ricans" < str_0) );
|
||||
VERIFY( !("costa rica" < str_0) );
|
||||
VERIFY( !(str_0 < "costa rica") );
|
||||
|
||||
VERIFY( str_0 >= "costa marbella" );//true cuz r>m
|
||||
VERIFY( str_0 >= "cost" );
|
||||
VERIFY( !(str_0 >= "costa ricans") );
|
||||
VERIFY( !("costa marbella" >= str_0) );//false cuz m<r
|
||||
VERIFY( !("cost" >= str_0) );
|
||||
VERIFY( "costa ricans" >= str_0 );
|
||||
VERIFY( "costa rica" >= str_0 );
|
||||
VERIFY( str_0 >= "costa rica" );
|
||||
|
||||
VERIFY( !(str_0 <= "costa marbella") );//false cuz r>m
|
||||
VERIFY( !(str_0 <= "cost") );
|
||||
VERIFY( str_0 <= "costa ricans" );
|
||||
VERIFY( "costa marbella" <= str_0 );//true cuz m<r
|
||||
VERIFY( "cost" <= str_0 );
|
||||
VERIFY( !("costa ricans" <= str_0) );
|
||||
VERIFY( "costa rica" <= str_0 );
|
||||
VERIFY( str_0 <= "costa rica" );
|
||||
}
|
||||
|
||||
constexpr bool
|
||||
test02()
|
||||
{
|
||||
std::string_view str_0("costa rica");
|
||||
std::string_view str_1("costa marbella");
|
||||
std::string_view str_2("cost");
|
||||
std::string_view str_3("costa ricans");
|
||||
std::string_view str_4;
|
||||
|
||||
#undef VERIFY
|
||||
#define VERIFY(x) if (!(x)) return false
|
||||
|
||||
str_4 = str_0;
|
||||
//comparisons between string objects
|
||||
VERIFY( !(str_0 == str_1) );
|
||||
VERIFY( !(str_0 == str_2) );
|
||||
VERIFY( !(str_0 == str_3) );
|
||||
VERIFY( !(str_1 == str_0) );
|
||||
VERIFY( !(str_2 == str_0) );
|
||||
VERIFY( !(str_3 == str_0) );
|
||||
VERIFY( str_4 == str_0 );
|
||||
VERIFY( str_0 == str_4 );
|
||||
|
||||
VERIFY( str_0 != str_1 );
|
||||
VERIFY( str_0 != str_2 );
|
||||
VERIFY( str_0 != str_3 );
|
||||
VERIFY( str_1 != str_0 );
|
||||
VERIFY( str_2 != str_0 );
|
||||
VERIFY( str_3 != str_0 );
|
||||
VERIFY( !(str_0 != str_4) );
|
||||
VERIFY( !(str_4 != str_0) );
|
||||
|
||||
VERIFY( str_0 > str_1 ); //true cuz r>m
|
||||
VERIFY( str_0 > str_2 );
|
||||
VERIFY( !(str_0 > str_3) );
|
||||
|
@ -232,13 +356,12 @@ test01()
|
|||
VERIFY( "costa rica" <= str_0 );
|
||||
VERIFY( str_0 <= "costa rica" );
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
|
||||
return 0;
|
||||
static_assert( test02() );
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ template<class charT, class traits, class Allocator>
|
|||
const basic_string_view<charT,traits,Allocator>& rhs);
|
||||
|
||||
template<class charT, class traits, class Allocator>
|
||||
bool operator!=(const basic_string_view<charT,traits,Allocator>& lhs,
|
||||
bool operator!=(const basic_string_view<charT,traits,Allocator>& lhs,
|
||||
const charT* rhs);
|
||||
*/
|
||||
|
||||
|
@ -60,7 +60,7 @@ template<class charT, class traits, class Allocator>
|
|||
const charT* rhs);
|
||||
|
||||
template<class charT, class traits, class Allocator>
|
||||
bool operator< (const charT* lhs,
|
||||
bool operator< (const charT* lhs,
|
||||
const basic_string_view<charT,traits,Allocator>& rhs);
|
||||
*/
|
||||
|
||||
|
@ -112,7 +112,7 @@ template<class charT, class traits, class Allocator>
|
|||
#include <string_view>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
int
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::wstring_view str_0(L"costa rica");
|
||||
|
@ -120,7 +120,7 @@ test01()
|
|||
std::wstring_view str_2(L"cost");
|
||||
std::wstring_view str_3(L"costa ricans");
|
||||
std::wstring_view str_4;
|
||||
|
||||
|
||||
str_4 = str_0;
|
||||
//comparisons between string_view objects
|
||||
VERIFY( !(str_0 == str_1) );
|
||||
|
@ -140,7 +140,131 @@ test01()
|
|||
VERIFY( str_3 != str_0 );
|
||||
VERIFY( !(str_0 != str_4) );
|
||||
VERIFY( !(str_4 != str_0) );
|
||||
|
||||
|
||||
VERIFY( str_0 > str_1 ); //true cuz r>m
|
||||
VERIFY( str_0 > str_2 );
|
||||
VERIFY( !(str_0 > str_3) );
|
||||
VERIFY( !(str_1 > str_0) ); //false cuz m<r
|
||||
VERIFY( !(str_2 > str_0) );
|
||||
VERIFY( str_3 > str_0 );
|
||||
VERIFY( !(str_0 > str_4) );
|
||||
VERIFY( !(str_4 > str_0) );
|
||||
|
||||
VERIFY( !(str_0 < str_1) ); //false cuz r>m
|
||||
VERIFY( !(str_0 < str_2) );
|
||||
VERIFY( str_0 < str_3 );
|
||||
VERIFY( str_1 < str_0 ); //true cuz m<r
|
||||
VERIFY( str_2 < str_0 );
|
||||
VERIFY( !(str_3 < str_0) );
|
||||
VERIFY( !(str_0 < str_4) );
|
||||
VERIFY( !(str_4 < str_0) );
|
||||
|
||||
VERIFY( str_0 >= str_1 ); //true cuz r>m
|
||||
VERIFY( str_0 >= str_2 );
|
||||
VERIFY( !(str_0 >= str_3) );
|
||||
VERIFY( !(str_1 >= str_0) );//false cuz m<r
|
||||
VERIFY( !(str_2 >= str_0) );
|
||||
VERIFY( str_3 >= str_0 );
|
||||
VERIFY( str_0 >= str_4 );
|
||||
VERIFY( str_4 >= str_0 );
|
||||
|
||||
VERIFY( !(str_0 <= str_1) );//false cuz r>m
|
||||
VERIFY( !(str_0 <= str_2) );
|
||||
VERIFY( str_0 <= str_3 );
|
||||
VERIFY( str_1 <= str_0 );//true cuz m<r
|
||||
VERIFY( str_2 <= str_0 );
|
||||
VERIFY( !(str_3 <= str_0) );
|
||||
VERIFY( str_0 <= str_4 );
|
||||
VERIFY( str_4 <= str_0 );
|
||||
|
||||
//comparisons between string_view object and string_view literal
|
||||
VERIFY( !(str_0 == L"costa marbella") );
|
||||
VERIFY( !(str_0 == L"cost") );
|
||||
VERIFY( !(str_0 == L"costa ricans") );
|
||||
VERIFY( !(L"costa marbella" == str_0) );
|
||||
VERIFY( !(L"cost" == str_0) );
|
||||
VERIFY( !(L"costa ricans" == str_0) );
|
||||
VERIFY( L"costa rica" == str_0 );
|
||||
VERIFY( str_0 == L"costa rica" );
|
||||
|
||||
VERIFY( str_0 != L"costa marbella" );
|
||||
VERIFY( str_0 != L"cost" );
|
||||
VERIFY( str_0 != L"costa ricans" );
|
||||
VERIFY( L"costa marbella" != str_0 );
|
||||
VERIFY( L"cost" != str_0 );
|
||||
VERIFY( L"costa ricans" != str_0 );
|
||||
VERIFY( !(L"costa rica" != str_0) );
|
||||
VERIFY( !(str_0 != L"costa rica") );
|
||||
|
||||
VERIFY( str_0 > L"costa marbella" ); //true cuz r>m
|
||||
VERIFY( str_0 > L"cost" );
|
||||
VERIFY( !(str_0 > L"costa ricans") );
|
||||
VERIFY( !(L"costa marbella" > str_0) );//false cuz m<r
|
||||
VERIFY( !(L"cost" > str_0) );
|
||||
VERIFY( L"costa ricans" > str_0 );
|
||||
VERIFY( !(L"costa rica" > str_0) );
|
||||
VERIFY( !(str_0 > L"costa rica") );
|
||||
|
||||
VERIFY( !(str_0 < L"costa marbella") );//false cuz r>m
|
||||
VERIFY( !(str_0 < L"cost") );
|
||||
VERIFY( str_0 < L"costa ricans" );
|
||||
VERIFY( L"costa marbella" < str_0 );//true cuz m<r
|
||||
VERIFY( L"cost" < str_0 );
|
||||
VERIFY( !(L"costa ricans" < str_0) );
|
||||
VERIFY( !(L"costa rica" < str_0) );
|
||||
VERIFY( !(str_0 < L"costa rica") );
|
||||
|
||||
VERIFY( str_0 >= L"costa marbella" );//true cuz r>m
|
||||
VERIFY( str_0 >= L"cost" );
|
||||
VERIFY( !(str_0 >= L"costa ricans") );
|
||||
VERIFY( !(L"costa marbella" >= str_0) );//false cuz m<r
|
||||
VERIFY( !(L"cost" >= str_0) );
|
||||
VERIFY( L"costa ricans" >= str_0 );
|
||||
VERIFY( L"costa rica" >= str_0 );
|
||||
VERIFY( str_0 >= L"costa rica" );
|
||||
|
||||
VERIFY( !(str_0 <= L"costa marbella") );//false cuz r>m
|
||||
VERIFY( !(str_0 <= L"cost") );
|
||||
VERIFY( str_0 <= L"costa ricans" );
|
||||
VERIFY( L"costa marbella" <= str_0 );//true cuz m<r
|
||||
VERIFY( L"cost" <= str_0 );
|
||||
VERIFY( !(L"costa ricans" <= str_0) );
|
||||
VERIFY( L"costa rica" <= str_0 );
|
||||
VERIFY( str_0 <= L"costa rica" );
|
||||
}
|
||||
|
||||
constexpr bool
|
||||
test02()
|
||||
{
|
||||
std::wstring_view str_0(L"costa rica");
|
||||
std::wstring_view str_1(L"costa marbella");
|
||||
std::wstring_view str_2(L"cost");
|
||||
std::wstring_view str_3(L"costa ricans");
|
||||
std::wstring_view str_4;
|
||||
|
||||
#undef VERIFY
|
||||
#define VERIFY(x) if (!(x)) return false
|
||||
|
||||
str_4 = str_0;
|
||||
//comparisons between string_view objects
|
||||
VERIFY( !(str_0 == str_1) );
|
||||
VERIFY( !(str_0 == str_2) );
|
||||
VERIFY( !(str_0 == str_3) );
|
||||
VERIFY( !(str_1 == str_0) );
|
||||
VERIFY( !(str_2 == str_0) );
|
||||
VERIFY( !(str_3 == str_0) );
|
||||
VERIFY( str_4 == str_0 );
|
||||
VERIFY( str_0 == str_4 );
|
||||
|
||||
VERIFY( str_0 != str_1 );
|
||||
VERIFY( str_0 != str_2 );
|
||||
VERIFY( str_0 != str_3 );
|
||||
VERIFY( str_1 != str_0 );
|
||||
VERIFY( str_2 != str_0 );
|
||||
VERIFY( str_3 != str_0 );
|
||||
VERIFY( !(str_0 != str_4) );
|
||||
VERIFY( !(str_4 != str_0) );
|
||||
|
||||
VERIFY( str_0 > str_1 ); //true cuz r>m
|
||||
VERIFY( str_0 > str_2 );
|
||||
VERIFY( !(str_0 > str_3) );
|
||||
|
@ -232,13 +356,12 @@ test01()
|
|||
VERIFY( L"costa rica" <= str_0 );
|
||||
VERIFY( str_0 <= L"costa rica" );
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
|
||||
return 0;
|
||||
static_assert( test02() );
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// 24.6.5, range access [iterator.range]
|
||||
// C++17 27.7, range access [iterator.range]
|
||||
|
||||
#include <string_view>
|
||||
|
||||
|
@ -28,4 +28,20 @@ test01()
|
|||
std::string_view s("Hello, World!");
|
||||
std::begin(s);
|
||||
std::end(s);
|
||||
std::rbegin(s);
|
||||
std::rend(s);
|
||||
}
|
||||
|
||||
void
|
||||
test02()
|
||||
{
|
||||
constexpr std::string_view s("Hello, World!");
|
||||
[[maybe_unused]] constexpr auto b = std::begin(s);
|
||||
[[maybe_unused]] constexpr auto e = std::end(s);
|
||||
[[maybe_unused]] constexpr auto cb = std::cbegin(s);
|
||||
[[maybe_unused]] constexpr auto ce = std::cend(s);
|
||||
[[maybe_unused]] constexpr auto rb = std::rbegin(s);
|
||||
[[maybe_unused]] constexpr auto re = std::rend(s);
|
||||
[[maybe_unused]] constexpr auto crb = std::crbegin(s);
|
||||
[[maybe_unused]] constexpr auto cre = std::crend(s);
|
||||
}
|
||||
|
|
|
@ -18,16 +18,30 @@
|
|||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// 24.6.5, range access [iterator.range]
|
||||
// C++17 27.7, range access [iterator.range]
|
||||
|
||||
#include <string_view>
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
#ifdef _GLIBCXX_USE_WCHAR_T
|
||||
std::wstring_view ws(L"Hello, World!");
|
||||
std::begin(ws);
|
||||
std::end(ws);
|
||||
#endif
|
||||
std::rbegin(ws);
|
||||
std::rend(ws);
|
||||
}
|
||||
|
||||
void
|
||||
test02()
|
||||
{
|
||||
constexpr std::wstring_view ws(L"Hello, World!");
|
||||
[[maybe_unused]] constexpr auto b = std::begin(ws);
|
||||
[[maybe_unused]] constexpr auto e = std::end(ws);
|
||||
[[maybe_unused]] constexpr auto cb = std::cbegin(ws);
|
||||
[[maybe_unused]] constexpr auto ce = std::cend(ws);
|
||||
[[maybe_unused]] constexpr auto rb = std::rbegin(ws);
|
||||
[[maybe_unused]] constexpr auto re = std::rend(ws);
|
||||
[[maybe_unused]] constexpr auto crb = std::crbegin(ws);
|
||||
[[maybe_unused]] constexpr auto cre = std::crend(ws);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue