Implement std::string_view and P0254r2,

Integrating std::string_view and std::string.
	* include/Makefile.am: Add string_view and string_view.tcc
	to the exported headers.
	* include/Makefile.in: Likewise.
	* include/bits/basic_string.h: Include <string_view> in C++17 mode.
	(__sv_type): New.
	(basic_string(__sv_type, const _Alloc&)): Likewise.
	(operator=(__sv_type)): Likewise.
	(operator __sv_type()): Likewise.
	(operator+=(__sv_type)): Likewise.
	(append(__sv_type __sv)): Likewise.
	(append(__sv_type, size_type, size_type)): Likewise.
	(assign(__sv_type)): Likewise.
	(assign(__sv_type, size_type, size_type)): Likewise.
	(insert(size_type, __sv_type)): Likewise.
	(insert(size_type, __sv_type, size_type, size_type)): Likewise.
	(replace(size_type, size_type, __sv_type)): Likewise.
	(replace(size_type, size_type, __sv_type, size_type, size_type)):
	Likewise.
	(replace(const_iterator, const_iterator, __sv_type)): Likewise.
	(find(__sv_type, size_type)): Likewise.
	(rfind(__sv_type, size_type)): Likewise.
	(find_first_of(__sv_type, size_type)): Likewise.
	(find_last_of(__sv_type, size_type)): Likewise.
	(find_first_not_of(__sv_type, size_type)): Likewise.
	(find_last_not_of(__sv_type, size_type)): Likewise.
	(compare(__sv_type)): Likewise.
	(compare(size_type, size_type, __sv_type)): Likewise.
	(compare(size_type, size_type, __sv_type, size_type, size_type)):
	Likewise.
	* include/bits/string_view.tcc: New.
	* include/std/string_view: Likewise.
	* testsuite/21_strings/basic_string/cons/char/7.cc: Likewise.
	* testsuite/21_strings/basic_string/cons/wchar_t/7.cc: Likewise.
	* testsuite/21_strings/basic_string/modifiers/append/char/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/append/wchar_t/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/assign/char/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/assign/wchar_t/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/insert/char/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/insert/wchar_t/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/replace/char/7.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/replace/wchar_t/7.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/compare/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/compare/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/find/char/5.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/find/wchar_t/5.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operators/char/5.cc: Likewise.
	* testsuite/21_strings/basic_string/operators/wchar_t/5.cc: Likewise.
	* testsuite/21_strings/basic_string_view/capacity/1.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/char/1.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/char/2.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/char/3.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/wchar_t/1.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/wchar_t/2.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/wchar_t/3.cc: Likewise.
	* testsuite/21_strings/basic_string_view/element_access/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/char/empty.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/char/front_back.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/empty.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/front_back.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/include.cc: Likewise.
	* testsuite/21_strings/basic_string_view/inserters/char/1.cc: Likewise.
	* testsuite/21_strings/basic_string_view/inserters/char/2.cc: Likewise.
	* testsuite/21_strings/basic_string_view/inserters/char/3.cc: Likewise.
	* testsuite/21_strings/basic_string_view/inserters/pod/10081-out.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/inserters/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/inserters/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/inserters/wchar_t/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/char/1.cc:
	Likewise.
	* 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/compare/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/char/13650.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/wchar_t/13650.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/copy/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/copy/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/data/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/data/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/char/4.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/operations/find/wchar_t/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/char/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/wchar_t/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/string_conversion/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/substr/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/substr/wchar_t/1.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:
	Likewise.
	* testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char16_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char32_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/typedefs.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/typedefs.cc: Likewise.
	* testsuite/21_strings/basic_string_view/types/1.cc: Likewise.

From-SVN: r238823
This commit is contained in:
Ville Voutilainen 2016-07-28 18:15:26 +03:00 committed by Ville Voutilainen
parent a23404c90f
commit ca8f2cb137
86 changed files with 6458 additions and 0 deletions

View File

@ -1,3 +1,181 @@
2016-07-28 Ville Voutilainen <ville.voutilainen@gmail.com>
Implement std::string_view and P0254r2,
Integrating std::string_view and std::string.
* include/Makefile.am: Add string_view and string_view.tcc
to the exported headers.
* include/Makefile.in: Likewise.
* include/bits/basic_string.h: Include <string_view> in C++17 mode.
(__sv_type): New.
(basic_string(__sv_type, const _Alloc&)): Likewise.
(operator=(__sv_type)): Likewise.
(operator __sv_type()): Likewise.
(operator+=(__sv_type)): Likewise.
(append(__sv_type __sv)): Likewise.
(append(__sv_type, size_type, size_type)): Likewise.
(assign(__sv_type)): Likewise.
(assign(__sv_type, size_type, size_type)): Likewise.
(insert(size_type, __sv_type)): Likewise.
(insert(size_type, __sv_type, size_type, size_type)): Likewise.
(replace(size_type, size_type, __sv_type)): Likewise.
(replace(size_type, size_type, __sv_type, size_type, size_type)):
Likewise.
(replace(const_iterator, const_iterator, __sv_type)): Likewise.
(find(__sv_type, size_type)): Likewise.
(rfind(__sv_type, size_type)): Likewise.
(find_first_of(__sv_type, size_type)): Likewise.
(find_last_of(__sv_type, size_type)): Likewise.
(find_first_not_of(__sv_type, size_type)): Likewise.
(find_last_not_of(__sv_type, size_type)): Likewise.
(compare(__sv_type)): Likewise.
(compare(size_type, size_type, __sv_type)): Likewise.
(compare(size_type, size_type, __sv_type, size_type, size_type)):
Likewise.
* include/bits/string_view.tcc: New.
* include/std/string_view: Likewise.
* testsuite/21_strings/basic_string/cons/char/7.cc: Likewise.
* testsuite/21_strings/basic_string/cons/wchar_t/7.cc: Likewise.
* testsuite/21_strings/basic_string/modifiers/append/char/4.cc:
Likewise.
* testsuite/21_strings/basic_string/modifiers/append/wchar_t/4.cc:
Likewise.
* testsuite/21_strings/basic_string/modifiers/assign/char/4.cc:
Likewise.
* testsuite/21_strings/basic_string/modifiers/assign/wchar_t/4.cc:
Likewise.
* testsuite/21_strings/basic_string/modifiers/insert/char/3.cc:
Likewise.
* testsuite/21_strings/basic_string/modifiers/insert/wchar_t/3.cc:
Likewise.
* testsuite/21_strings/basic_string/modifiers/replace/char/7.cc:
Likewise.
* testsuite/21_strings/basic_string/modifiers/replace/wchar_t/7.cc:
Likewise.
* testsuite/21_strings/basic_string/operations/compare/char/2.cc:
Likewise.
* testsuite/21_strings/basic_string/operations/compare/wchar_t/2.cc:
Likewise.
* testsuite/21_strings/basic_string/operations/find/char/5.cc:
Likewise.
* testsuite/21_strings/basic_string/operations/find/wchar_t/5.cc:
Likewise.
* testsuite/21_strings/basic_string/operators/char/5.cc: Likewise.
* testsuite/21_strings/basic_string/operators/wchar_t/5.cc: Likewise.
* testsuite/21_strings/basic_string_view/capacity/1.cc: Likewise.
* testsuite/21_strings/basic_string_view/cons/char/1.cc: Likewise.
* testsuite/21_strings/basic_string_view/cons/char/2.cc: Likewise.
* testsuite/21_strings/basic_string_view/cons/char/3.cc: Likewise.
* testsuite/21_strings/basic_string_view/cons/wchar_t/1.cc: Likewise.
* testsuite/21_strings/basic_string_view/cons/wchar_t/2.cc: Likewise.
* testsuite/21_strings/basic_string_view/cons/wchar_t/3.cc: Likewise.
* testsuite/21_strings/basic_string_view/element_access/char/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/char/2.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/char/empty.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/char/front_back.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/wchar_t/2.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/wchar_t/empty.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/wchar_t/front_back.cc:
Likewise.
* testsuite/21_strings/basic_string_view/include.cc: Likewise.
* testsuite/21_strings/basic_string_view/inserters/char/1.cc: Likewise.
* testsuite/21_strings/basic_string_view/inserters/char/2.cc: Likewise.
* testsuite/21_strings/basic_string_view/inserters/char/3.cc: Likewise.
* testsuite/21_strings/basic_string_view/inserters/pod/10081-out.cc:
Likewise.
* testsuite/21_strings/basic_string_view/inserters/wchar_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/inserters/wchar_t/2.cc:
Likewise.
* testsuite/21_strings/basic_string_view/inserters/wchar_t/3.cc:
Likewise.
* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/char/1.cc:
Likewise.
* 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/compare/char/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/compare/char/13650.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/compare/wchar_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/compare/wchar_t/13650.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/copy/char/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/copy/wchar_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/data/char/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/data/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/char/4.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/operations/find/wchar_t/4.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/rfind/char/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/rfind/char/2.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/rfind/char/3.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/rfind/wchar_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/rfind/wchar_t/2.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/rfind/wchar_t/3.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/string_conversion/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/substr/char/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/substr/wchar_t/1.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:
Likewise.
* testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char16_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char32_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/wchar_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/requirements/typedefs.cc:
Likewise.
* testsuite/21_strings/basic_string_view/typedefs.cc: Likewise.
* testsuite/21_strings/basic_string_view/types/1.cc: Likewise.
2016-07-27 Jonathan Wakely <jwakely@redhat.com>
* testsuite/20_util/forward/1_neg.cc: Move dg-error to right line.

View File

@ -67,6 +67,7 @@ std_headers = \
${std_srcdir}/stdexcept \
${std_srcdir}/streambuf \
${std_srcdir}/string \
${std_srcdir}/string_view \
${std_srcdir}/system_error \
${std_srcdir}/thread \
${std_srcdir}/tuple \
@ -183,6 +184,7 @@ bits_headers = \
${bits_srcdir}/stl_vector.h \
${bits_srcdir}/streambuf.tcc \
${bits_srcdir}/stringfwd.h \
${bits_srcdir}/string_view.tcc \
${bits_srcdir}/uniform_int_dist.h \
${bits_srcdir}/unique_ptr.h \
${bits_srcdir}/unordered_map.h \

View File

@ -357,6 +357,7 @@ std_headers = \
${std_srcdir}/stdexcept \
${std_srcdir}/streambuf \
${std_srcdir}/string \
${std_srcdir}/string_view \
${std_srcdir}/system_error \
${std_srcdir}/thread \
${std_srcdir}/tuple \
@ -473,6 +474,7 @@ bits_headers = \
${bits_srcdir}/stl_vector.h \
${bits_srcdir}/streambuf.tcc \
${bits_srcdir}/stringfwd.h \
${bits_srcdir}/string_view.tcc \
${bits_srcdir}/uniform_int_dist.h \
${bits_srcdir}/unique_ptr.h \
${bits_srcdir}/unordered_map.h \

View File

