Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_algobase.h
Go to the documentation of this file.
1
46#ifndef _RWSTD_RW_ALGOBASE_H_INCLUDED
47#define _RWSTD_RW_ALGOBASE_H_INCLUDED
48
49
50#include <rw/_pair.h> // for pair
51#include <rw/_iterbase.h> // for iterator_traits, __rw_debug_iter
52
53
55
56
57// 25.3.7, p1
58template <class _TypeT>
59inline const _TypeT& (min)(const _TypeT& __a, const _TypeT& __b)
60{
61 return __b < __a ? __b : __a;
62}
63
64template <class _TypeT, class _Compare>
65inline const _TypeT& (min)(const _TypeT& __a, const _TypeT& __b, _Compare __cmp)
66{
67 return __cmp (__b, __a) ? __b : __a;
68}
69
70
71// 25.3.7, p3
72template <class _TypeT>
73inline const _TypeT& (max)(const _TypeT& __a, const _TypeT& __b)
74{
75 return __a < __b ? __b : __a;
76}
77
78
79template <class _TypeT, class _Compare>
80inline const _TypeT&
81(max)(const _TypeT& __a, const _TypeT& __b, _Compare __cmp)
82{
83 return !(__cmp (__a, __b) == false) ? __b : __a;
84}
85
86
87// 25.2.1, p1
88template <class _InputIter, class _OutputIter>
89inline _OutputIter
90copy (_InputIter __first, _InputIter __last, _OutputIter __res)
91{
92 _RWSTD_ASSERT_RANGE (__first, __last);
93
94 for (; !(__first == __last); ++__first,++__res)
95 *__res = *__first;
96 return __res;
97}
98
99
100// 25.2.1, p5
101template <class _BidirIter1, class _BidirIter2>
102inline _BidirIter2
103copy_backward (_BidirIter1 __first, _BidirIter1 __last, _BidirIter2 __res)
104{
105 _RWSTD_ASSERT_RANGE (__first, __last);
106
107 while (!(__first == __last))
108 *--__res = *--__last;
109 return __res;
110}
111
112
113// 25.2.5
114template <class _FwdIter, class _TypeT>
115inline void fill (_FwdIter __first, _FwdIter __last, const _TypeT &__val)
116{
117 _RWSTD_ASSERT_RANGE (__first, __last);
118
119 for ( ; !(__first == __last); ++__first)
120 *__first = __val;
121}
122
123
124template <class _OutputIter, class _Size, class _TypeT>
125inline void fill_n (_OutputIter __first, _Size __n, const _TypeT &__val)
126{
127 // Size must be convertible to integral type but need not itself be one
128 // Complexity:
129 // Exactly n if n is positive, or 0 otherwise, assignments.
130 // (see lwg issue 426 for the complexity when n is not positive)
131 for (_RWSTD_PTRDIFF_T __inx = __n; 0 < __inx; --__inx, ++__first)
132 *__first = __val;
133}
134
135
136} // namespace std
137
139
140// `less than' function object - used by non-predicate forms
141// of algorithms to invoke the predicate forms for code reuse
142struct __rw_lt
143{
144 template <class _TypeT, class _TypeU>
145 bool operator() (const _TypeT &__lhs, const _TypeU &__rhs) const {
146 // cast away constness in case operator<
147 // takes a non-const argument
148 return _RWSTD_CONST_CAST (_TypeT&, __lhs)
149 < _RWSTD_CONST_CAST (_TypeU&, __rhs);
150 }
151};
152
153# define _RWSTD_LESS(ignore) _RW::__rw_lt ()
154
155
156// swaps values of 2 (possibly distinct) types
157template <class _TypeT, class _TypeU>
158inline void __rw_swap (_TypeT& __a, _TypeU& __b)
159{
160 // _TypeT must satisfy Assignable and CopyConstructible
161 _TypeT __tmp = __a;
162 __a = __b;
163 __b = __tmp;
164}
165
166
167} // namespace __rw
168
169
171
172
173// 25.2.2, p1
174template <class _TypeT>
175inline void swap (_TypeT& __a, _TypeT& __b)
176{
177 // lwg issue 227 - _TypeT must satisfy Assignable and CopyConstructible
178 _TypeT __tmp = __a;
179 __a = __b;
180 __b = __tmp;
181}
182
183
184// 25.2.2, p7
185template <class _FwdIter1, class _FwdIter2>
186inline void iter_swap (_FwdIter1 __a, _FwdIter2 __b)
187{
188 // std::iterator_traits<_FwdIter[12]>::value_type must satisfy
189 // both Assignable and CopyConstructible
190
191#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
192
193 // accommodate _FwdIter::operator*() that returns an rvalue that
194 // doesn't bind to a non-const reference e.g., vector<bool>::reference
195
196 typename iterator_traits<_FwdIter1>::reference __ref1 (*__a);
197 typename iterator_traits<_FwdIter2>::reference __ref2 (*__b);
198
199 _RW::__rw_swap (__ref1, __ref2);
200
201#else // if defined (_RWSTD_NO_CLASS_PARTIAL_SPEC)
202
203 // the return type of std::iterator_traits<_FwdIter>::operator*()
204 // must be (convertible to) a true reference (i.e., value_type&)
205 _RW::__rw_swap (*__a, *__b);
206
207#endif // _RWSTD_NO_CLASS_PARTIAL_SPEC
208}
209
210
211// 25.1.7 - Mismatch
212template <class _InputIter1, class _InputIter2>
213inline pair<_InputIter1, _InputIter2>
214mismatch (_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2)
215{
216 _RWSTD_ASSERT_RANGE (__first1, __last1);
217
218 while (!(__first1 == __last1) && *__first1 == *__first2) {
219 ++__first1;
220 ++__first2;
221 }
222 return pair<_InputIter1, _InputIter2> (__first1, __first2);
223}
224
225
226template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
227inline pair<_InputIter1, _InputIter2>
228mismatch (_InputIter1 __first1, _InputIter1 __last1,
229 _InputIter2 __first2, _BinaryPredicate __pred)
230{
231 _RWSTD_ASSERT_RANGE (__first1, __last1);
232
233 while ( !(__first1 == __last1)
234 && !(__pred (*__first1, *__first2) == false)) {
235 ++__first1;
236 ++__first2;
237 }
238 return pair<_InputIter1, _InputIter2> (__first1, __first2);
239}
240
241
242// 25.1.8 - Equal
243template <class _InputIter1, class _InputIter2>
244inline bool
245equal (_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2)
246{
247 return __last1 == _STD::mismatch (__first1, __last1, __first2).first;
248}
249
250
251template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
252inline bool equal (_InputIter1 __first1, _InputIter1 __last1,
253 _InputIter2 __first2, _BinaryPredicate __pred)
254{
255 return __last1 == _STD::mismatch (__first1, __last1,
256 __first2, __pred).first;
257}
258
259
260// 25.3.8 - Lexicographical Comparison
262template <class _InputIter1, class _InputIter2>
263bool lexicographical_compare (_InputIter1 __first1, _InputIter1 __last1,
264 _InputIter2 __first2, _InputIter2 __last2);
265
266
268template <class _InputIter1, class _InputIter2, class _Compare>
269bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
270 _InputIter2 __first2, _InputIter2 __last2,
271 _Compare __comp);
272
273} // namespace std
274
275
276#ifdef _RWSTD_NO_IMPLICIT_INCLUSION
277# include <rw/_algobase.cc>
278#endif // _RWSTD_NO_IMPLICIT_INCLUSION
279
280
281#endif // _RWSTD_RW_ALGOBASE_H_INCLUDED
bool equal(const T &x, const U &y)
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _EXPORT
Definition _defs.h:498
#define _RWSTD_ASSERT_RANGE(ign1, ign2)
Definition _defs.h:1247
#define _RWSTD_CONST_CAST(T, x)
Definition _defs.h:536
Definition json.h:5363
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression, cppcoreguidelines-noexcept-swap, performance-noexcept-swap) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition json.h:24538
#define min(a, b)
#define max(a, b)