8#ifndef INCLUDED_BSLSTL_ALGORITHM
9#define INCLUDED_BSLSTL_ALGORITHM
65#include <bslscm_version.h>
77#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
94 template <
class t_INPUT_ITERATOR,
class t_SIZE,
class t_OUTPUT_ITERATOR>
96 t_OUTPUT_ITERATOR copyNImp(t_INPUT_ITERATOR first,
98 t_OUTPUT_ITERATOR result,
99 const bsl::input_iterator_tag&);
100 template <
class t_RANDOM_ACCESS_ITERATOR,
102 class t_OUTPUT_ITERATOR>
104 t_OUTPUT_ITERATOR copyNImp(t_RANDOM_ACCESS_ITERATOR first,
106 t_OUTPUT_ITERATOR result,
107 const bsl::random_access_iterator_tag&);
115 template <
class CONTAINER,
class PREDICATE>
117 typename CONTAINER::size_type
123 template <
class t_INPUT_ITERATOR,
class t_SIZE,
class t_OUTPUT_ITERATOR>
125 t_OUTPUT_ITERATOR
copyN(t_INPUT_ITERATOR first,
127 t_OUTPUT_ITERATOR result);
136 using std::adjacent_find;
137 using std::binary_search;
139 using std::copy_backward;
142 using std::equal_range;
147 using std::find_first_of;
151 using std::generate_n;
153 using std::inplace_merge;
154 using std::iter_swap;
155 using std::lexicographical_compare;
156 using std::lower_bound;
158 using std::make_heap;
160 using std::max_element;
163 using std::min_element;
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;
171 using std::prev_permutation;
172 using std::push_heap;
174 using std::remove_copy;
175 using std::remove_copy_if;
176 using std::remove_if;
178 using std::replace_copy;
179 using std::replace_copy_if;
180 using std::replace_if;
182 using std::reverse_copy;
184 using std::rotate_copy;
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;
193 using std::sort_heap;
194 using std::stable_partition;
195 using std::stable_sort;
197 using std::swap_ranges;
198 using std::transform;
200 using std::unique_copy;
201 using std::upper_bound;
203#if ! defined BSLS_LIBRARYFEATURES_HAS_CPP17_DEPRECATED_REMOVED
205 using std::random_shuffle;
208#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
214 #define BSLSTL_ALGORITHM_COPY_N_IS_ALIASED
216 using std::find_if_not;
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;
224 using std::minmax_element;
226 using std::move_backward;
228 using std::partition_copy;
229 using std::partition_point;
238#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
240 using std::for_each_n;
244#ifdef BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
245 using std::lexicographical_compare_three_way;
248#ifdef BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES
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;
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;
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;
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;
343 using std::ranges::lower_bound;
344 using std::ranges::upper_bound;
345 using std::ranges::binary_search;
346 using std::ranges::equal_range;
350 using std::ranges::merge;
351 using std::ranges::merge_result;
352 using std::ranges::inplace_merge;
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;
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;
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;
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;
404#ifndef BDE_OMIT_INTERNAL_DEPRECATED
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)
416 using std::new_handler;
418 using std::nothrow_t;
419 using std::output_iterator_tag;
420 using std::random_access_iterator_tag;
424#ifndef BSLSTL_ITERATOR_PROVIDE_SUN_CPP98_FIXES
433 template <
class InputIter,
class TYPE>
434 typename iterator_traits<InputIter>::difference_type
435 count(InputIter first, InputIter last,
const TYPE& value);
440 template <
class InputIter,
class PREDICATE>
441 typename iterator_traits<InputIter>::difference_type
442 count_if(InputIter first, InputIter last, PREDICATE pred);
446#ifndef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
452 template <
class INPUT_ITERATOR,
class PREDICATE>
453 bool all_of(INPUT_ITERATOR first, INPUT_ITERATOR last, PREDICATE pred);
460 template <
class INPUT_ITERATOR,
class PREDICATE>
461 bool any_of(INPUT_ITERATOR first, INPUT_ITERATOR last, PREDICATE pred);
468 template <
class INPUT_ITERATOR,
class PREDICATE>
469 bool none_of(INPUT_ITERATOR first, INPUT_ITERATOR last, PREDICATE pred);
471# if defined(BSLS_LIBRARYFEATURES_STDCPP_MSVC)
478# define BSLSTL_ALGORITHMWORKAROUND_IMPLEMENTS_COPY_IF 1
490 template <
class INPUT_ITERATOR,
class OUTPUT_ITERATOR,
class PREDICATE>
492 copy_if(INPUT_ITERATOR first,
494 OUTPUT_ITERATOR result,
499#ifndef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
502 template<
class TYPE,
class COMPARE>
505 clamp(
const TYPE& value,
const TYPE& low,
const TYPE& high, COMPARE comp);
512 clamp(
const TYPE& value,
const TYPE& low,
const TYPE& high);
515#ifndef BSLS_LIBRARYFEATURES_HAS_CPP17_SEARCH_OVERLOAD
519 template<
class FORWARD_ITERATOR,
class SEARCHER>
521 FORWARD_ITERATOR
search(FORWARD_ITERATOR first,
522 FORWARD_ITERATOR last,
523 const SEARCHER& searcher);
530#ifndef BSLSTL_ALGORITHM_COPY_N_IS_ALIASED
535template <
class t_INPUT_ITERATOR,
class t_SIZE,
class t_OUTPUT_ITERATOR>
537t_OUTPUT_ITERATOR copy_n(t_INPUT_ITERATOR first,
539 t_OUTPUT_ITERATOR result);
552template <
class t_INPUT_ITERATOR,
class t_SIZE,
class t_OUTPUT_ITERATOR>
554t_OUTPUT_ITERATOR BloombergLP::bslstl::AlgorithmUtil::copyNImp(
555 t_INPUT_ITERATOR first,
557 t_OUTPUT_ITERATOR result,
558 const bsl::input_iterator_tag&)
560 for ( ; count > 0; --count) {
568template <
class t_RANDOM_ACCESS_ITERATOR,
570 class t_OUTPUT_ITERATOR>
572t_OUTPUT_ITERATOR BloombergLP::bslstl::AlgorithmUtil::copyNImp(
573 t_RANDOM_ACCESS_ITERATOR first,
575 t_OUTPUT_ITERATOR result,
576 const bsl::random_access_iterator_tag&)
578 return std::copy(first, first + count, result);
582template <
class CONTAINER,
class PREDICATE>
584typename CONTAINER::size_type
585BloombergLP::bslstl::AlgorithmUtil::containerEraseIf(CONTAINER& container,
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);
598 return oldSize - container.size();
601template <
class t_INPUT_ITERATOR,
class t_SIZE,
class t_OUTPUT_ITERATOR>
603t_OUTPUT_ITERATOR BloombergLP::bslstl::AlgorithmUtil::copyN(
604 t_INPUT_ITERATOR first,
606 t_OUTPUT_ITERATOR result)
608 typedef typename bsl::iterator_traits<t_INPUT_ITERATOR>::iterator_category
610 return BloombergLP::bslstl::AlgorithmUtil::copyNImp(first,
616#ifdef BSLSTL_ITERATOR_PROVIDE_SUN_CPP98_FIXES
617template <
class INPUT_ITERATOR,
class TYPE>
619typename bsl::iterator_traits<INPUT_ITERATOR>::difference_type
620bsl::count(INPUT_ITERATOR first, INPUT_ITERATOR last,
const TYPE& value)
622 typename bsl::iterator_traits<INPUT_ITERATOR>::difference_type ret = 0;
623 std::count(first, last, value, ret);
627template <
class INPUT_ITERATOR,
class PREDICATE>
629typename bsl::iterator_traits<INPUT_ITERATOR>::difference_type
630bsl::count_if(INPUT_ITERATOR first, INPUT_ITERATOR last, PREDICATE pred)
632 typename bsl::iterator_traits<INPUT_ITERATOR>::difference_type ret = 0;
633 std::count_if(first, last, pred, ret);
639#ifndef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
641template <
class INPUT_ITERATOR,
class PREDICATE>
642bool bsl::all_of(INPUT_ITERATOR first, INPUT_ITERATOR last, PREDICATE pred)
644 for (; first != last; ++first) {
652template <
class INPUT_ITERATOR,
class PREDICATE>
653bool bsl::any_of(INPUT_ITERATOR first, INPUT_ITERATOR last, PREDICATE pred)
655 for (; first != last; ++first) {
663template <
class INPUT_ITERATOR,
class PREDICATE>
664bool bsl::none_of(INPUT_ITERATOR first, INPUT_ITERATOR last, PREDICATE pred)
666 for (; first != last; ++first) {
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,
679 OUTPUT_ITERATOR result,
682 while(first != last) {
695#ifndef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
696template<
class TYPE,
class COMPARE>
699bsl::clamp(
const TYPE& value,
const TYPE& low,
const TYPE& high, COMPARE comp)
702 return comp(value, low) ? low : comp(high, value) ? high : value;
708bsl::clamp(
const TYPE& value,
const TYPE& low,
const TYPE& high)
710 return bsl::clamp(value, low, high, std::less<TYPE>());
715#ifndef BSLS_LIBRARYFEATURES_HAS_CPP17_SEARCH_OVERLOAD
716template<
class FORWARD_ITERATOR,
class SEARCHER>
720 FORWARD_ITERATOR last,
721 const SEARCHER& searcher)
728#ifndef BSLSTL_ALGORITHM_COPY_N_IS_ALIASED
729template <
class t_INPUT_ITERATOR,
class t_SIZE,
class t_OUTPUT_ITERATOR>
731t_OUTPUT_ITERATOR bsl::copy_n(t_INPUT_ITERATOR first,
733 t_OUTPUT_ITERATOR result)
735 return BloombergLP::bslstl::AlgorithmUtil::copyN(first,
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)