@ -44,6 +44,11 @@
#include <initializer_list>
#endif
#if __cplusplus > 201402L
# include <string_view>
#endif
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
@ -103,6 +108,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
typedef const_iterator __const_iterator;
#endif
#if __cplusplus > 201402L
// A helper type for avoiding boiler-plate.
typedef basic_string_view<_CharT, _Traits> __sv_type;
#endif
// Use empty-base optimization: http://www.cantrip.org/emptyopt.html
struct _Alloc_hider : allocator_type // TODO check __is_final
{
@ -559,6 +569,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
: _M_dataplus(_M_local_data(), __a)
{ _M_construct(__beg, __end); }
#if __cplusplus > 201402L
/**
* @brief Construct string from a string_view.
* @param __sv Source string view.
* @param __a Allocator to use (default is default allocator).
*/
explicit basic_string(__sv_type __sv, const _Alloc& __a = _Alloc())
: basic_string(__sv.data(), __sv.size(), __a) {}
#endif // C++17
/**
* @brief Destroy the string instance.
*/
@ -684,6 +704,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
}
#endif // C++11
#if __cplusplus > 201402L
/**
* @brief Set value to string constructed from a string_view.
* @param __sv A string_view.
*/
basic_string& operator=(__sv_type __sv)
{ return this->assign(__sv); }
/**
* @brief Convert to a string_view.
* @return A string_view.
*/
operator __sv_type() const noexcept
{ return __sv_type(data(), size()); }
#endif // C++17
// Iterators:
/**
* Returns a read/write iterator that points to the first character in
@ -1067,6 +1103,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
{ return this->append(__l.begin(), __l.size()); }
#endif // C++11
#if __cplusplus > 201402L
/**
* @brief Append a string_view.
* @param __sv The string_view to be appended.
* @return Reference to this string.
*/
basic_string&
operator+=(__sv_type __sv)
{ return this->append(__sv); }
#endif // C++17
/**
* @brief Append a string to this string.
* @param __str The string to append.
@ -1164,6 +1211,31 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
append(_InputIterator __first, _InputIterator __last)
{ return this->replace(end(), end(), __first, __last); }
#if __cplusplus > 201402L
/**
* @brief Append a string_view.
* @param __sv The string_view to be appended.
* @return Reference to this string.
*/
basic_string& append(__sv_type __sv)
{ return this->append(__sv.data(), __sv.size()); }
/**
* @brief Append a range of characters from a string_view.
* @param __sv The string_view to be appended from.
* @param __pos The position in the string_view to append from.
* @param __n The number of characters to append from the string_view.
* @return Reference to this string.
*/
basic_string& append(__sv_type __sv,
size_type __pos, size_type __n = npos)
{
return _M_append(__sv.data()
+ __sv._M_check(__pos, "basic_string::append"),
__sv._M_limit(__pos, __n));
}
#endif // C++17
/**
* @brief Append a single character.
* @param __c Character to append.
@ -1304,6 +1376,32 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
{ return this->assign(__l.begin(), __l.size()); }
#endif // C++11
#if __cplusplus > 201402L
/**
* @brief Set value from a string_view.
* @param __sv The source string_view.
* @return Reference to this string.
*/
basic_string& assign(__sv_type __sv)
{ return this->assign(__sv.data(), __sv.size()); }
/**
* @brief Set value from a range of characters in a string_view.
* @param __sv The source string_view.
* @param __pos The position in the string_view to assign from.
* @param __n The number of characters to assign.
* @return Reference to this string.
*/
basic_string&
assign(__sv_type __sv,
size_type __pos, size_type __n = npos)
{
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
/**
* @brief Insert multiple characters.
@ -1534,6 +1632,35 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
return iterator(_M_data() + __pos);
}
#if __cplusplus > 201402L
/**
* @brief Insert a string_view.
* @param __pos Iterator referencing position in string to insert at.
* @param __sv The string_view to insert.
* @return Reference to this string.
*/
basic_string& insert(size_type __pos,
__sv_type __sv)
{ return this->insert(__pos, __sv.data(), __sv.size()); }
/**
* @brief Insert a string_view.
* @param __pos Iterator referencing position in string to insert at.
* @param __sv The string_view to insert from.
* @param __pos Iterator referencing position in string_view to insert
* from.
* @param __n The number of characters to insert.
* @return Reference to this string.
*/
basic_string& insert(size_type __pos1, __sv_type __sv,
size_type __pos2, size_type __n = npos)
{
return this->replace(__pos1, size_type(0), __sv.data()
+ __sv._M_check(__pos2, "basic_string::insert"),
__sv._M_limit(__pos2, __n));
}
#endif // C++17
/**
* @brief Remove characters.
* @param __pos Index of first character to remove (default 0).
@ -1923,6 +2050,50 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
{ return this->replace(__i1, __i2, __l.begin(), __l.size()); }
#endif // C++11
#if __cplusplus > 201402L
/**
* @brief Replace range of characters with string_view.
* @param __pos The position to replace at.
* @param __n The number of characters to replace.
* @param __sv The string_view to insert.
* @return Reference to this string.
*/
basic_string& replace(size_type __pos, size_type __n,
__sv_type __sv)
{ return this->replace(__pos, __n, __sv.data(), __sv.size()); }
/**
* @brief Replace range of characters with string_view.
* @param __pos1 The position to replace at.
* @param __n1 The number of characters to replace.
* @param __sv The string_view to insert from.
* @param __pos2 The position in the string_view to insert from.
* @param __n2 The number of characters to insert.
* @return Reference to this string.
*/
basic_string& replace(size_type __pos1, size_type __n1,
__sv_type __sv,
size_type __pos2, size_type __n2 = npos)
{
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 __i1 An iterator referencing the start position
to replace at.
* @param __i2 An iterator referencing the end position
for the replace.
* @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)
{ return this->replace(__i1 - begin(), __i2 - __i1, __sv); }
#endif // C++17
private:
template<class _Integer>
basic_string&
@ -2032,6 +2203,19 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_GLIBCXX_NOEXCEPT
{ return this->find(__str.data(), __pos, __str.size()); }
#if __cplusplus > 201402L
/**
* @brief Find position of a string_view.
* @param __sv The string_view to locate.
* @param __pos Index of character to search from (default 0).
* @return Index of start of first occurrence.
*/
size_type
find(__sv_type __sv,
size_type __pos = 0) const noexcept
{ return this->find(__sv.data(), __pos, __sv.size()); }
#endif // C++17
/**
* @brief Find position of a C string.
* @param __s C string to locate.
@ -2077,6 +2261,19 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_GLIBCXX_NOEXCEPT
{ return this->rfind(__str.data(), __pos, __str.size()); }
#if __cplusplus > 201402L
/**
* @brief Find last position of a string_view.
* @param __sv The string_view to locate.
* @param __pos Index of character to search back from (default end).
* @return Index of start of last occurrence.
*/
size_type
rfind (__sv_type __sv,
size_type __pos = npos) const noexcept
{ return this->rfind(__sv.data(), __pos, __sv.size()); }
#endif // C++17
/**
* @brief Find last position of a C substring.
* @param __s C string to locate.
@ -2138,6 +2335,18 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_GLIBCXX_NOEXCEPT
{ return this->find_first_of(__str.data(), __pos, __str.size()); }
#if __cplusplus > 201402L
/**
* @brief Find position of a character of a string_view.
* @param __sv A string_view containing characters to locate.
* @param __pos Index of character to search from (default 0).
* @return Index of first occurrence.
*/
size_type
find_first_of(__sv_type __sv, size_type __pos = 0) const noexcept
{ return this->find_first_of(__sv.data(), __pos, __sv.size()); }
#endif // C++17
/**
* @brief Find position of a character of C substring.
* @param __s String containing characters to locate.
@ -2202,6 +2411,18 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_GLIBCXX_NOEXCEPT
{ return this->find_last_of(__str.data(), __pos, __str.size()); }
#if __cplusplus > 201402L
/**
* @brief Find last position of a character of string.
* @param __sv A string_view containing characters to locate.
* @param __pos Index of character to search back from (default end).
* @return Index of last occurrence.
*/
size_type
find_last_of(__sv_type __sv, size_type __pos = npos) const noexcept
{ return this->find_last_of(__sv.data(), __pos, __sv.size()); }
#endif // C++17
/**
* @brief Find last position of a character of C substring.
* @param __s C string containing characters to locate.
@ -2265,6 +2486,18 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_GLIBCXX_NOEXCEPT
{ return this->find_first_not_of(__str.data(), __pos, __str.size()); }
#if __cplusplus > 201402L
/**
* @brief Find position of a character not in a string_view.
* @param __sv A string_view containing characters to avoid.
* @param __pos Index of character to search from (default 0).
* @return Index of first occurrence.
*/
size_type
find_first_not_of(__sv_type __sv, size_type __pos = 0) const noexcept
{ return this->find_first_not_of(__sv.data(), __pos, __sv.size()); }
#endif // C++17
/**
* @brief Find position of a character not in C substring.
* @param __s C string containing characters to avoid.
@ -2328,6 +2561,18 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_GLIBCXX_NOEXCEPT
{ return this->find_last_not_of(__str.data(), __pos, __str.size()); }
#if __cplusplus > 201402L
/**
* @brief Find last position of a character not in a string_view.
* @param __sv A string_view containing characters to avoid.
* @param __pos Index of character to search back from (default end).
* @return Index of last occurrence.
*/
size_type
find_last_not_of(__sv_type __sv, size_type __pos = npos) const noexcept
{ return this->find_last_not_of(__sv.data(), __pos, __sv.size()); }
#endif // C++17
/**
* @brief Find last position of a character not in C substring.
* @param __s C string containing characters to avoid.
@ -2419,6 +2664,57 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
return __r;
}
#if __cplusplus > 201402L
/**
* @brief Compare to a string_view.
* @param __sv A string_view to compare against.
* @return Integer < 0, 0, or > 0.
*/
int
compare(__sv_type __sv) const
{
const size_type __size = this->size();
const size_type __osize = __sv.size();
const size_type __len = std::min(__size, __osize);
int __r = traits_type::compare(_M_data(), __sv.data(), __len);
if (!__r)
__r = _S_compare(__size, __osize);
return __r;
}
/**
* @brief Compare to a string_view.
* @param __pos A position in the string to start comparing from.
* @param __n The number of characters to compare.
* @param __sv A string_view to compare against.
* @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);
}
/**
* @brief Compare to a string_view.
* @param __pos1 A position in the string to start comparing from.
* @param __n1 The number of characters to compare.
* @param __sv A string_view to compare against.
* @param __pos2 A position in the string_view to start comparing from.
* @param __n2 The number of characters to compare.
* @return Integer < 0, 0, or > 0.
*/
int compare(size_type __pos1, size_type __n1,
__sv_type __sv,
size_type __pos2, size_type __n2 = npos) const
{
return __sv_type(*this)
.substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
}
#endif // C++17
/**
* @brief Compare substring to a string.
* @param __pos Index of first character of substring.

View File

@ -0,0 +1,227 @@
// Components for manipulating non-owning sequences of characters -*- C++ -*-
// Copyright (C) 2013-2016 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.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file bits/string_view.tcc
* This is an internal header file, included by other library headers.
* Do not attempt to use it directly. @headername{string_view}
*/
//
// N3762 basic_string_view library
//
#ifndef _GLIBCXX_STRING_VIEW_TCC
#define _GLIBCXX_STRING_VIEW_TCC 1
#pragma GCC system_header
#if __cplusplus <= 201402L
# include <bits/c++17_warning.h>
#else
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _CharT, typename _Traits>
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
{
__glibcxx_requires_string_len(__str, __n);
if (__n == 0)
return __pos <= this->_M_len ? __pos : npos;
if (__n <= this->_M_len)
{
for (; __pos <= this->_M_len - __n; ++__pos)
if (traits_type::eq(this->_M_str[__pos], __str[0])
&& traits_type::compare(this->_M_str + __pos + 1,
__str + 1, __n - 1) == 0)
return __pos;
}
return npos;
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find(_CharT __c, size_type __pos) const noexcept
{
size_type __ret = npos;
if (__pos < this->_M_len)
{
const size_type __n = this->_M_len - __pos;
const _CharT* __p = traits_type::find(this->_M_str + __pos, __n, __c);
if (__p)
__ret = __p - this->_M_str;
}
return __ret;
}
template<typename _CharT, typename _Traits>
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
{
__glibcxx_requires_string_len(__str, __n);
if (__n <= this->_M_len)
{
__pos = std::min(size_type(this->_M_len - __n), __pos);
do
{
if (traits_type::compare(this->_M_str + __pos, __str, __n) == 0)
return __pos;
}
while (__pos-- > 0);
}
return npos;
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
rfind(_CharT __c, size_type __pos) const noexcept
{
size_type __size = this->_M_len;
if (__size > 0)
{
if (--__size > __pos)
__size = __pos;
for (++__size; __size-- > 0; )
if (traits_type::eq(this->_M_str[__size], __c))
return __size;
}
return npos;
}
template<typename _CharT, typename _Traits>
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
{
__glibcxx_requires_string_len(__str, __n);
for (; __n && __pos < this->_M_len; ++__pos)
{
const _CharT* __p = traits_type::find(__str, __n,
this->_M_str[__pos]);
if (__p)
return __pos;
}
return npos;
}
template<typename _CharT, typename _Traits>
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
{
__glibcxx_requires_string_len(__str, __n);
size_type __size = this->size();
if (__size && __n)
{
if (--__size > __pos)
__size = __pos;
do
{
if (traits_type::find(__str, __n, this->_M_str[__size]))
return __size;
}
while (__size-- != 0);
}
return npos;
}
template<typename _CharT, typename _Traits>
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
{
__glibcxx_requires_string_len(__str, __n);
for (; __pos < this->_M_len; ++__pos)
if (!traits_type::find(__str, __n, this->_M_str[__pos]))
return __pos;
return npos;
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_first_not_of(_CharT __c, size_type __pos) const noexcept
{
for (; __pos < this->_M_len; ++__pos)
if (!traits_type::eq(this->_M_str[__pos], __c))
return __pos;
return npos;
}
template<typename _CharT, typename _Traits>
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
{
__glibcxx_requires_string_len(__str, __n);
size_type __size = this->_M_len;
if (__size)
{
if (--__size > __pos)
__size = __pos;
do
{
if (!traits_type::find(__str, __n, this->_M_str[__size]))
return __size;
}
while (__size--);
}
return npos;
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_last_not_of(_CharT __c, size_type __pos) const noexcept
{
size_type __size = this->_M_len;
if (__size)
{
if (--__size > __pos)
__size = __pos;
do
{
if (!traits_type::eq(this->_M_str[__size], __c))
return __size;
}
while (__size--);
}
return npos;
}
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
#endif // __cplusplus <= 201402L
#endif // _GLIBCXX_STRING_VIEW_TCC

View File

@ -0,0 +1,652 @@
// Components for manipulating non-owning sequences of characters -*- C++ -*-
// Copyright (C) 2013-2016 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.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file string_view
* This is a Standard C++ Library header.
*/
//
// N3762 basic_string_view library
//
#ifndef _GLIBCXX_STRING_VIEW
#define _GLIBCXX_STRING_VIEW 1
#pragma GCC system_header
#if __cplusplus <= 201402L
# include <bits/c++17_warning.h>
#else
#include <limits>
#include <iosfwd>
#include <bits/char_traits.h>
#include <bits/functional_hash.h>
#include <bits/range_access.h>
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/**
* @class basic_string_view <string_view>
* @brief A non-owning reference to a string.
*
* @ingroup strings
* @ingroup sequences
*
* @tparam _CharT Type of character
* @tparam _Traits Traits for character type, defaults to
* char_traits<_CharT>.
*
* A basic_string_view looks like this:
*
* @code
* _CharT* _M_str
* size_t _M_len
* @endcode
*/
template<typename _CharT, typename _Traits = std::char_traits<_CharT>>
class basic_string_view
{
public:
// types
using traits_type = _Traits;
using value_type = _CharT;
using pointer = const _CharT*;
using const_pointer = const _CharT*;
using reference = const _CharT&;
using const_reference = const _CharT&;
using const_iterator = const _CharT*;
using iterator = const_iterator;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
using reverse_iterator = const_reverse_iterator;
using size_type = size_t;
using difference_type = ptrdiff_t;
static constexpr size_type npos = size_type(-1);
// [string.view.cons], construct/copy
constexpr
basic_string_view() noexcept
: _M_len{0}, _M_str{nullptr}
{ }
constexpr basic_string_view(const basic_string_view&) noexcept = default;
constexpr basic_string_view(const _CharT* __str)
: _M_len{__str == nullptr ? 0 : traits_type::length(__str)},
_M_str{__str}
{ }
constexpr basic_string_view(const _CharT* __str, size_type __len)
: _M_len{__len},
_M_str{__str}
{ }
basic_string_view&
operator=(const basic_string_view&) noexcept = default;
// [string.view.iterators], iterators
constexpr const_iterator
begin() const noexcept
{ return this->_M_str; }
constexpr const_iterator
end() const noexcept
{ return this->_M_str + this->_M_len; }
constexpr const_iterator
cbegin() const noexcept
{ return this->_M_str; }
constexpr const_iterator
cend() const noexcept
{ return this->_M_str + this->_M_len; }
const_reverse_iterator
rbegin() const noexcept
{ return const_reverse_iterator(this->end()); }
const_reverse_iterator
rend() const noexcept
{ return const_reverse_iterator(this->begin()); }
const_reverse_iterator
crbegin() const noexcept
{ return const_reverse_iterator(this->end()); }
const_reverse_iterator
crend() const noexcept
{ return const_reverse_iterator(this->begin()); }
// [string.view.capacity], capacity
constexpr size_type
size() const noexcept
{ return this->_M_len; }
constexpr size_type
length() const noexcept
{ return _M_len; }
constexpr size_type
max_size() const noexcept
{
return (npos - sizeof(size_type) - sizeof(void*))
/ sizeof(value_type) / 4;
}
constexpr bool
empty() const noexcept
{ return this->_M_len == 0; }
// [string.view.access], element access
constexpr const _CharT&
operator[](size_type __pos) const noexcept
{
// TODO: Assert to restore in a way compatible with the constexpr.
// __glibcxx_assert(__pos < this->_M_len);
return *(this->_M_str + __pos);
}
constexpr const _CharT&
at(size_type __pos) const
{
return __pos < this->_M_len
? *(this->_M_str + __pos)
: (__throw_out_of_range_fmt(__N("basic_string_view::at: __pos "
"(which is %zu) >= this->size() "
"(which is %zu)"),
__pos, this->size()),
*this->_M_str);
}
constexpr const _CharT&
front() const
{
// TODO: Assert to restore in a way compatible with the constexpr.
// __glibcxx_assert(this->_M_len > 0);
return *this->_M_str;
}
constexpr const _CharT&
back() const
{
// TODO: Assert to restore in a way compatible with the constexpr.
// __glibcxx_assert(this->_M_len > 0);
return *(this->_M_str + this->_M_len - 1);
}
constexpr const _CharT*
data() const noexcept
{ return this->_M_str; }
// [string.view.modifiers], modifiers:
void
remove_prefix(size_type __n)
{
__glibcxx_assert(this->_M_len >= __n);
this->_M_str += __n;
this->_M_len -= __n;
}
void
remove_suffix(size_type __n)
{ this->_M_len -= __n; }
void
swap(basic_string_view& __sv) noexcept
{
std::swap(this->_M_len, __sv._M_len);
std::swap(this->_M_str, __sv._M_str);
}
// [string.view.ops], string operations:
size_type
copy(_CharT* __str, size_type __n, size_type __pos = 0) const
{
__glibcxx_requires_string_len(__str, __n);
if (__pos > this->_M_len)
__throw_out_of_range_fmt(__N("basic_string_view::copy: __pos "
"(which is %zu) > this->size() "
"(which is %zu)"),
__pos, this->size());
size_type __rlen{std::min(__n, size_type{this->_M_len - __pos})};
for (auto __begin = this->_M_str + __pos,
__end = __begin + __rlen; __begin != __end;)
*__str++ = *__begin++;
return __rlen;
}
// [string.view.ops], string operations:
constexpr basic_string_view
substr(size_type __pos, size_type __n=npos) const
{
return __pos <= this->_M_len
? basic_string_view{this->_M_str + __pos,
std::min(__n, size_type{this->_M_len - __pos})}
: (__throw_out_of_range_fmt(__N("basic_string_view::substr: __pos "
"(which is %zu) > this->size() "
"(which is %zu)"),
__pos, this->size()), basic_string_view{});
}
int
compare(basic_string_view __str) const noexcept
{
int __ret = traits_type::compare(this->_M_str, __str._M_str,
std::min(this->_M_len, __str._M_len));
if (__ret == 0)
__ret = _S_compare(this->_M_len, __str._M_len);
return __ret;
}
int
compare(size_type __pos1, size_type __n1, basic_string_view __str) const
{ return this->substr(__pos1, __n1).compare(__str); }
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
compare(const _CharT* __str) const noexcept
{ return this->compare(basic_string_view{__str}); }
int
compare(size_type __pos1, size_type __n1, const _CharT* __str) const
{ return this->substr(__pos1, __n1).compare(basic_string_view{__str}); }
int
compare(size_type __pos1, size_type __n1,
const _CharT* __str, size_type __n2) const
{
return this->substr(__pos1, __n1)
.compare(basic_string_view(__str, __n2));
}
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
find(_CharT __c, size_type __pos=0) const noexcept;
size_type
find(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
size_type
find(const _CharT* __str, size_type __pos=0) const noexcept
{ return this->find(__str, __pos, traits_type::length(__str)); }
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
rfind(_CharT __c, size_type __pos = npos) const noexcept;
size_type
rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
size_type
rfind(const _CharT* __str, size_type __pos = npos) const noexcept
{ return this->rfind(__str, __pos, traits_type::length(__str)); }
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
find_first_of(_CharT __c, size_type __pos = 0) const noexcept
{ return this->find(__c, __pos); }
size_type
find_first_of(const _CharT* __str, size_type __pos, size_type __n) const;
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
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
find_last_of(_CharT __c, size_type __pos=npos) const noexcept
{ return this->rfind(__c, __pos); }
size_type
find_last_of(const _CharT* __str, size_type __pos, size_type __n) const;
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
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
find_first_not_of(_CharT __c, size_type __pos = 0) const noexcept;
size_type
find_first_not_of(const _CharT* __str,
size_type __pos, size_type __n) const;
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
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
find_last_not_of(_CharT __c, size_type __pos = npos) const noexcept;
size_type
find_last_not_of(const _CharT* __str,
size_type __pos, size_type __n) const;
size_type
find_last_not_of(const _CharT* __str,
size_type __pos = npos) const noexcept
{
return this->find_last_not_of(__str, __pos,
traits_type::length(__str));
}
size_type
_M_check(size_type __pos, const char* __s) const
{
if (__pos > this->size())
__throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "
"this->size() (which is %zu)"),
__s, __pos, this->size());
return __pos;
}
// NB: _M_limit doesn't check for a bad __pos value.
size_type
_M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT
{
const bool __testoff = __off < this->size() - __pos;
return __testoff ? __off : this->size() - __pos;
}
private:
static constexpr const int
_S_compare(size_type __n1, size_type __n2) noexcept
{
return difference_type{__n1 - __n2} > std::numeric_limits<int>::max()
? std::numeric_limits<int>::max()
: difference_type{__n1 - __n2} < std::numeric_limits<int>::min()
? std::numeric_limits<int>::min()
: static_cast<int>(difference_type{__n1 - __n2});
}
size_t _M_len;
const _CharT* _M_str;
};
// [string.view.comparison], non-member basic_string_view comparison function
_GLIBCXX_END_NAMESPACE_VERSION
namespace __detail
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
// Identity transform to make ADL work with just one argument.
// See n3766.html.
template<typename _Tp = void>
struct __identity
{ typedef _Tp type; };
template<>
struct __identity<void>;
template<typename _Tp>
using __idt = typename __identity<_Tp>::type;
_GLIBCXX_END_NAMESPACE_VERSION
}
_GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _CharT, typename _Traits>
inline 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
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
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
operator!=(basic_string_view<_CharT, _Traits> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return !(__x == __y); }
template<typename _CharT, typename _Traits>
inline 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
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
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
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
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
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
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
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
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
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
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
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
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
operator>=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) >= 0; }
// [string.view.io], Inserters and extractors
template<typename _CharT, typename _Traits>
inline basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os,
basic_string_view<_CharT,_Traits> __str)
{ return __ostream_insert(__os, __str.data(), __str.size()); }
// basic_string_view typedef names
using string_view = basic_string_view<char>;
#ifdef _GLIBCXX_USE_WCHAR_T
using wstring_view = basic_string_view<wchar_t>;
#endif
#ifdef _GLIBCXX_USE_C99_STDINT_TR1
using u16string_view = basic_string_view<char16_t>;
using u32string_view = basic_string_view<char32_t>;
#endif
// [string.view.hash], hash support:
template<typename _Tp>
struct hash;
template<>
struct hash<string_view>
: public __hash_base<size_t, string_view>
{
size_t
operator()(const string_view& __str) const noexcept
{ return std::_Hash_impl::hash(__str.data(), __str.length()); }
};
template<>
struct __is_fast_hash<hash<string_view>> : std::false_type
{ };
#ifdef _GLIBCXX_USE_WCHAR_T
template<>
struct hash<wstring_view>
: public __hash_base<size_t, wstring>
{
size_t
operator()(const wstring_view& __s) const noexcept
{ return std::_Hash_impl::hash(__s.data(),
__s.length() * sizeof(wchar_t)); }
};
template<>
struct __is_fast_hash<hash<wstring_view>> : std::false_type
{ };
#endif
#ifdef _GLIBCXX_USE_C99_STDINT_TR1
template<>
struct hash<u16string_view>
: public __hash_base<size_t, u16string_view>
{
size_t
operator()(const u16string_view& __s) const noexcept
{ return std::_Hash_impl::hash(__s.data(),
__s.length() * sizeof(char16_t)); }
};
template<>
struct __is_fast_hash<hash<u16string_view>> : std::false_type
{ };
template<>
struct hash<u32string_view>
: public __hash_base<size_t, u32string_view>
{
size_t
operator()(const u32string_view& __s) const noexcept
{ return std::_Hash_impl::hash(__s.data(),
__s.length() * sizeof(char32_t)); }
};
template<>
struct __is_fast_hash<hash<u32string_view>> : std::false_type
{ };
#endif
_GLIBCXX_END_NAMESPACE_VERSION
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
#include <bits/string_view.tcc>
#endif // __cplusplus <= 201402L
#endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW

