BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslstl_algorithm.h
Go to the documentation of this file.
1/// @file bslstl_algorithm.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_algorithm.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_ALGORITHM
9#define INCLUDED_BSLSTL_ALGORITHM
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_algorithm bslstl_algorithm
15/// @brief Provide implementations for algorithms not in the system library.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_algorithm
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_algorithm-purpose"> Purpose</a>
25/// * <a href="#bslstl_algorithm-classes"> Classes </a>
26/// * <a href="#bslstl_algorithm-description"> Description </a>
27/// * <a href="#bslstl_algorithm-usage"> Usage </a>
28///
29/// # Purpose {#bslstl_algorithm-purpose}
30/// Provide implementations for algorithms not in the system library.
31///
32/// # Classes {#bslstl_algorithm-classes}
33///
34///
35/// **Canonical header:** bsl_algorithm.h
36///
37/// @see bsl+bslhdrs
38///
39/// # Description {#bslstl_algorithm-description}
40/// This component is for internal use only. Please include
41/// `<bsl_algorithm.h>` instead. This component provides a namespace for
42/// implementations for standard algorithms that are not provided by the
43/// underlying standard library implementation. For example, `any_of` is a
44/// C++11 algorithm, and it is provided here for code using C++03.
45///
46/// ## Usage {#bslstl_algorithm-usage}
47///
48///
49/// This component is for use by the `bsl+bslhdrs` package. Use
50/// `bsl_algorithm.h` directly.
51/// @}
52/** @} */
53/** @} */
54
55/** @addtogroup bsl
56 * @{
57 */
58/** @addtogroup bslstl
59 * @{
60 */
61/** @addtogroup bslstl_algorithm
62 * @{
63 */
64
65#include <bslscm_version.h>
66#include <bsls_assert.h>
68#include <bsls_keyword.h>
70
71#include <bslstl_iterator.h> // iterator tags
72#include <bslstl_pair.h>
73
74#include <algorithm>
75#include <functional> // less
76
77#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
78#include <bsls_nativestd.h>
79#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
80
81
82namespace bslstl {
83
84/// Provide a namespace for implementing helper routines for algorithm
85/// implementations.
87
88 private:
89 // PRIVATE CLASS METHODS
90
91 /// Copy the specified `count` elements from the specified `first`
92 /// to the specified `result`. Return an iterator pointing past
93 /// the last copied element in the output range.
94 template <class t_INPUT_ITERATOR, class t_SIZE, class t_OUTPUT_ITERATOR>
95 static
96 t_OUTPUT_ITERATOR copyNImp(t_INPUT_ITERATOR first,
97 t_SIZE count,
98 t_OUTPUT_ITERATOR result,
99 const bsl::input_iterator_tag&);
100 template <class t_RANDOM_ACCESS_ITERATOR,
101 class t_SIZE,
102 class t_OUTPUT_ITERATOR>
103 static
104 t_OUTPUT_ITERATOR copyNImp(t_RANDOM_ACCESS_ITERATOR first,
105 t_SIZE count,
106 t_OUTPUT_ITERATOR result,
107 const bsl::random_access_iterator_tag&);
108
109 public:
110 // CLASS FUNCTIONS
111
112 /// Erase all the elements in the specified container `container` that
113 /// satisfy the specified predicate `predicate`. Return the number of
114 /// elements erased.
115 template <class CONTAINER, class PREDICATE>
116 static
117 typename CONTAINER::size_type
118 containerEraseIf(CONTAINER& container, PREDICATE predicate);
119
120 /// Copy the specified `count` elements from the specified `first`
121 /// to the specified `result`. Return an iterator pointing past
122 /// the last copied element in the output range.
123 template <class t_INPUT_ITERATOR, class t_SIZE, class t_OUTPUT_ITERATOR>
124 static
125 t_OUTPUT_ITERATOR copyN(t_INPUT_ITERATOR first,
126 t_SIZE count,
127 t_OUTPUT_ITERATOR result);
128};
129
130} // close package namespace
131
132
133namespace bsl {
134
135 // Import selected symbols into bsl namespace
136 using std::adjacent_find;
137 using std::binary_search;
138 using std::copy;
139 using std::copy_backward;
140
141 using std::equal;
142 using std::equal_range;
143 using std::fill;
144 using std::fill_n;
145 using std::find;
146 using std::find_end;
147 using std::find_first_of;
148 using std::find_if;
149 using std::for_each;
150 using std::generate;
151 using std::generate_n;
152 using std::includes;
153 using std::inplace_merge;
154 using std::iter_swap;
155 using std::lexicographical_compare;
156 using std::lower_bound;
157
158 using std::make_heap;
159 using std::max;
160 using std::max_element;
161 using std::merge;
162 using std::min;
163 using std::min_element;
164 using std::mismatch;
165 using std::next_permutation;
166 using std::nth_element;
167 using std::partial_sort;
168 using std::partial_sort_copy;
169 using std::partition;
170 using std::pop_heap;
171 using std::prev_permutation;
172 using std::push_heap;
173 using std::remove;
174 using std::remove_copy;
175 using std::remove_copy_if;
176 using std::remove_if;
177 using std::replace;
178 using std::replace_copy;
179 using std::replace_copy_if;
180 using std::replace_if;
181 using std::reverse;
182 using std::reverse_copy;
183 using std::rotate;
184 using std::rotate_copy;
185 using std::search;
186 using std::search_n;
187 using std::set_difference;
188 using std::set_intersection;
189 using std::set_new_handler;
190 using std::set_symmetric_difference;
191 using std::set_union;
192 using std::sort;
193 using std::sort_heap;
194 using std::stable_partition;
195 using std::stable_sort;
196 using std::swap;
197 using std::swap_ranges;
198 using std::transform;
199 using std::unique;
200 using std::unique_copy;
201 using std::upper_bound;
202
203#if ! defined BSLS_LIBRARYFEATURES_HAS_CPP17_DEPRECATED_REMOVED
204 // These names are removed by C++17
205 using std::random_shuffle;
206#endif
207
208#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
209 using std::all_of;
210 using std::any_of;
211 using std::copy_if;
212
213 using std::copy_n;
214 #define BSLSTL_ALGORITHM_COPY_N_IS_ALIASED
215
216 using std::find_if_not;
217 using std::is_heap;
218 using std::is_heap_until;
219 using std::is_partitioned;
220 using std::is_permutation;
221 using std::is_sorted;
222 using std::is_sorted_until;
223 using std::minmax;
224 using std::minmax_element;
225 using std::move;
226 using std::move_backward;
227 using std::none_of;
228 using std::partition_copy;
229 using std::partition_point;
230 using std::shuffle;
231#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
232
233// C++14 Algorithms
234// We get these via the "using std::equal" above
235// equal
236// mismatch
237
238#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
239 using std::clamp;
240 using std::for_each_n;
241 using std::sample;
242#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
243
244#ifdef BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
245 using std::lexicographical_compare_three_way;
246#endif // BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
247
248#ifdef BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES
249namespace ranges {
250
251 // Non-modifying sequence operations
252
253 using std::ranges::all_of;
254 using std::ranges::any_of;
255 using std::ranges::none_of;
256 using std::ranges::for_each;
257 using std::ranges::for_each_result;
258 using std::ranges::for_each_n;
259 using std::ranges::for_each_n_result;
260 using std::ranges::count;
261 using std::ranges::count_if;
262 using std::ranges::mismatch;
263 using std::ranges::mismatch_result;
264 using std::ranges::equal;
265 using std::ranges::lexicographical_compare;
266 using std::ranges::find;
267 using std::ranges::find_if;
268 using std::ranges::find_if_not;
269 using std::ranges::find_end;
270 using std::ranges::find_first_of;
271 using std::ranges::adjacent_find;
272 using std::ranges::search;
273 using std::ranges::search_n;
274
275 // Modifying sequence operations
276
277 using std::ranges::copy;
278 using std::ranges::copy_result;
279 using std::ranges::copy_if;
280 using std::ranges::copy_if_result;
281 using std::ranges::copy_n;
282 using std::ranges::copy_n_result;
283 using std::ranges::copy_backward;
284 using std::ranges::copy_backward_result;
285 using std::ranges::move;
286 using std::ranges::move_result;
287 using std::ranges::move_backward;
288 using std::ranges::move_backward_result;
289 using std::ranges::fill;
290 using std::ranges::fill_n;
291 using std::ranges::transform;
292 using std::ranges::unary_transform_result;
293 using std::ranges::binary_transform_result;
294 using std::ranges::generate;
295 using std::ranges::generate_n;
296 using std::ranges::remove;
297 using std::ranges::remove_if;
298 using std::ranges::remove_copy;
299 using std::ranges::remove_copy_result;
300 using std::ranges::remove_copy_if;
301 using std::ranges::remove_copy_if_result;
302 using std::ranges::replace;
303 using std::ranges::replace_if;
304 using std::ranges::replace_copy;
305 using std::ranges::replace_copy_result;
306 using std::ranges::replace_copy_if;
307 using std::ranges::replace_copy_if_result;
308 using std::ranges::swap_ranges;
309 using std::ranges::swap_ranges_result;
310 using std::ranges::reverse;
311 using std::ranges::reverse_copy;
312 using std::ranges::reverse_copy_result;
313 using std::ranges::rotate;
314 using std::ranges::rotate_copy;
315 using std::ranges::rotate_copy_result;
316 using std::ranges::shuffle;
317 using std::ranges::sample;
318 using std::ranges::unique;
319 using std::ranges::unique_copy;
320 using std::ranges::unique_copy_result;
321
322 // Partitioning operations
323
324 using std::ranges::is_partitioned;
325 using std::ranges::partition;
326 using std::ranges::partition_copy;
327 using std::ranges::partition_copy_result;
328 using std::ranges::stable_partition;
329 using std::ranges::partition_point;
330
331 // Sorting operations
332
333 using std::ranges::is_sorted;
334 using std::ranges::is_sorted_until;
335 using std::ranges::sort;
336 using std::ranges::partial_sort;
337 using std::ranges::partial_sort_copy;
338 using std::ranges::stable_sort;
339 using std::ranges::nth_element;
340
341 // Binary search operations (on sorted ranges)
342
343 using std::ranges::lower_bound;
344 using std::ranges::upper_bound;
345 using std::ranges::binary_search;
346 using std::ranges::equal_range;
347
348 // Other operations (on sorted ranges)
349
350 using std::ranges::merge;
351 using std::ranges::merge_result;
352 using std::ranges::inplace_merge;
353
354 // Set operations (on sorted ranges)
355
356 using std::ranges::includes;
357 using std::ranges::set_difference;
358 using std::ranges::set_difference_result;
359 using std::ranges::set_intersection;
360 using std::ranges::set_intersection_result;
361 using std::ranges::set_symmetric_difference;
362 using std::ranges::set_symmetric_difference_result;
363 using std::ranges::set_union;
364 using std::ranges::set_union_result;
365
366 // Heap operations
367
368 using std::ranges::is_heap;
369 using std::ranges::is_heap_until;
370 using std::ranges::make_heap;
371 using std::ranges::push_heap;
372 using std::ranges::pop_heap;
373 using std::ranges::sort_heap;
374
375 // Minimum/maximum operations
376
377 using std::ranges::max;
378 using std::ranges::max_element;
379 using std::ranges::min;
380 using std::ranges::min_element;
381 using std::ranges::minmax;
382 using std::ranges::minmax_result;
383 using std::ranges::minmax_element;
384 using std::ranges::minmax_element_result;
385 using std::ranges::clamp;
386 using std::ranges::is_permutation;
387 using std::ranges::next_permutation;
388 using std::ranges::next_permutation_result;
389 using std::ranges::prev_permutation;
390 using std::ranges::prev_permutation_result;
391
392 // Return types
393
394 using std::ranges::in_fun_result;
395 using std::ranges::in_in_result;
396 using std::ranges::in_out_result;
397 using std::ranges::in_in_out_result;
398 using std::ranges::in_out_out_result;
399 using std::ranges::min_max_result;
400 using std::ranges::in_found_result;
401}
402#endif // BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES
403
404#ifndef BDE_OMIT_INTERNAL_DEPRECATED
405 // Import additional names expected by existing code, but not mandated by
406 // the standard header.
407 using std::advance;
408 using std::bad_alloc;
409 using std::bidirectional_iterator_tag;
410 using std::forward_iterator_tag;
411 using std::input_iterator_tag;
412#if !defined(BSLS_PLATFORM_CMP_MSVC) && \
413 (BSLS_COMPILERFEATURES_CPLUSPLUS <= 201703L)
414 using std::iterator;
415#endif
416 using std::new_handler;
417 using std::nothrow;
418 using std::nothrow_t;
419 using std::output_iterator_tag;
420 using std::random_access_iterator_tag;
421
422#endif // BDE_OMIT_INTERNAL_DEPRECATED
423
424#ifndef BSLSTL_ITERATOR_PROVIDE_SUN_CPP98_FIXES
425 // Use the compiler vendor supplied version of `count` and `count_if`.
426 using std::count;
427 using std::count_if;
428#else
429 // Sun-specific fixes
430
431 /// Provide an override for `count` since Sun only provides a 4 argument
432 /// version while the C++ standard requires a 3 argument version.
433 template <class InputIter, class TYPE>
434 typename iterator_traits<InputIter>::difference_type
435 count(InputIter first, InputIter last, const TYPE& value);
436
437 /// Provide an override for `count_if` since Sun only provides a 4
438 /// argument version while the C++ standard requires a 3 argument
439 /// version.
440 template <class InputIter, class PREDICATE>
441 typename iterator_traits<InputIter>::difference_type
442 count_if(InputIter first, InputIter last, PREDICATE pred);
443#endif // BSLSTL_ITERATOR_PROVIDE_SUN_CPP98_FIXES
444
445
446#ifndef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
447 /// Return `true` if, for the specified `[first, last)` range and the
448 /// specified predicate `pred`, the range is either empty or `pred(*i)`
449 /// is `true` for every iterator `i` in the range, and `false`
450 /// otherwise. Note that at most `last - first` applications of the
451 /// predicate are performed.
452 template <class INPUT_ITERATOR, class PREDICATE>
453 bool all_of(INPUT_ITERATOR first, INPUT_ITERATOR last, PREDICATE pred);
454
455 /// Return `false` if, for the specified `[first, last)` range and the
456 /// specified predicate `pred`, the range is either empty or `pred(*i)`
457 /// is `false` for every iterator `i` in the range, and `true`
458 /// otherwise. Note that at most `last - first` applications of the
459 /// predicate are performed.
460 template <class INPUT_ITERATOR, class PREDICATE>
461 bool any_of(INPUT_ITERATOR first, INPUT_ITERATOR last, PREDICATE pred);
462
463 /// Return `true` if, for the specified `[first, last)` range and the
464 /// specified predicate `pred`, the range is either empty or `pred(*i)`
465 /// is `false` for every iterator `i` in the range, and `false`
466 /// otherwise. Note that at most `last - first` applications of the
467 /// predicate are performed.
468 template <class INPUT_ITERATOR, class PREDICATE>
469 bool none_of(INPUT_ITERATOR first, INPUT_ITERATOR last, PREDICATE pred);
470
471# if defined(BSLS_LIBRARYFEATURES_STDCPP_MSVC)
472 // Visual Studio (the versions we support) provides 'copy_if'.
473 using std::copy_if;
474# else
475/// C++03 standard libraries do not provide `std::copy_if` (as it was not
476/// part of the C++03 standard), but it is actually implementable in C++03,
477/// so we inject it here.
478# define BSLSTL_ALGORITHMWORKAROUND_IMPLEMENTS_COPY_IF 1
479
480 /// Copy all elements in the half-open range of the specified `first`,
481 /// and `last` (`[first, last)`) input iterators for which the specified
482 /// `pred` unary predicate is `true` to the specified `result` output
483 /// iterator, incrementing result after each copied element, keeping the
484 /// element order stable. The behavior is undefined if the ranges
485 /// `[first, last)` and
486 /// `[result, advance(result, distance(first, last)))` overlap. The
487 /// behavior is also undefined if `pred` attempts to invoke any
488 /// non-constant functions of its argument. See also [alg.copy] in the
489 /// C++11 standard.
490 template <class INPUT_ITERATOR, class OUTPUT_ITERATOR, class PREDICATE>
491 OUTPUT_ITERATOR
492 copy_if(INPUT_ITERATOR first,
493 INPUT_ITERATOR last,
494 OUTPUT_ITERATOR result,
495 PREDICATE pred);
496# endif // !BSLS_LIBRARYFEATURES_STDCPP_MSVC
497#endif // !BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
498
499#ifndef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
500 /// Return the specified `value` adjusted so that it is in the range
501 /// [`low`, `high`), using the specified comparison predicate `comp`.
502 template<class TYPE, class COMPARE>
504 const TYPE&
505 clamp(const TYPE& value, const TYPE& low, const TYPE& high, COMPARE comp);
506
507 /// Return the specified `value` adjusted so that it is in the range
508 /// [`low`, `high`).
509 template<class TYPE>
511 const TYPE&
512 clamp(const TYPE& value, const TYPE& low, const TYPE& high);
513#endif
514
515#ifndef BSLS_LIBRARYFEATURES_HAS_CPP17_SEARCH_OVERLOAD
516 /// Return the position in the specified range `[first, last)` of the
517 /// first occurrence of the pattern sought by the specified `searcher`
518 /// if found, and `last` otherwise. See [alg.search].
519 template<class FORWARD_ITERATOR, class SEARCHER>
521 FORWARD_ITERATOR search(FORWARD_ITERATOR first,
522 FORWARD_ITERATOR last,
523 const SEARCHER& searcher);
524#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_SEARCH_OVERLOAD
525
526} // close namespace bsl
527
528
529
530#ifndef BSLSTL_ALGORITHM_COPY_N_IS_ALIASED
531namespace bsl {
532/// Copy the specified `count` elements from the specified `first` to the
533/// specified `result`. Return an iterator pointing past the last copied
534/// element in the output range.
535template <class t_INPUT_ITERATOR, class t_SIZE, class t_OUTPUT_ITERATOR>
536inline
537t_OUTPUT_ITERATOR copy_n(t_INPUT_ITERATOR first,
538 t_SIZE count,
539 t_OUTPUT_ITERATOR result);
540} // close namespace bsl
541#endif // BSLSTL_ALGORITHM_COPY_N_IS_ALIASED
542
543// ============================================================================
544// INLINE DEFINITIONS
545// ============================================================================
546
547 // --------------------
548 // struct AlgorithmUtil
549 // --------------------
550
551// PRIVATE CLASS METHODS
552template <class t_INPUT_ITERATOR, class t_SIZE, class t_OUTPUT_ITERATOR>
553inline
554t_OUTPUT_ITERATOR BloombergLP::bslstl::AlgorithmUtil::copyNImp(
555 t_INPUT_ITERATOR first,
556 t_SIZE count,
557 t_OUTPUT_ITERATOR result,
558 const bsl::input_iterator_tag&)
559{
560 for ( ; count > 0; --count) {
561 *result = *first;
562 ++first;
563 ++result;
564 }
565 return result;
566}
567
568template <class t_RANDOM_ACCESS_ITERATOR,
569 class t_SIZE,
570 class t_OUTPUT_ITERATOR>
571inline
572t_OUTPUT_ITERATOR BloombergLP::bslstl::AlgorithmUtil::copyNImp(
573 t_RANDOM_ACCESS_ITERATOR first,
574 t_SIZE count,
575 t_OUTPUT_ITERATOR result,
576 const bsl::random_access_iterator_tag&)
577{
578 return std::copy(first, first + count, result);
579}
580
581// CLASS METHODS
582template <class CONTAINER, class PREDICATE>
583inline
584typename CONTAINER::size_type
585BloombergLP::bslstl::AlgorithmUtil::containerEraseIf(CONTAINER& container,
586 PREDICATE predicate)
587{
588 typename CONTAINER::size_type oldSize = container.size();
589 for (typename CONTAINER::iterator it = container.begin();
590 it != container.end();) {
591 if (predicate(*it)) {
592 it = container.erase(it);
593 }
594 else {
595 ++it;
596 }
597 }
598 return oldSize - container.size();
599}
600
601template <class t_INPUT_ITERATOR, class t_SIZE, class t_OUTPUT_ITERATOR>
602inline
603t_OUTPUT_ITERATOR BloombergLP::bslstl::AlgorithmUtil::copyN(
604 t_INPUT_ITERATOR first,
605 t_SIZE count,
606 t_OUTPUT_ITERATOR result)
607{
608 typedef typename bsl::iterator_traits<t_INPUT_ITERATOR>::iterator_category
609 Tag;
610 return BloombergLP::bslstl::AlgorithmUtil::copyNImp(first,
611 count,
612 result,
613 Tag());
614}
615
616#ifdef BSLSTL_ITERATOR_PROVIDE_SUN_CPP98_FIXES
617template <class INPUT_ITERATOR, class TYPE>
618inline
619typename bsl::iterator_traits<INPUT_ITERATOR>::difference_type
620bsl::count(INPUT_ITERATOR first, INPUT_ITERATOR last, const TYPE& value)
621{
622 typename bsl::iterator_traits<INPUT_ITERATOR>::difference_type ret = 0;
623 std::count(first, last, value, ret);
624 return ret;
625}
626
627template <class INPUT_ITERATOR, class PREDICATE>
628inline
629typename bsl::iterator_traits<INPUT_ITERATOR>::difference_type
630bsl::count_if(INPUT_ITERATOR first, INPUT_ITERATOR last, PREDICATE pred)
631{
632 typename bsl::iterator_traits<INPUT_ITERATOR>::difference_type ret = 0;
633 std::count_if(first, last, pred, ret);
634 return ret;
635}
636#endif // BSLSTL_ITERATOR_PROVIDE_SUN_CPP98_FIXES
637
638
639#ifndef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
640
641template <class INPUT_ITERATOR, class PREDICATE>
642bool bsl::all_of(INPUT_ITERATOR first, INPUT_ITERATOR last, PREDICATE pred)
643{
644 for (; first != last; ++first) {
645 if (!pred(*first)) {
646 return false; // RETURN
647 }
648 }
649 return true;
650}
651
652template <class INPUT_ITERATOR, class PREDICATE>
653bool bsl::any_of(INPUT_ITERATOR first, INPUT_ITERATOR last, PREDICATE pred)
654{
655 for (; first != last; ++first) {
656 if (pred(*first)) {
657 return true; // RETURN
658 }
659 }
660 return false;
661}
662
663template <class INPUT_ITERATOR, class PREDICATE>
664bool bsl::none_of(INPUT_ITERATOR first, INPUT_ITERATOR last, PREDICATE pred)
665{
666 for (; first != last; ++first) {
667 if (pred(*first)) {
668 return false; // RETURN
669 }
670 }
671 return true;
672}
673
674# ifdef BSLSTL_ALGORITHMWORKAROUND_IMPLEMENTS_COPY_IF
675template <class INPUT_ITERATOR, class OUTPUT_ITERATOR, class PREDICATE>
676inline OUTPUT_ITERATOR
677bsl::copy_if(INPUT_ITERATOR first,
678 INPUT_ITERATOR last,
679 OUTPUT_ITERATOR result,
680 PREDICATE pred)
681{
682 while(first != last) {
683 if (pred(*first)) {
684 *result++ = *first;
685 }
686 ++first;
687 }
688 return result;
689}
690# endif // BSLSTL_ALGORITHMWORKAROUND_IMPLEMENTS_COPY_IF
691
692#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
693
694
695#ifndef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
696template<class TYPE, class COMPARE>
698inline const TYPE&
699bsl::clamp(const TYPE& value, const TYPE& low, const TYPE& high, COMPARE comp)
700{
701 BSLS_ASSERT(!comp(high, low));
702 return comp(value, low) ? low : comp(high, value) ? high : value;
703}
704
705template<class TYPE>
707inline const TYPE&
708bsl::clamp(const TYPE& value, const TYPE& low, const TYPE& high)
709{
710 return bsl::clamp(value, low, high, std::less<TYPE>());
711}
712#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
713
714
715#ifndef BSLS_LIBRARYFEATURES_HAS_CPP17_SEARCH_OVERLOAD
716template<class FORWARD_ITERATOR, class SEARCHER>
717inline
718BSLS_KEYWORD_CONSTEXPR_CPP14 FORWARD_ITERATOR
719bsl::search(FORWARD_ITERATOR first,
720 FORWARD_ITERATOR last,
721 const SEARCHER& searcher)
722{
723 bsl::pair<FORWARD_ITERATOR, FORWARD_ITERATOR> res = searcher(first, last);
724 return res.first;
725}
726#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_SEARCH_OVERLOAD
727
728#ifndef BSLSTL_ALGORITHM_COPY_N_IS_ALIASED
729template <class t_INPUT_ITERATOR, class t_SIZE, class t_OUTPUT_ITERATOR>
730inline
731t_OUTPUT_ITERATOR bsl::copy_n(t_INPUT_ITERATOR first,
732 t_SIZE count,
733 t_OUTPUT_ITERATOR result)
734{
735 return BloombergLP::bslstl::AlgorithmUtil::copyN(first,
736 count,
737 result);
738}
739#endif // BSLSTL_ALGORITHM_COPY_N_IS_ALIASED
740
741#endif // INCLUDED_BSLSTL_ALGORITHM
742
743// ----------------------------------------------------------------------------
744// Copyright 2020 Bloomberg Finance L.P.
745//
746// Licensed under the Apache License, Version 2.0 (the "License");
747// you may not use this file except in compliance with the License.
748// You may obtain a copy of the License at
749//
750// http://www.apache.org/licenses/LICENSE-2.0
751//
752// Unless required by applicable law or agreed to in writing, software
753// distributed under the License is distributed on an "AS IS" BASIS,
754// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
755// See the License for the specific language governing permissions and
756// limitations under the License.
757// ----------------------------- END-OF-FILE ----------------------------------
758
759/** @} */
760/** @} */
761/** @} */
Definition bslstl_pair.h:1210
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_CONSTEXPR_CPP14
Definition bsls_keyword.h:595
Definition bdlb_printmethods.h:283
BSLS_KEYWORD_CONSTEXPR_CPP14 const TYPE & clamp(const TYPE &value, const TYPE &low, const TYPE &high, COMPARE comp)
BSLS_KEYWORD_CONSTEXPR_CPP14 FORWARD_ITERATOR search(FORWARD_ITERATOR first, FORWARD_ITERATOR last, const SEARCHER &searcher)
Definition bslstl_algorithm.h:82
void swap(TYPE &a, TYPE &b)
TYPE first
Definition bslstl_pair.h:605
Definition bslstl_algorithm.h:86
static CONTAINER::size_type containerEraseIf(CONTAINER &container, PREDICATE predicate)
static t_OUTPUT_ITERATOR copyN(t_INPUT_ITERATOR first, t_SIZE count, t_OUTPUT_ITERATOR result)