1 // Versatile string utility -*- C++ -*-
3 // Copyright (C) 2005-2022 Free Software Foundation, Inc.
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)
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.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file ext/vstring_util.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{ext/vstring.h}
30 #ifndef _VSTRING_UTIL_H
31 #define _VSTRING_UTIL_H 1
33 #pragma GCC system_header
35 #include <bits/requires_hosted.h> // GNU extensions are currently omitted
37 #include <ext/vstring_fwd.h>
38 #include <debug/debug.h>
39 #include <bits/stl_function.h> // For less
40 #include <bits/functexcept.h>
41 #include <bits/localefwd.h>
42 #include <bits/ostream_insert.h>
43 #include <bits/stl_iterator.h>
44 #include <ext/numeric_traits.h>
45 #include <ext/alloc_traits.h>
46 #include <bits/move.h>
47 #include <bits/range_access.h>
49 namespace __gnu_cxx
_GLIBCXX_VISIBILITY(default)
51 _GLIBCXX_BEGIN_NAMESPACE_VERSION
53 template<typename _CharT
, typename _Traits
, typename _Alloc
>
54 struct __vstring_utility
56 typedef typename __alloc_traits
<_Alloc
>::template rebind
<_CharT
>::other
58 typedef __alloc_traits
<_CharT_alloc_type
> _CharT_alloc_traits
;
60 typedef _Traits traits_type
;
61 typedef typename
_Traits::char_type value_type
;
62 typedef typename
_CharT_alloc_type::size_type size_type
;
63 typedef typename
_CharT_alloc_type::difference_type difference_type
;
64 typedef typename
_CharT_alloc_traits::pointer pointer
;
65 typedef typename
_CharT_alloc_traits::const_pointer const_pointer
;
69 __normal_iterator
<pointer
, __gnu_cxx::
70 __versa_string
<_CharT
, _Traits
, _Alloc
,
74 __normal_iterator
<const_pointer
, __gnu_cxx::
75 __versa_string
<_CharT
, _Traits
, _Alloc
,
81 __normal_iterator
<pointer
, __gnu_cxx::
82 __versa_string
<_CharT
, _Traits
, _Alloc
,
86 __normal_iterator
<const_pointer
, __gnu_cxx::
87 __versa_string
<_CharT
, _Traits
, _Alloc
,
91 // NB: When the allocator is empty, deriving from it saves space
92 // (http://www.cantrip.org/emptyopt.html).
93 template<typename _Alloc1
>
97 _Alloc_hider(_CharT
* __ptr
)
98 : _Alloc1(), _M_p(__ptr
) { }
100 _Alloc_hider(const _Alloc1
& __a
, _CharT
* __ptr
)
101 : _Alloc1(__a
), _M_p(__ptr
) { }
103 _CharT
* _M_p
; // The actual data.
106 // When __n = 1 way faster than the general multichar
107 // traits_type::copy/move/assign.
109 _S_copy(_CharT
* __d
, const _CharT
* __s
, size_type __n
)
112 traits_type::assign(*__d
, *__s
);
114 traits_type::copy(__d
, __s
, __n
);
118 _S_move(_CharT
* __d
, const _CharT
* __s
, size_type __n
)
121 traits_type::assign(*__d
, *__s
);
123 traits_type::move(__d
, __s
, __n
);
127 _S_assign(_CharT
* __d
, size_type __n
, _CharT __c
)
130 traits_type::assign(*__d
, __c
);
132 traits_type::assign(__d
, __n
, __c
);
135 // _S_copy_chars is a separate template to permit specialization
136 // to optimize for the common case of pointers as iterators.
137 template<typename _Iterator
>
139 _S_copy_chars(_CharT
* __p
, _Iterator __k1
, _Iterator __k2
)
141 for (; __k1
!= __k2
; ++__k1
, ++__p
)
142 traits_type::assign(*__p
, *__k1
); // These types are off.
146 _S_copy_chars(_CharT
* __p
, __sso_iterator __k1
, __sso_iterator __k2
)
147 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
150 _S_copy_chars(_CharT
* __p
, __const_sso_iterator __k1
,
151 __const_sso_iterator __k2
)
152 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
155 _S_copy_chars(_CharT
* __p
, __rc_iterator __k1
, __rc_iterator __k2
)
156 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
159 _S_copy_chars(_CharT
* __p
, __const_rc_iterator __k1
,
160 __const_rc_iterator __k2
)
161 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
164 _S_copy_chars(_CharT
* __p
, _CharT
* __k1
, _CharT
* __k2
)
165 { _S_copy(__p
, __k1
, __k2
- __k1
); }
168 _S_copy_chars(_CharT
* __p
, const _CharT
* __k1
, const _CharT
* __k2
)
169 { _S_copy(__p
, __k1
, __k2
- __k1
); }
172 _S_compare(size_type __n1
, size_type __n2
)
174 const difference_type __d
= difference_type(__n1
- __n2
);
176 if (__d
> __numeric_traits_integer
<int>::__max
)
177 return __numeric_traits_integer
<int>::__max
;
178 else if (__d
< __numeric_traits_integer
<int>::__min
)
179 return __numeric_traits_integer
<int>::__min
;
185 _GLIBCXX_END_NAMESPACE_VERSION
188 #endif /* _VSTRING_UTIL_H */