View File

@ -0,0 +1,39 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2016 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/>.
// [string.cons]
#include <string>
#include <testsuite_hooks.h>
void test02()
{
bool test __attribute__((unused)) = true;
std::string_view s("foo");
std::string s2(s);
VERIFY(s==s2);
}
int main()
{
test02();
return 0;
}

View File

@ -0,0 +1,39 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2016 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/>.
// [string.cons]
#include <string>
#include <testsuite_hooks.h>
void test02()
{
bool test __attribute__((unused)) = true;
std::wstring_view s(L"foo");
std::wstring s2(s);
VERIFY(s==s2);
}
int main()
{
test02();
return 0;
}

View File

@ -0,0 +1,45 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2016 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/>.
// [string.modifiers]
#include <string>
#include <testsuite_hooks.h>
void
test03()
{
bool test __attribute__((unused)) = true;
std::string_view str1("foo");
std::string str2;
str2 += str1;
VERIFY (str2 == str1);
std::string str3;
str3.append(str1);
VERIFY (str3 == str1);
std::string str4;
str4.append(str1, 1, 2);
VERIFY (str4 == "oo");
}
int main()
{
test03();
return 0;
}

View File

@ -0,0 +1,45 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2016 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/>.
// [string.modifiers]
#include <string>
#include <testsuite_hooks.h>
void
test03()
{
bool test __attribute__((unused)) = true;
std::wstring_view str1(L"foo");
std::wstring str2;
str2 += str1;
VERIFY (str2 == str1);
std::wstring str3;
str3.append(str1);
VERIFY (str3 == str1);
std::wstring str4;
str4.append(str1, 1, 2);
VERIFY (str4 == L"oo");
}
int main()
{
test03();
return 0;
}

