1// { dg-options "-std=gnu++17" } 2 3// Copyright (C) 2013-2023 Free Software Foundation, Inc. 4// 5// This file is part of the GNU ISO C++ Library. This library is free 6// software; you can redistribute it and/or modify it under the 7// terms of the GNU General Public License as published by the 8// Free Software Foundation; either version 3, or (at your option) 9// any later version. 10 11// This library is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14// GNU General Public License for more details. 15 16// You should have received a copy of the GNU General Public License along 17// with this library; see the file COPYING3. If not see 18// <http://www.gnu.org/licenses/>. 19 20// string_view size, length 21 22namespace capacity_1 { 23 24template<typename T> 25 struct A { }; 26 27template<typename T> 28 bool 29 operator==(const A<T>&, const A<T>&) { return true; } 30 31template<typename T> 32 bool 33 operator<(const A<T>&, const A<T>&) { return true; } 34 35struct B { }; 36 37} // namespace capacity_1 38} // namespace string_view 39} // namespace selftests 40 41// char_traits specialization 42namespace std 43{ 44 template<> 45 struct char_traits<selftests::string_view::capacity_1::A< 46 selftests::string_view::capacity_1::B> > 47 { 48 typedef selftests::string_view::capacity_1::A< 49 selftests::string_view::capacity_1::B> char_type; 50 // Unsigned as wint_t in unsigned. 51 typedef unsigned long int_type; 52 typedef streampos pos_type; 53 typedef streamoff off_type; 54 typedef mbstate_t state_type; 55 56 static void 57 assign(char_type& __c1, const char_type& __c2) 58 { __c1 = __c2; } 59 60 static bool 61 eq(const char_type& __c1, const char_type& __c2) 62 { return __c1 == __c2; } 63 64 static bool 65 lt(const char_type& __c1, const char_type& __c2) 66 { return __c1 < __c2; } 67 68 static int 69 compare(const char_type* __s1, const char_type* __s2, size_t __n) 70 { 71 for (size_t __i = 0; __i < __n; ++__i) 72 if (!eq(__s1[__i], __s2[__i])) 73 return lt(__s1[__i], __s2[__i]) ? -1 : 1; 74 return 0; 75 } 76 77 static size_t 78 length(const char_type* __s) 79 { 80 const char_type* __p = __s; 81 while (__p) 82 ++__p; 83 return (__p - __s); 84 } 85 86 static const char_type* 87 find(const char_type* __s, size_t __n, const char_type& __a) 88 { 89 for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p) 90 if (*__p == __a) return __p; 91 return 0; 92 } 93 94 static char_type* 95 move(char_type* __s1, const char_type* __s2, size_t __n) 96 { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); } 97 98 static char_type* 99 copy(char_type* __s1, const char_type* __s2, size_t __n) 100 { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); } 101 102 static char_type* 103 assign(char_type* __s, size_t __n, char_type __a) 104 { 105 for (char_type* __p = __s; __p < __s + __n; ++__p) 106 assign(*__p, __a); 107 return __s; 108 } 109 110 static char_type 111 to_char_type(const int_type&) 112 { return char_type(); } 113 114 static int_type 115 to_int_type(const char_type&) { return int_type(); } 116 117 static bool 118 eq_int_type(const int_type& __c1, const int_type& __c2) 119 { return __c1 == __c2; } 120 121 static int_type 122 eof() { return static_cast<int_type>(-1); } 123 124 static int_type 125 not_eof(const int_type& __c) 126 { return eq_int_type(__c, eof()) ? int_type(0) : __c; } 127 }; 128} // namespace std 129 130namespace selftests { 131namespace string_view { 132namespace capacity_1 { 133 134static void 135test01 () 136{ 137 gdb::basic_string_view<A<B>> str02; 138 typedef gdb::basic_string_view< A<B> >::size_type size_type_o; 139 size_type_o sz03; 140 size_type_o sz04; 141 142 // non-POD types: size, length, max_size, empty() 143 bool b01 = str02.empty(); 144 VERIFY( b01 == true ); 145 sz03 = str02.size(); 146 sz04 = str02.length(); 147 VERIFY( sz03 == sz04 ); 148 str02.data(); 149 sz03 = str02.size(); 150 sz04 = str02.length(); 151 VERIFY( sz03 == sz04 ); 152 153 sz03 = str02.max_size(); 154 VERIFY( sz03 >= sz04 ); 155 156 sz03 = str02.size(); 157 str02 = {}; 158 b01 = str02.empty(); 159 VERIFY( b01 == true ); 160 sz04 = str02.size(); 161 VERIFY( sz03 >= sz04 ); 162} 163 164static int 165main() 166{ 167 test01(); 168 169 return 0; 170} 171 172} // namespace capacity_1 173