View File

@ -0,0 +1,42 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2016 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/>.
// [string.modifiers]
#include <string>
#include <testsuite_hooks.h>
void
test03()
{
bool test __attribute__((unused)) = true;
std::string_view str1("foo");
std::string str2;
str2.assign(str1);
VERIFY (str2 == str1);
std::string str4;
str4.assign(str1, 1, 2);
VERIFY (str4 == "oo");
}
int main()
{
test03();
return 0;
}

View File

@ -0,0 +1,42 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2016 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/>.
// [string.modifiers]
#include <string>
#include <testsuite_hooks.h>
void
test03()
{
bool test __attribute__((unused)) = true;
std::wstring_view str1(L"foo");
std::wstring str2;
str2.assign(str1);
VERIFY (str2 == str1);
std::wstring str4;
str4.assign(str1, 1, 2);
VERIFY (str4 == L"oo");
}
int main()
{
test03();
return 0;
}

View File

@ -0,0 +1,46 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2016 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/>.
// [string.modifiers]
#include <string>
#include <testsuite_hooks.h>
void
test03()
{
bool test __attribute__((unused)) = true;
std::string_view str1("foo");
std::string str2;
str2.insert(0, str1);
VERIFY (str2 == str1);
str2.insert(3, str1);
VERIFY (str2 == "foofoo");
std::string str4{str1};
str4.insert(3, str1, 1, 2);
VERIFY (str4 == "foooo");
str4.insert(5, str1, 1, 2);
VERIFY (str4 == "foooooo");
}
int main()
{
test03();
return 0;
}

View File

@ -0,0 +1,46 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2016 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/>.
// [string.modifiers]
#include <string>
#include <testsuite_hooks.h>
void
test03()
{
bool test __attribute__((unused)) = true;
std::wstring_view str1(L"foo");
std::wstring str2;
str2.insert(0, str1);
VERIFY (str2 == str1);
str2.insert(3, str1);
VERIFY (str2 == L"foofoo");
std::wstring str4{str1};
str4.insert(3, str1, 1, 2);
VERIFY (str4 == L"foooo");
str4.insert(5, str1, 1, 2);
VERIFY (str4 == L"foooooo");
}
int main()
{
test03();
return 0;
}

View File

@ -0,0 +1,54 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2016 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/>.
// [string.modifiers]
#include <string>
#include <testsuite_hooks.h>
void
test03()
{
bool test __attribute__((unused)) = true;
std::string_view str1("foo");
std::string str2("bar");
str2.replace(0, 3, str1);
VERIFY (str2 == str1);
str2 = "foobar";
str2.replace(3, 3, str1);
VERIFY (str2 == "foofoo");
str2 = "foobar";
str2.replace(3, 3, str1, 0, 3);
VERIFY (str2 == "foofoo");
str2 = "foobar";
str2.replace(3, 1024, str1, 0, 3);
VERIFY (str2 == "foofoo");
str2 = "foobar";
str2.replace(3, 3, str1, 0, 1024);
VERIFY (str2 == "foofoo");
str2 = "foobar";
str2.replace(str2.begin()+3, str2.begin()+6, str1);
VERIFY (str2 == "foofoo");
}
int main()
{
test03();
return 0;
}

View File

@ -0,0 +1,54 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2016 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/>.
// [string.modifiers]
#include <string>
#include <testsuite_hooks.h>
void
test03()
{
bool test __attribute__((unused)) = true;
std::wstring_view str1(L"foo");
std::wstring str2(L"bar");
str2.replace(0, 3, str1);
VERIFY (str2 == str1);
str2 = L"foobar";
str2.replace(3, 3, str1);
VERIFY (str2 == L"foofoo");
str2 = L"foobar";
str2.replace(3, 3, str1, 0, 3);
VERIFY (str2 == L"foofoo");
str2 = L"foobar";
str2.replace(3, 1024, str1, 0, 3);
VERIFY (str2 == L"foofoo");
str2 = L"foobar";
str2.replace(3, 3, str1, 0, 1024);
VERIFY (str2 == L"foofoo");
str2 = L"foobar";
str2.replace(str2.begin()+3, str2.begin()+6, str1);
VERIFY (str2 == L"foofoo");
}
int main()
{
test03();
return 0;
}

View File

@ -0,0 +1,56 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2016 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/>.
// [string::compare]
#include <string>
#include <testsuite_hooks.h>
void
test03()
{
bool test __attribute__((unused)) = true;
std::string_view str1("foobar");
std::string str2("foobar");
auto x = str2.compare(str1);
VERIFY (x == 0);
str1 = "bar";
x = str2.compare(str1);
VERIFY (x > 0);
str1 = "foobar";
str2 = "bar";
x = str2.compare(str1);
VERIFY (x < 0);
x = str2.compare(0, 3, str1, 3, 3);
VERIFY (x == 0);
str1 = "bar";
str2 = "foobar";
x = str2.compare(3, 3, str1);
VERIFY (x == 0);
}
int main()
{
test03();
return 0;
}

View File

@ -0,0 +1,56 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2016 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/>.
// [string::compare]
#include <string>
#include <testsuite_hooks.h>
void
test03()
{
bool test __attribute__((unused)) = true;
std::wstring_view str1(L"foobar");
std::wstring str2(L"foobar");
auto x = str2.compare(str1);
VERIFY (x == 0);
str1 = L"bar";
x = str2.compare(str1);
VERIFY (x > 0);
str1 = L"foobar";
str2 = L"bar";
x = str2.compare(str1);
VERIFY (x < 0);
x = str2.compare(0, 3, str1, 3, 3);
VERIFY (x == 0);
str1 = L"bar";
str2 = L"foobar";
x = str2.compare(3, 3, str1);
VERIFY (x == 0);
}
int main()
{
test03();
return 0;
}

View File

@ -0,0 +1,88 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2016 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/>.
// [string::find]
// [string::rfind]
// [string::find.first.of]
// [string::find.last.of]
// [string::find.first.not.of]
// [string::find.last.not.of]
#include <string>
#include <testsuite_hooks.h>
void
test03()
{
bool test __attribute__((unused)) = true;
std::string_view str1("bar");
std::string str2("foobar");
auto x = str2.find(str1);
VERIFY (x == 3);
x = str2.find(str1, 1);
VERIFY (x == 3);
str2 = "barbar";
x = str2.rfind(str1);
VERIFY (x == 3);
x = str2.rfind(str1, 0);
VERIFY (x == 0);
x = str2.rfind(str1, 3);
VERIFY (x == 3);
str2 = "foobarxyz";
str1 = "zyx";
x = str2.find_first_of(str1);
VERIFY (x == 6);
str2 = "foobarxyzfooxyz";
x = str2.find_first_of(str1);
VERIFY (x == 6);
x = str2.find_first_of(str1, 9);
VERIFY (x == 12);
x = str2.find_last_of(str1);
VERIFY (x == 14);
x = str2.find_last_of(str1, 10);
VERIFY (x == 8);
str2 = "abcabcabcxxx";
str1 = "cba";
x = str2.find_first_not_of(str1);
VERIFY (x == 9);
str2 = "abcabcabcxxxabcabcxxx";
x = str2.find_first_not_of(str1, 12);
VERIFY (x == 18);
str1 = "x";
x = str2.find_last_not_of(str1);
VERIFY (x == 17);
x = str2.find_last_not_of(str1, 11);
VERIFY (x == 8);
}
int main()
{
test03();
return 0;
}

View File

@ -0,0 +1,88 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2016 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/>.
// [string::find]
// [string::rfind]
// [string::find.first.of]
// [string::find.last.of]
// [string::find.first.not.of]
// [string::find.last.not.of]
#include <string>
#include <testsuite_hooks.h>
void
test03()
{
bool test __attribute__((unused)) = true;
std::wstring_view str1(L"bar");
std::wstring str2(L"foobar");
auto x = str2.find(str1);
VERIFY (x == 3);
x = str2.find(str1, 1);
VERIFY (x == 3);
str2 = L"barbar";
x = str2.rfind(str1);
VERIFY (x == 3);
x = str2.rfind(str1, 0);
VERIFY (x == 0);
x = str2.rfind(str1, 3);
VERIFY (x == 3);
str2 = L"foobarxyz";
str1 = L"zyx";
x = str2.find_first_of(str1);
VERIFY (x == 6);
str2 = L"foobarxyzfooxyz";
x = str2.find_first_of(str1);
VERIFY (x == 6);
x = str2.find_first_of(str1, 9);
VERIFY (x == 12);
x = str2.find_last_of(str1);
VERIFY (x == 14);
x = str2.find_last_of(str1, 10);
VERIFY (x == 8);
str2 = L"abcabcabcxxx";
str1 = L"cba";
x = str2.find_first_not_of(str1);
VERIFY (x == 9);
str2 = L"abcabcabcxxxabcabcxxx";
x = str2.find_first_not_of(str1, 12);
VERIFY (x == 18);
str1 = L"x";
x = str2.find_last_not_of(str1);
VERIFY (x == 17);
x = str2.find_last_not_of(str1, 11);
VERIFY (x == 8);
}
int main()
{
test03();
return 0;
}

View File

@ -0,0 +1,41 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2016 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/>.
// [string.accessors]
#include <string>
#include <testsuite_hooks.h>
int test01(void)
{
bool test __attribute__((unused)) = true;
std::string_view str1("foo");;
std::string str2;
str2 = str1;
VERIFY( str1 == str2 );
return 0;
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,41 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2016 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/>.
// [string.accessors]
#include <string>
#include <testsuite_hooks.h>
int test01(void)
{
bool test __attribute__((unused)) = true;
std::wstring_view str1(L"foo");;
std::wstring str2;
str2 = str1;
VERIFY( str1 == str2 );
return 0;
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,164 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// string_view size, length
#include <string_view>
#include <cstring>
#include <testsuite_hooks.h>
template<typename T>
struct A { };
template<typename T>
bool
operator==(const A<T>&, const A<T>&) { return true; }
template<typename T>
bool
operator<(const A<T>&, const A<T>&) { return true; }
struct B { };
// char_traits specialization
namespace std
{
template<>
struct char_traits<A<B> >
{
typedef A<B> char_type;
// Unsigned as wint_t in unsigned.
typedef unsigned long int_type;
typedef streampos pos_type;
typedef streamoff off_type;
typedef mbstate_t state_type;
static void
assign(char_type& __c1, const char_type& __c2)
{ __c1 = __c2; }
static bool
eq(const char_type& __c1, const char_type& __c2)
{ return __c1 == __c2; }
static bool
lt(const char_type& __c1, const char_type& __c2)
{ return __c1 < __c2; }
static int
compare(const char_type* __s1, const char_type* __s2, size_t __n)
{
for (size_t __i = 0; __i < __n; ++__i)
if (!eq(__s1[__i], __s2[__i]))
return lt(__s1[__i], __s2[__i]) ? -1 : 1;
return 0;
}
static size_t
length(const char_type* __s)
{
const char_type* __p = __s;
while (__p)
++__p;
return (__p - __s);
}
static const char_type*
find(const char_type* __s, size_t __n, const char_type& __a)
{
for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p)
if (*__p == __a) return __p;
return 0;
}
static char_type*
move(char_type* __s1, const char_type* __s2, size_t __n)
{ return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); }
static char_type*
copy(char_type* __s1, const char_type* __s2, size_t __n)
{ return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); }
static char_type*
assign(char_type* __s, size_t __n, char_type __a)
{
for (char_type* __p = __s; __p < __s + __n; ++__p)
assign(*__p, __a);
return __s;
}
static char_type
to_char_type(const int_type&)
{ return char_type(); }
static int_type
to_int_type(const char_type&) { return int_type(); }
static bool
eq_int_type(const int_type& __c1, const int_type& __c2)
{ return __c1 == __c2; }
static int_type
eof() { return static_cast<int_type>(-1); }
static int_type
not_eof(const int_type& __c)
{ return eq_int_type(__c, eof()) ? int_type(0) : __c; }
};
} // namespace std
void
test01()
{
bool test [[gnu::unused]] = true;
std::basic_string_view<A<B>> str02;
typedef std::basic_string_view< A<B> >::size_type size_type_o;
size_type_o sz03;
size_type_o sz04;
// non-POD types: size, length, max_size, empty()
bool b01 = str02.empty();
VERIFY( b01 == true );
sz03 = str02.size();
sz04 = str02.length();
VERIFY( sz03 == sz04 );
str02.data();
sz03 = str02.size();
sz04 = str02.length();
VERIFY( sz03 == sz04 );
sz03 = str02.max_size();
VERIFY( sz03 >= sz04 );
sz03 = str02.size();
str02 = {};
b01 = str02.empty();
VERIFY( b01 == true );
sz04 = str02.size();
VERIFY( sz03 >= sz04 );
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,69 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view constructors.
#include <string_view>
#include <string>
#include <cstring>
#include <testsuite_hooks.h>
void
test01()
{
bool test [[gnu::unused]] = true;
typedef std::string_view::size_type csize_type;
// basic_string_view()
const std::string_view str00{};
VERIFY( str00.length() == 0 );
VERIFY( str00.data() == nullptr );
// basic_string_view(const char*)
const char str_lit01[] = "rodeo beach, marin";
const std::string_view str01{str_lit01};
VERIFY( str01.length() == 18 );
VERIFY( str01.data() == str_lit01 );
const std::string_view str02{"baker beach, san francisco"};
VERIFY( str02.length() == 26 );
// basic_string_view(const string_view&)
std::string_view str04{str01};
VERIFY( str04.length() == str01.length() );
VERIFY( str04.data() == str01.data() );
// basic_string_view(const char* s)
csize_type len_lit01 = strlen(str_lit01);
std::string_view str05{str_lit01, len_lit01};
VERIFY( str05.length() == len_lit01 );
VERIFY( str05.data() == str_lit01 );
// basic_string_view(basic_string& s)
std::string istr07(10, 'z');
std::string_view str07{istr07};
VERIFY( str07.length() == 10 );
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,48 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view constructors.
#include <new>
#include <string_view>
#include <stdexcept>
#include <testsuite_hooks.h>
void
test03()
{
bool test [[gnu::unused]] = true;
const char* with_nulls = "This contains \0 a zero byte.";
// These are tests to see how basic_string_view handles data with NUL
// bytes. Obviously basic_string_view(char*) will halt at the first one, but
// nothing else should.
std::string_view s1(with_nulls, 28);
VERIFY( s1.size() == 28 );
std::string_view s2(s1);
VERIFY( s2.size() == 28 );
}
int
main()
{
test03();
return 0;
}

View File

@ -0,0 +1,41 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view constructors.
#include <string_view>
#include <vector>
#include <testsuite_hooks.h>
void
test05()
{
bool test [[gnu::unused]] = true;
char const * s = 0;
std::string_view zero_length_built_with_NULL(s, 0);
}
int
main()
{
test05();
return 0;
}

View File

@ -0,0 +1,69 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view constructors.
#include <string_view>
#include <string>
#include <cwchar>
#include <testsuite_hooks.h>
void
test01()
{
bool test [[gnu::unused]] = true;
typedef std::wstring_view::size_type csize_type;
// basic_string_view()
const std::wstring_view str00{};
VERIFY( str00.length() == 0 );
VERIFY( str00.data() == nullptr );
// basic_string_view(const char*)
const wchar_t str_lit01[] = L"rodeo beach, marin";
const std::wstring_view str01{str_lit01};
VERIFY( str01.length() == 18 );
VERIFY( str01.data() == str_lit01 );
const std::wstring_view str02{L"baker beach, san francisco"};
VERIFY( str02.length() == 26 );
// basic_string_view(const string_view&)
std::wstring_view str04{str01};
VERIFY( str04.length() == str01.length() );
VERIFY( str04.data() == str01.data() );
// basic_string_view(const char* s)
csize_type len_lit01 = wcslen(str_lit01);
std::wstring_view str05{str_lit01, len_lit01};
VERIFY( str05.length() == len_lit01 );
VERIFY( str05.data() == str_lit01 );
// basic_string_view(basic_string& s)
std::wstring istr07(10, L'z');
std::wstring_view str07{istr07};
VERIFY( str07.length() == 10 );
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,46 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view constructors.
#include <string_view>
#include <testsuite_hooks.h>
void
test03()
{
bool test [[gnu::unused]] = true;
const wchar_t* with_nulls = L"This contains \0 a zero byte.";
// These are tests to see how basic_string_view handles data with NUL
// bytes. Obviously basic_string_view(char*) will halt at the first one, but
// nothing else should.
std::wstring_view s1 (with_nulls, 28);
VERIFY( s1.size() == 28 );
std::wstring_view s2 (s1);
VERIFY( s2.size() == 28 );
}
int
main()
{
test03();
return 0;
}

View File

@ -0,0 +1,40 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view constructors.
#include <string_view>
#include <testsuite_hooks.h>
void
test05()
{
bool test [[gnu::unused]] = true;
wchar_t const * s = 0;
std::wstring_view zero_length_built_with_NULL(s, 0);
}
int
main()
{
test05();
return 0;
}

View File

@ -0,0 +1,74 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string element access
#include <string_view>
#include <stdexcept>
#include <testsuite_hooks.h>
bool
test01()
{
bool test [[gnu::unused]] = true;
typedef std::string_view::size_type csize_type;
typedef std::string_view::const_reference cref;
typedef std::string_view::reference ref;
csize_type csz01, csz02;
const std::string_view str01("tamarindo, costa rica");
std::string_view str02("41st street beach, capitola, california");
std::string_view str03;
// const_reference operator[] (size_type pos) const;
csz01 = str01.size();
cref cref1 = str01[csz01 - 1];
VERIFY( cref1 == 'a' );
// Undefined behavior at size().
//cref cref2 = str01[csz01];
//VERIFY( cref2 == char() );
// const_reference at(size_type pos) const;
csz01 = str01.size();
cref cref3 = str01.at(csz01 - 1);
VERIFY( cref3 == 'a' );
try
{
str01.at(csz01);
VERIFY( false ); // Should not get here, as exception thrown.
}
catch (std::out_of_range& fail)
{
VERIFY( true );
}
catch (...)
{
VERIFY( false );
}
return test;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,30 @@
// { dg-do run { xfail *-*-* } }
// { dg-options "-std=gnu++17 -O0" }
// { dg-require-debug-mode "" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
int
main()
{
typedef std::string_view string_view_type;
string_view_type s;
s[0]; // abort
}

View File

@ -0,0 +1,40 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 3 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/>.
//
#include <string_view>
#include <testsuite_hooks.h>
int
main()
{
bool test [[gnu::unused]] = true;
{
std::string_view empty;
VERIFY( empty.empty() );
}
{
const std::string_view empty;
VERIFY( empty.empty() );
}
return 0;
}

View File

@ -0,0 +1,44 @@
// { dg-options "-std=gnu++17" }
// { dg-require-string-conversions "" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
#include <testsuite_hooks.h>
void
test01()
{
bool test [[gnu::unused]] = true;
std::string_view str("ramifications");
const std::string_view cstr("melodien");
VERIFY( str.front() == 'r' );
VERIFY( str.back() == 's' );
VERIFY( cstr.front() == 'm' );
VERIFY( cstr.back() == 'n' );
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,75 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view element access
#include <string_view>
#include <stdexcept>
#include <testsuite_hooks.h>
bool
test01()
{
bool test [[gnu::unused]] = true;
typedef std::wstring_view::size_type csize_type;
typedef std::wstring_view::const_reference cref;
typedef std::wstring_view::reference ref;
csize_type csz01, csz02;
const std::wstring_view str01(L"tamarindo, costa rica");
std::wstring_view str02(L"41st street beach, capitola, california");
std::wstring_view str03;
// const_reference operator[] (size_type pos) const;
csz01 = str01.size();
cref cref1 = str01[csz01 - 1];
VERIFY( cref1 == L'a' );
// Undefined behavior at size().
//cref cref2 = str01[csz01];
//VERIFY( cref2 == wchar_t() );
// const_reference at(size_type pos) const;
csz01 = str01.size();
cref cref3 = str01.at(csz01 - 1);
VERIFY( cref3 == L'a' );
try
{
str01.at(csz01);
VERIFY( false ); // Should not get here, as exception thrown.
}
catch (std::out_of_range& fail)
{
VERIFY( true );
}
catch (...)
{
VERIFY( false );
}
return test;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,32 @@
// { dg-do run { xfail *-*-* } }
// { dg-options "-std=gnu++17 -O0" }
// { dg-require-debug-mode "" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
// libstdc++/21674
// NB: Should work without any inlining or optimizations (ie. -O0).
int
main()
{
typedef std::wstring_view string_view_type;
string_view_type s;
s[0]; // abort
}

View File

@ -0,0 +1,40 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
//
#include <string_view>
#include <testsuite_hooks.h>
int
main()
{
bool test [[gnu::unused]] = true;
{
std::wstring_view empty;
VERIFY( empty.empty() );
}
{
const std::wstring_view empty;
VERIFY( empty.empty() );
}
return 0;
}

View File

@ -0,0 +1,44 @@
// { dg-options "-std=gnu++17" }
// { dg-require-string-conversions "" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
#include <testsuite_hooks.h>
void
test01()
{
bool test [[gnu::unused]] = true;
std::wstring_view str(L"ramifications");
const std::wstring_view cstr(L"melodien");
VERIFY( str.front() == L'r' );
VERIFY( str.back() == L's' );
VERIFY( cstr.front() == L'm' );
VERIFY( cstr.back() == L'n' );
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,25 @@
// -*- C++ -*-
// Copyright (C) 2013-2016 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/>.
// NB: This issue affected only debug-mode.
// { dg-options "-std=gnu++17 -fno-rtti" }
// { dg-do compile }
#include <string_view>

View File

@ -0,0 +1,69 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// inserters
// NB: This file is predicated on sstreams, istreams, and ostreams
// working, not to mention other major details like char_traits, and
// all of the string_view class.
#include <string_view>
#include <stdexcept>
#include <sstream>
#include <fstream>
#include <iostream>
#include <testsuite_hooks.h>
bool
test01()
{
bool test [[gnu::unused]] = true;
typedef std::string_view::size_type csize_type;
typedef std::string_view::const_reference cref;
typedef std::string_view::reference ref;
const std::string_view str01("sailing grand traverse bay\n"
"\t\t\t from Elk Rapids to the point reminds me of miles");
// ostream& operator<<(ostream&, const basic_string_view&)
std::ostringstream ostrs01;
try
{
ostrs01 << str01;
VERIFY( ostrs01.str() == str01 );
}
catch(std::exception& fail)
{
VERIFY( false );
}
std::string_view hello_world;
std::cout << hello_world;
return test;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,93 @@
// Copyright (C) 2013-2016 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/>.
// inserters
// NB: This file is predicated on sstreams, ostreams
// working, not to mention other major details like char_traits, and
// all of the string_view class.
// { dg-options "-std=gnu++17" }
// { dg-require-fileio "" }
#include <string_view>
#include <string>
#include <fstream>
#include <iostream>
#include <testsuite_hooks.h>
// testing basic_filebuf::xsputn via stress testing with large string_views
// based on a bug report libstdc++ 9
// mode == out
void
test05(std::size_t size)
{
bool test [[gnu::unused]] = true;
const char filename[] = "inserters_extractors-2.txt";
const char fillc = 'f';
std::ofstream ofs(filename);
std::string str(size, fillc);
std::string_view strv{str};
// sanity checks
VERIFY( str.size() == size );
VERIFY( ofs.good() );
// stress test
ofs << str << std::endl;
if (!ofs.good())
test = false;
ofs << str << std::endl;
if (!ofs.good())
test = false;
VERIFY( str.size() == size );
VERIFY( ofs.good() );
ofs.close();
// sanity check on the written file
std::ifstream ifs(filename);
std::size_t count = 0;
char c;
while (count <= (2 * size) + 4)
{
ifs >> c;
if (ifs.good() && c == fillc)
{
++count;
c = '0';
}
else
break;
}
VERIFY( count == 2 * size );
}
int
main()
{
test05(1);
test05(1000);
test05(10000);
return 0;
}

View File

@ -0,0 +1,56 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// inserters
// NB: This file is predicated on sstreams, and ostreams
// working, not to mention other major details like char_traits, and
// all of the string_view class.
#include <string_view>
#include <sstream>
#include <iomanip>
#include <testsuite_hooks.h>
// libstdc++/2830
void
test09()
{
bool test [[gnu::unused]] = true;
std::string_view foo{"peace\0\0\0& love"};
std::ostringstream oss1;
oss1 << foo;
VERIFY( oss1.str() == foo );
std::ostringstream oss2;
oss2.width(20);
oss2 << foo;
VERIFY( oss2.str() != foo );
VERIFY( oss2.str().size() == 20 );
}
int
main()
{
test09();
return 0;
}

View File

@ -0,0 +1,77 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// class basic_istream::sentry
#include <string_view>
#include <ostream>
#include <sstream>
#include <locale>
#include <typeinfo>
#include <testsuite_hooks.h>
#include <testsuite_character.h>
void
test01()
{
using namespace std;
using __gnu_test::pod_ushort;
typedef basic_string_view<pod_ushort> string_type;
typedef basic_stringbuf<pod_ushort> stringbuf_type;
typedef basic_ostream<pod_ushort> ostream_type;
bool test [[gnu::unused]] = true;
string_type str;
stringbuf_type strbuf01;
ostream_type stream(&strbuf01);
try
{
stream << str;
}
catch (std::bad_cast& obj)
{
// Ok, throws bad_cast because locale has no ctype facet.
}
catch (...)
{
VERIFY( false );
}
const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>);
stream.imbue(loc);
try
{
stream << str;
}
catch (...)
{
VERIFY( false );
}
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,74 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// inserters
// NB: This file is predicated on sstreams, and ostreams
// working, not to mention other major details like char_traits, and
// all of the string_view class.
#include <string_view>
#include <stdexcept>
#include <sstream>
#include <fstream>
#include <iostream>
#include <testsuite_hooks.h>
bool
test01()
{
bool test [[gnu::unused]] = true;
typedef std::wstring_view::size_type csize_type;
typedef std::wstring_view::const_reference cref;
typedef std::wstring_view::reference ref;
const std::wstring_view str01(L"sailing grand traverse bay\n"
L"\t\t\t from Elk Rapids to the point reminds me of miles");
const std::wstring_view str02(L"sailing");
const std::wstring_view str03(L"grand");
const std::wstring_view str04(L"traverse");
const std::wstring_view str05;
std::wstring_view str10;
// ostream& operator<<(ostream&, const basic_string_view&)
std::wostringstream ostrs01;
try
{
ostrs01 << str01;
VERIFY( ostrs01.str() == str01 );
}
catch(std::exception& fail)
{
VERIFY( false );
}
std::wstring_view hello_world;
std::wcout << hello_world;
return test;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,91 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// inserters
// NB: This file is predicated on sstreams, istreams, and ostreams
// working, not to mention other major details like char_traits, and
// all of the string_view class.
#include <string_view>
#include <string>
#include <fstream>
#include <iostream>
#include <testsuite_hooks.h>
// testing basic_filebuf::xsputn via stress testing with large string_views
// based on a bug report libstdc++ 9
// mode == out
void
test05(std::size_t size)
{
bool test [[gnu::unused]] = true;
const char filename[] = "inserters_extractors-2.txt";
const wchar_t fillc = L'f';
std::wofstream ofs(filename);
std::wstring str(size, fillc);
std::wstring_view strv(str);
// sanity checks
VERIFY( str.size() == size );
VERIFY( ofs.good() );
// stress test
ofs << str << std::endl;
if (!ofs.good())
test = false;
ofs << str << std::endl;
if (!ofs.good())
test = false;
VERIFY( str.size() == size );
VERIFY( ofs.good() );
ofs.close();
// sanity check on the written file
std::wifstream ifs(filename);
std::size_t count = 0;
wchar_t c;
while (count <= (2 * size) + 4)
{
ifs >> c;
if (ifs.good() && c == fillc)
{
++count;
c = '0';
}
else
break;
}
VERIFY( count == 2 * size );
}
int
main()
{
test05(1);
test05(1000);
test05(10000);
return 0;
}

View File

@ -0,0 +1,55 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// inserters
// NB: This file is predicated on sstreams, istreams, and ostreams
// working, not to mention other major details like char_traits, and
// all of the string_view class.
#include <string_view>
#include <sstream>
#include <iomanip>
#include <testsuite_hooks.h>
void
test09()
{
bool test [[gnu::unused]] = true;
std::wstring_view foo{L"peace\0\0\0& love"};
std::wostringstream oss1;
oss1 << foo;
VERIFY( oss1.str() == foo );
std::wostringstream oss2;
oss2.width(20);
oss2 << foo;
VERIFY( oss2.str() != foo );
VERIFY( oss2.str().size() == 20 );
}
int
main()
{
test09();
return 0;
}

View File

@ -0,0 +1,44 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
#include <testsuite_hooks.h>
void
test01()
{
bool test [[gnu::unused]] = true;
using std::string_view;
string_view str0{"olympus mons"};
string_view::pointer p = str0.data();
str0.remove_prefix(4);
VERIFY( str0.data() == p + 4);
VERIFY( str0.length() == 8 );
VERIFY( str0 == string_view{"pus mons"} );
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,44 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
#include <testsuite_hooks.h>
void
test01()
{
bool test [[gnu::unused]] = true;
using std::wstring_view;
wstring_view str0{L"olympus mons"};
wstring_view::pointer p = str0.data();
str0.remove_prefix(4);
VERIFY( str0.data() == p + 4);
VERIFY( str0.length() == 8 );
VERIFY( str0 == wstring_view{L"pus mons"} );
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,44 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
#include <testsuite_hooks.h>
void
test01()
{
bool test [[gnu::unused]] = true;
using std::string_view;
string_view str0{"olympus mons"};
string_view::pointer p = str0.data();
str0.remove_suffix(2);
VERIFY( str0.data() == p);
VERIFY( str0.length() == 10 );
VERIFY( str0 == string_view{"olympus mo"} );
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,44 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
#include <testsuite_hooks.h>
void
test01()
{
bool test [[gnu::unused]] = true;
using std::wstring_view;
wstring_view str0{L"olympus mons"};
wstring_view::pointer p = str0.data();
str0.remove_suffix(2);
VERIFY( str0.data() == p);
VERIFY( str0.length() == 10 );
VERIFY( str0 == wstring_view{L"olympus mo"} );
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,134 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view::compare
// int compare(const basic_string_view& str) const;
// int compare(size_type pos1, size_type n1, const basic_string_view& str) const;
// int compare(size_type pos1, size_type n1, const basic_string_view& str,
// size_type pos2, size_type n2) const;
// int compare(const charT* s) const;
// int compare(size_type pos1, size_type n1,
// const charT* s, size_type n2 = npos) const;
// NB compare should be thought of as a lexographical compare, ie how
// things would be sorted in a dictionary.
#include <string_view>
#include <cstring>
#include <testsuite_hooks.h>
enum want_value {lt=0, z=1, gt=2};
int
test_value(int result, want_value expected);
int
test_value(int result, want_value expected)
{
bool test [[gnu::unused]] = true;
bool pass = false;
switch (expected) {
case lt:
if (result < 0)
pass = true;
break;
case z:
if (!result)
pass = true;
break;
case gt:
if (result > 0)
pass = true;
break;
default:
pass = false; //should not get here
}
VERIFY(pass);
return 0;
}
int
test01()
{
using std::string_view;
string_view str_0("costa rica");
string_view str_1("costa marbella");
string_view str_2;
//sanity check
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);
test_value(strncmp(str_1.data(), str_0.data(), 6), z);
test_value(strncmp(str_1.data(), str_0.data(), 14), lt);
test_value(memcmp(str_1.data(), str_0.data(), 6), z);
test_value(memcmp(str_1.data(), str_0.data(), 14), lt);
test_value(memcmp("costa marbella", "costa rica", 14), lt);
// int compare(const basic_string_view& str) const;
test_value(str_0.compare(str_1), gt); //because r>m
test_value(str_1.compare(str_0), lt); //because m<r
str_2 = str_0;
test_value(str_2.compare(str_0), z);
str_2 = "cost";
test_value(str_2.compare(str_0), lt);
str_2 = "costa ricans";
test_value(str_2.compare(str_0), gt);
// int compare(size_type pos1, size_type n1, const basic_string_view& str) const;
test_value(str_1.compare(0, 6, str_0), lt);
str_2 = "cost";
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;
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);
// int compare(const charT* s) const;
test_value(str_0.compare("costa marbella"), gt);
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);
// 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);
return 0;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,51 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view::compare [lib.string_view::compare]
#include <string_view>
#include <testsuite_hooks.h>
// libstdc++/13650
void
test01()
{
bool test [[gnu::unused]] = true;
using std::string_view;
const char lit_01[]{ 'w', 'e', '\0', 'r', 'd' };
const char lit_02[]{ 'w', 'e', 'i', '\0', 'd' };
const char lit_ref_a[]{ 'w', 'e', '\0', 'q', 'd' };
const string_view str_a(lit_ref_a, 5);
VERIFY( str_a.compare(0, 5, lit_01, 5) < 0 );
const char lit_ref_b[]{ 'w', 'e', 'i' };
const string_view str_b(lit_ref_b, 3);
VERIFY( str_b.compare(0, 3, lit_02, 5) < 0 );
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,134 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view::compare
// int compare(const basic_string_view& str) const;
// int compare(size_type pos1, size_type n1, const basic_string_view& str) const;
// int compare(size_type pos1, size_type n1, const basic_string_view& str,
// size_type pos2, size_type n2) const;
// int compare(const charT* s) const;
// int compare(size_type pos1, size_type n1,
// const charT* s, size_type n2 = npos) const;
// NB compare should be thought of as a lexographical compare, ie how
// things would be sorted in a dictionary.
#include <string_view>
#include <testsuite_hooks.h>
enum want_value {lt=0, z=1, gt=2};
int
test_value(int result, want_value expected);
int
test_value(int result, want_value expected)
{
bool test [[gnu::unused]] = true;
bool pass = false;
switch (expected) {
case lt:
if (result < 0)
pass = true;
break;
case z:
if (!result)
pass = true;
break;
case gt:
if (result > 0)
pass = true;
break;
default:
pass = false; //should not get here
}
VERIFY(pass);
return 0;
}
int
test01()
{
using std::wstring_view;
wstring_view str_0(L"costa rica");
wstring_view str_1(L"costa marbella");
wstring_view str_2;
//sanity check
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);
test_value(wcsncmp(str_1.data(), str_0.data(), 6), z);
test_value(wcsncmp(str_1.data(), str_0.data(), 14), lt);
test_value(wmemcmp(str_1.data(), str_0.data(), 6), z);
test_value(wmemcmp(str_1.data(), str_0.data(), 14), lt);
test_value(wmemcmp(L"costa marbella", L"costa rica", 14), lt);
// int compare(const basic_string_view& str) const;
test_value(str_0.compare(str_1), gt); //because r>m
test_value(str_1.compare(str_0), lt); //because m<r
str_2 = str_0;
test_value(str_2.compare(str_0), z);
str_2 = L"cost";
test_value(str_2.compare(str_0), lt);
str_2 = L"costa ricans";
test_value(str_2.compare(str_0), gt);
// int compare(size_type pos1, size_type n1, const basic_string_view& str) const;
test_value(str_1.compare(0, 6, str_0), lt);
str_2 = L"cost";
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;
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);
// int compare(const charT* s) const;
test_value(str_0.compare(L"costa marbella"), gt);
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);
// 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);
return 0;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,51 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view::compare [lib.string_view::compare]
#include <string_view>
#include <testsuite_hooks.h>
// libstdc++/13650
void
test01()
{
bool test [[gnu::unused]] = true;
using std::wstring_view;
const wchar_t lit_01[] = { L'w', L'e', L'\0', L'r', L'd' };
const wchar_t lit_02[] = { L'w', L'e', L'i', L'\0', L'd' };
const wchar_t lit_ref_a[] = { L'w', L'e', L'\0', L'q', L'd' };
const wstring_view str_a(lit_ref_a, 5);
VERIFY( str_a.compare(0, 5, lit_01, 5) < 0 );
const wchar_t lit_ref_b[] = { L'w', L'e', L'i' };
const wstring_view str_b(lit_ref_b, 3);
VERIFY( str_b.compare(0, 3, lit_02, 5) < 0 );
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,49 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view::copy
#include <string_view>
#include <testsuite_hooks.h>
bool
test01()
{
bool test [[gnu::unused]] = true;
typedef std::string_view::size_type csize_type;
const char str_lit01[] = "123456789A";
const std::string_view str01(str_lit01);
char buffer[4] = { 0 };
csize_type len = str01.copy(buffer, sizeof(buffer), 8);
VERIFY( 2 == len );
VERIFY( '9' == buffer[0] );
return test;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,50 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view::copy
#include <string_view>
#include <testsuite_hooks.h>
bool
test01()
{
bool test [[gnu::unused]] = true;
typedef std::wstring_view::size_type csize_type;
csize_type csz01;
const wchar_t str_lit01[] = L"123456789A";
const std::wstring_view str01(str_lit01);
wchar_t buffer[4] = { 0 };
csize_type len = str01.copy(buffer, sizeof(buffer), 8);
VERIFY( 2 == len );
VERIFY( L'9' == buffer[0] );
return test;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,45 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2014 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/>.
// string_view operations
#include <string_view>
#include <testsuite_hooks.h>
int
test01()
{
bool test [[gnu::unused]] = true;
std::string_view empty;
VERIFY( empty.size() == 0 );
const std::string_view::value_type* p = empty.data();
VERIFY( p == nullptr );
return 0;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,45 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2014 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/>.
// string_view operations
#include <string_view>
#include <testsuite_hooks.h>
int
test01()
{
bool test [[gnu::unused]] = true;
std::wstring_view empty;
VERIFY( empty.size() == 0 );
const std::wstring_view::value_type* p = empty.data();
VERIFY( p == nullptr );
return 0;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,98 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view find
#include <string_view>
#include <testsuite_hooks.h>
bool
test01()
{
bool test [[gnu::unused]] = true;
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, csz02;
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;
// 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 test;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,97 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view find_first_of
#include <string_view>
#include <testsuite_hooks.h>
bool
test02()
{
bool test [[gnu::unused]] = true;
typedef std::string_view::size_type csize_type;
csize_type npos = std::string_view::npos;
csize_type csz01, csz02;
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;
// 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 test;
}
int
main()
{
test02();
return 0;
}

View File

@ -0,0 +1,97 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view find_first_not_of
#include <string_view>
#include <testsuite_hooks.h>
bool
test03()
{
bool test [[gnu::unused]] = true;
typedef std::string_view::size_type csize_type;
csize_type npos = std::string_view::npos;
csize_type csz01;
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;
// 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 test;
}
int
main()
{
test03();
return 0;
}

View File

@ -0,0 +1,46 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view find
#include <string_view>
#include <testsuite_hooks.h>
// libstdc++/31401
void
test01()
{
bool test [[gnu::unused]] = true;
typedef std::string_view::size_type csize_type;
csize_type npos = std::string_view::npos;
std::string_view use = "anu";
csize_type pos1 = use.find("a", npos);
VERIFY( pos1 == npos );
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,98 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view find
#include <string_view>
#include <testsuite_hooks.h>
bool
test01()
{
bool test [[gnu::unused]] = true;
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, csz02;
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;
// 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 test;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,97 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view find_first_of
#include <string_view>
#include <testsuite_hooks.h>
bool
test02()
{
bool test [[gnu::unused]] = true;
typedef std::wstring_view::size_type csize_type;
csize_type npos = std::wstring_view::npos;
csize_type csz01, csz02;
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;
// 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 test;
}
int
main()
{
test02();
return 0;
}

View File

@ -0,0 +1,97 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view find_first_not_of
#include <string_view>
#include <testsuite_hooks.h>
bool
test03()
{
bool test [[gnu::unused]] = true;
typedef std::wstring_view::size_type csize_type;
csize_type npos = std::wstring_view::npos;
csize_type csz01;
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;
// 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 test;
}
int
main()
{
test03();
return 0;
}

View File

@ -0,0 +1,46 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view find
#include <string_view>
#include <testsuite_hooks.h>
// libstdc++/31401
void
test01()
{
bool test [[gnu::unused]] = true;
typedef std::wstring_view::size_type csize_type;
csize_type npos = std::wstring_view::npos;
std::wstring_view use = L"anu";
csize_type pos1 = use.find(L"a", npos);
VERIFY( pos1 == npos );
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,98 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
#include <testsuite_hooks.h>
// basic_string_view rfind
bool
test01()
{
bool test [[gnu::unused]] = true;
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, csz02;
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;
// size_type rfind(const string_view&, size_type pos = 0) const;
csz01 = str01.rfind(str01);
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str01, 4);
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str02,3);
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str02);
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str03);
VERIFY( csz01 == 8 );
csz01 = str01.rfind(str03, 3);
VERIFY( csz01 == npos );
csz01 = str01.rfind(str03, 12);
VERIFY( csz01 == 8 );
// 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.rfind(str04, 0);
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str04, 5);
VERIFY( csz01 == 5 );
csz01 = str01.rfind(str04, str01.size());
VERIFY( csz01 == str01.size() );
csz01 = str01.rfind(str04, str01.size()+1);
VERIFY( csz01 == str01.size() );
// size_type rfind(const char* s, size_type pos, size_type n) const;
csz01 = str01.rfind(str_lit01, 0, 3);
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str_lit01, 3, 0);
VERIFY( csz01 == 3 );
// size_type rfind(const char* s, size_type pos = 0) const;
csz01 = str01.rfind(str_lit01);
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str_lit01, 3);
VERIFY( csz01 == 0 );
// size_type rfind(char c, size_type pos = 0) const;
csz01 = str01.rfind('z');
csz02 = str01.size() - 1;
VERIFY( csz01 == csz02 );
csz01 = str01.rfind('/');
VERIFY( csz01 == npos );
return test;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,57 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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.
// { dg-options "-std=gnu++17" }
// 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/>.
#include <string_view>
#include <testsuite_hooks.h>
// basic_string_view::find_last_of
bool
test02()
{
bool test [[gnu::unused]] = true;
std::string_view z("ab");
std::string_view::size_type pos;
pos = z.find_last_of("ab");
VERIFY( pos == 1 );
pos = z.find_last_of("Xa");
VERIFY( pos == 0 );
pos = z.find_last_of("Xb");
VERIFY( pos == 1 );
pos = z.find_last_of("XYZ");
VERIFY( pos == std::string_view::npos );
pos = z.find_last_of('a');
VERIFY( pos == 0 );
pos = z.find_last_of('b');
VERIFY( pos == 1 );
pos = z.find_last_of('X');
VERIFY( pos == std::string_view::npos );
return test;
}
int
main()
{
test02();
return 0;
}

View File

@ -0,0 +1,70 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
#include <testsuite_hooks.h>
// basic_string_view::find_last_not_of
bool
test03()
{
bool test [[gnu::unused]] = true;
typedef std::string_view::size_type csize_type;
std::string_view::size_type pos;
csize_type npos = std::string_view::npos;
std::string_view x;
pos = x.find_last_not_of('X');
VERIFY( pos == npos );
pos = x.find_last_not_of("XYZ");
VERIFY( pos == npos );
std::string_view y("a");
pos = y.find_last_not_of('X');
VERIFY( pos == 0 );
pos = y.find_last_not_of('a');
VERIFY( pos == npos );
pos = y.find_last_not_of("XYZ");
VERIFY( pos == 0 );
pos = y.find_last_not_of("a");
VERIFY( pos == npos );
std::string_view z("ab");
pos = z.find_last_not_of('X');
VERIFY( pos == 1 );
pos = z.find_last_not_of("XYZ");
VERIFY( pos == 1 );
pos = z.find_last_not_of('b');
VERIFY( pos == 0 );
pos = z.find_last_not_of("Xb");
VERIFY( pos == 0 );
pos = z.find_last_not_of("Xa");
VERIFY( pos == 1 );
return test;
}
int
main()
{
test03();
return 0;
}

View File

@ -0,0 +1,98 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
#include <testsuite_hooks.h>
// basic_string_view rfind
bool
test01()
{
bool test [[gnu::unused]] = true;
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, csz02;
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;
// size_type rfind(const wstring_view&, size_type pos = 0) const;
csz01 = str01.rfind(str01);
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str01, 4);
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str02,3);
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str02);
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str03);
VERIFY( csz01 == 8 );
csz01 = str01.rfind(str03, 3);
VERIFY( csz01 == npos );
csz01 = str01.rfind(str03, 12);
VERIFY( csz01 == 8 );
// 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.rfind(str04, 0);
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str04, 5);
VERIFY( csz01 == 5 );
csz01 = str01.rfind(str04, str01.size());
VERIFY( csz01 == str01.size() );
csz01 = str01.rfind(str04, str01.size()+1);
VERIFY( csz01 == str01.size() );
// size_type rfind(const wchar_t* s, size_type pos, size_type n) const;
csz01 = str01.rfind(str_lit01, 0, 3);
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str_lit01, 3, 0);
VERIFY( csz01 == 3 );
// size_type rfind(const wchar_t* s, size_type pos = 0) const;
csz01 = str01.rfind(str_lit01);
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str_lit01, 3);
VERIFY( csz01 == 0 );
// size_type rfind(wchar_t c, size_type pos = 0) const;
csz01 = str01.rfind(L'z');
csz02 = str01.size() - 1;
VERIFY( csz01 == csz02 );
csz01 = str01.rfind(L'/');
VERIFY( csz01 == npos );
return test;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,56 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
#include <testsuite_hooks.h>
// basic_string_view::find_last_of
bool
test02()
{
bool test [[gnu::unused]] = true;
std::wstring_view::size_type pos;
std::wstring_view z(L"ab");
pos = z.find_last_of(L"ab");
VERIFY( pos == 1 );
pos = z.find_last_of(L"Xa");
VERIFY( pos == 0 );
pos = z.find_last_of(L"Xb");
VERIFY( pos == 1 );
pos = z.find_last_of(L"XYZ");
VERIFY( pos == std::wstring_view::npos );
pos = z.find_last_of(L'a');
VERIFY( pos == 0 );
pos = z.find_last_of(L'b');
VERIFY( pos == 1 );
pos = z.find_last_of(L'X');
VERIFY( pos == std::wstring_view::npos );
return test;
}
int
main()
{
test02();
return 0;
}

View File

@ -0,0 +1,70 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
#include <testsuite_hooks.h>
// basic_string_view::find_last_not_of
bool
test03()
{
bool test [[gnu::unused]] = true;
typedef std::wstring_view::size_type csize_type;
std::wstring_view::size_type pos;
csize_type npos = std::wstring_view::npos;
std::wstring_view x;
pos = x.find_last_not_of(L'X');
VERIFY( pos == npos );
pos = x.find_last_not_of(L"XYZ");
VERIFY( pos == npos );
std::wstring_view y(L"a");
pos = y.find_last_not_of(L'X');
VERIFY( pos == 0 );
pos = y.find_last_not_of(L'a');
VERIFY( pos == npos );
pos = y.find_last_not_of(L"XYZ");
VERIFY( pos == 0 );
pos = y.find_last_not_of(L"a");
VERIFY( pos == npos );
std::wstring_view z(L"ab");
pos = z.find_last_not_of(L'X');
VERIFY( pos == 1 );
pos = z.find_last_not_of(L"XYZ");
VERIFY( pos == 1 );
pos = z.find_last_not_of(L'b');
VERIFY( pos == 0 );
pos = z.find_last_not_of(L"Xb");
VERIFY( pos == 0 );
pos = z.find_last_not_of(L"Xa");
VERIFY( pos == 1 );
return test;
}
int
main()
{
test03();
return 0;
}

View File

@ -0,0 +1,55 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2014-2016 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/>.
// basic_string_view::to_string
#include <string_view>
#include <string>
#include <algorithm>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
bool
test01()
{
bool test [[gnu::unused]] = true;
const char str_lit[] = "123456789A";
const std::string_view sv(str_lit);
char buffer[4] = { 0 };
std::string s1{sv};
VERIFY( s1 == str_lit );
using test_alloc = __gnu_test::tracker_allocator<char>;
std::basic_string<char, std::char_traits<char>, test_alloc>
s2{sv, test_alloc{}};
static_assert( std::is_same<decltype(s2)::allocator_type, test_alloc>::value,
"to_string() uses custom allocator" );
VERIFY( std::equal(s1.begin(), s1.end(), s2.begin(), s2.end()) );
auto s3 = static_cast<std::string>(sv);
VERIFY( s3 == s1 );
return test;
}
int
main()
{
test01();
}

View File

@ -0,0 +1,83 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view::substr
#include <string_view>
#include <stdexcept>
#include <testsuite_hooks.h>
bool
test01()
{
bool test [[gnu::unused]] = true;
typedef std::string_view::size_type csize_type;
typedef std::string_view::const_reference cref;
typedef std::string_view::reference ref;
csize_type csz01;
const char str_lit01[] = "rockaway, pacifica";
const std::string_view str01(str_lit01);
std::string_view str02;
// basic_string_view<charT, _Traits, _Alloc>
// substr(size_type pos = 0, size_type n = npos) const;
csz01 = str01.size();
str02 = str01.substr(0, 1);
VERIFY( str02 == "r" );
str02 = str01.substr(10);
VERIFY( str02 == "pacifica" );
try
{
str02 = str01.substr(csz01 + 1);
VERIFY( false );
}
catch(std::out_of_range& fail)
{
VERIFY( true );
}
catch(...)
{
VERIFY( false );
}
try
{
str02 = str01.substr(csz01);
VERIFY( str02.size() == 0 );
VERIFY( str02.begin() == str01.end() );
VERIFY( true );
}
catch(...)
{
VERIFY( false );
}
return test;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,83 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view::substr
#include <string_view>
#include <stdexcept>
#include <testsuite_hooks.h>
bool
test01()
{
bool test [[gnu::unused]] = true;
typedef std::wstring_view::size_type csize_type;
typedef std::wstring_view::const_reference cref;
typedef std::wstring_view::reference ref;
csize_type csz01;
const wchar_t str_lit01[] = L"rockaway, pacifica";
const std::wstring_view str01(str_lit01);
std::wstring_view str02;
// basic_string_view<charT, _Traits, _Alloc>
// substr(size_type pos = 0, size_type n = npos) const;
csz01 = str01.size();
str02 = str01.substr(0, 1);
VERIFY( str02 == L"r" );
str02 = str01.substr(10);
VERIFY( str02 == L"pacifica" );
try
{
str02 = str01.substr(csz01 + 1);
VERIFY( false );
}
catch(std::out_of_range& fail)
{
VERIFY( true );
}
catch(...)
{
VERIFY( false );
}
try
{
str02 = str01.substr(csz01);
VERIFY( str02.size() == 0 );
VERIFY( str02.begin() == str01.end() );
VERIFY( true );
}
catch(...)
{
VERIFY( false );
}
return test;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,246 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string non-member functions
// operator==
/*
template<class charT, class traits, class Allocator>
bool operator==(const basic_string<charT,traits,Allocator>& lhs,
const basic_string<charT,traits,Allocator>& rhs);
template<class charT, class traits, class Allocator>
bool operator==(const charT* lhs,
const basic_string<charT,traits,Allocator>& rhs);
template<class charT, class traits, class Allocator>
bool operator==(const basic_string<charT,traits,Allocator>& lhs,
const charT* rhs);
*/
// operator!=
/*
template<class charT, class traits, class Allocator>
bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
const basic_string<charT,traits,Allocator>& rhs);
template<class charT, class traits, class Allocator>
bool operator!=(const charT* lhs,
const basic_string<charT,traits,Allocator>& rhs);
template<class charT, class traits, class Allocator>
bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
const charT* rhs);
*/
// operator<
/*
template<class charT, class traits, class Allocator>
bool operator< (const basic_string<charT,traits,Allocator>& lhs,
const basic_string<charT,traits,Allocator>& rhs);
template<class charT, class traits, class Allocator>
bool operator< (const basic_string<charT,traits,Allocator>& lhs,
const charT* rhs);
template<class charT, class traits, class Allocator>
bool operator< (const charT* lhs,
const basic_string<charT,traits,Allocator>& rhs);
*/
// operator>
/*
template<class charT, class traits, class Allocator>
bool operator> (const basic_string<charT,traits,Allocator>& lhs,
const basic_string<charT,traits,Allocator>& rhs);
template<class charT, class traits, class Allocator>
bool operator> (const basic_string<charT,traits,Allocator>& lhs,
const charT* rhs);
template<class charT, class traits, class Allocator>
bool operator> (const charT* lhs,
const basic_string<charT,traits,Allocator>& rhs);
*/
// operator<=
/*
template<class charT, class traits, class Allocator>
bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
const basic_string<charT,traits,Allocator>& rhs);
template<class charT, class traits, class Allocator>
bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
const charT* rhs);
template<class charT, class traits, class Allocator>
bool operator<=(const charT* lhs,
const basic_string<charT,traits,Allocator>& rhs);
*/
// operator>=
/*
template<class charT, class traits, class Allocator>
bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
const basic_string<charT,traits,Allocator>& rhs);
template<class charT, class traits, class Allocator>
bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
const charT* rhs);
template<class charT, class traits, class Allocator>
bool operator>=(const charT* lhs,
const basic_string<charT,traits,Allocator>& rhs);
*/
#include <string_view>
#include <testsuite_hooks.h>
int
test01()
{
bool test [[gnu::unused]] = true;
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;
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) );
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" );
return 0;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,246 @@
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// basic_string_view non-member functions
// operator==
/*
template<class charT, class traits, class Allocator>
bool operator==(const basic_string_view<charT,traits,Allocator>& lhs,
const basic_string_view<charT,traits,Allocator>& rhs);
template<class charT, class traits, class Allocator>
bool operator==(const charT* lhs,
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,
const charT* rhs);
*/
// operator!=
/*
template<class charT, class traits, class Allocator>
bool operator!=(const basic_string_view<charT,traits,Allocator>& lhs,
const basic_string_view<charT,traits,Allocator>& rhs);
template<class charT, class traits, class Allocator>
bool operator!=(const charT* lhs,
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,
const charT* rhs);
*/
// operator<
/*
template<class charT, class traits, class Allocator>
bool operator< (const basic_string_view<charT,traits,Allocator>& lhs,
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,
const charT* rhs);
template<class charT, class traits, class Allocator>
bool operator< (const charT* lhs,
const basic_string_view<charT,traits,Allocator>& rhs);
*/
// operator>
/*
template<class charT, class traits, class Allocator>
bool operator> (const basic_string_view<charT,traits,Allocator>& lhs,
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,
const charT* rhs);
template<class charT, class traits, class Allocator>
bool operator> (const charT* lhs,
const basic_string_view<charT,traits,Allocator>& rhs);
*/
// operator<=
/*
template<class charT, class traits, class Allocator>
bool operator<=(const basic_string_view<charT,traits,Allocator>& lhs,
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,
const charT* rhs);
template<class charT, class traits, class Allocator>
bool operator<=(const charT* lhs,
const basic_string_view<charT,traits,Allocator>& rhs);
*/
// operator>=
/*
template<class charT, class traits, class Allocator>
bool operator>=(const basic_string_view<charT,traits,Allocator>& lhs,
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,
const charT* rhs);
template<class charT, class traits, class Allocator>
bool operator>=(const charT* lhs,
const basic_string_view<charT,traits,Allocator>& rhs);
*/
#include <string_view>
#include <testsuite_hooks.h>
int
test01()
{
bool test [[gnu::unused]] = true;
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;
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) );
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" );
return 0;
}
int
main()
{
test01();
return 0;
}

View File

@ -0,0 +1,31 @@
// { dg-do compile }
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// 24.6.5, range access [iterator.range]
#include <string_view>
void
test01()
{
std::string_view s("Hello, World!");
std::begin(s);
std::end(s);
}

View File

@ -0,0 +1,33 @@
// { dg-do compile }
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
// 24.6.5, 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
}

View File

@ -0,0 +1,26 @@
// Copyright (C) 2013-2016 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/>.
// This file tests explicit instantiation of basic_string
#include <string_view>
// { dg-do compile }
// { dg-options "-std=gnu++17" }
template class std::basic_string_view<int, std::char_traits<int>>;

View File

@ -0,0 +1,23 @@
// { dg-do compile }
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
template class std::basic_string_view<char>;

View File

@ -0,0 +1,24 @@
// { dg-do compile }
// { dg-options "-std=gnu++17" }
// { dg-require-cstdint "" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
template class std::basic_string_view<char16_t>;

View File

@ -0,0 +1,24 @@
// { dg-do compile }
// { dg-options "-std=gnu++17" }
// { dg-require-cstdint "" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
template class std::basic_string_view<char32_t>;

View File

@ -0,0 +1,23 @@
// { dg-do compile }
// { dg-options "-std=gnu++17" }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
template class std::basic_string_view<wchar_t>;

View File

@ -0,0 +1,47 @@
// { dg-options "-std=gnu++17" }
// { dg-do compile }
// Copyright (C) 2013-2016 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/>.
#include <string_view>
#include <testsuite_containers.h>
namespace __gnu_test
{
template<typename _Tp1, typename _Tp2>
struct traits<std::basic_string_view<_Tp1, _Tp2>> : public traits_base
{
typedef std::true_type is_container;
typedef std::true_type is_reversible;
};
}
#include <testsuite_containers.h>
// Check container for required typedefs.
__gnu_test::basic_types<std::string_view> t1b;
__gnu_test::reversible_types<std::string_view> t1r;
typedef typename std::string_view::traits_type traits_type1;
#ifdef _GLIBCXX_USE_WCHAR_T
__gnu_test::basic_types<std::wstring_view> t2b;
__gnu_test::reversible_types<std::wstring_view> t2r;
typedef typename std::wstring_view::traits_type traits_type2;
#endif

View File

@ -0,0 +1,36 @@
// { dg-options "-std=gnu++17" }
// { dg-do compile }
// Copyright (C) 2014-2016 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 moved_to of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <string_view>
template<typename C, typename T>
using check1_t = std::basic_string_view<C, T>;
using check2_t = std::string_view;
#ifdef _GLIBCXX_USE_C99_STDINT_TR1
using check3_t = std::u16string_view;
using check4_t = std::u32string_view;
#endif
#ifdef _GLIBCXX_USE_WCHAR_T
using check5_t = std::wstring_view;
#endif

View File

@ -0,0 +1,43 @@
//
// Copyright (C) 2013-2016 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 }
#include <string_view>
struct T
{
typedef std::string_view String_view;
typedef String_view::iterator iterator;
typedef String_view::const_iterator const_iterator;
char t(iterator f) { return *f; }
char t(const_iterator f) const { return *f; }
};
void
f()
{
std::string_view s;
T t;
T::const_iterator i = s.begin();
t.t(i);
}