NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StlAlgorithms.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <algorithm>
31#include <iterator>
32#include <numeric>
33#include <utility>
34
35#if defined(__cpp_lib_parallel_algorithm) && defined(NUMCPP_USE_MULTITHREAD)
36#define PARALLEL_ALGORITHMS_SUPPORTED
37#define CONDITIONAL_NO_EXCEPT
38#include <execution>
39#else
40#define CONDITIONAL_NO_EXCEPT noexcept
41#endif
42
44{
45 //============================================================================
46 // Method Description:
54 template<class InputIt, class UnaryPredicate>
56 {
57 return std::all_of(
59 std::execution::par_unseq,
60#endif
61 first,
62 last,
63 p);
64 }
65
66 //============================================================================
67 // Method Description:
75 template<class InputIt, class UnaryPredicate>
77 {
78 return std::any_of(
80 std::execution::par_unseq,
81#endif
82 first,
83 last,
84 p);
85 }
86
87 //============================================================================
88 // Method Description:
96 template<class InputIt, class OutputIt>
98 {
99 return std::copy(
101 std::execution::par_unseq,
102#endif
103 first,
104 last,
106 }
107
108 //============================================================================
109 // Method Description:
117 template<class InputIt, class T>
118 typename std::iterator_traits<InputIt>::difference_type
120 {
121 return std::count(
123 std::execution::par_unseq,
124#endif
125 first,
126 last,
127 value);
128 }
129
130 //============================================================================
131 // Method Description:
139 template<class InputIt1, class InputIt2>
141 {
142 return std::equal(
144 std::execution::par_unseq,
145#endif
146 first1,
147 last1,
148 first2);
149 }
150
151 //============================================================================
152 // Method Description:
161 template<class InputIt1, class InputIt2, class BinaryPredicate>
163 {
164 return std::equal(
166 std::execution::par_unseq,
167#endif
168 first1,
169 last1,
170 first2,
171 p);
172 }
173
174 //============================================================================
175 // Method Description:
182 template<class ForwardIt, class T>
184 {
185 return std::fill(
187 std::execution::par_unseq,
188#endif
189 first,
190 last,
191 value);
192 }
193
194 //============================================================================
195 // Method Description:
204 template<class InputIt, class T>
206 {
207 return std::find(
209 std::execution::par_unseq,
210#endif
211 first,
212 last,
213 value);
214 }
215
216 //============================================================================
217 // Method Description:
224 template<class InputIt, class UnaryFunction>
226 {
227 std::for_each(
229 std::execution::par_unseq,
230#endif
231 first,
232 last,
233 f);
234 }
235
236 //============================================================================
237 // Method Description:
244 template<class ForwardIt>
246 {
247 return std::is_sorted(
249 std::execution::par_unseq,
250#endif
251 first,
252 last);
253 }
254
255 //============================================================================
256 // Method Description:
264 template<class ForwardIt, class Compare>
266 {
267 return std::is_sorted(
269 std::execution::par_unseq,
270#endif
271 first,
272 last,
273 comp);
274 }
275
276 //============================================================================
277 // Method Description:
284 template<class ForwardIt>
286 {
287 return std::max_element(
289 std::execution::par_unseq,
290#endif
291 first,
292 last);
293 }
294
295 //============================================================================
296 // Method Description:
304 template<class ForwardIt, class Compare>
306 {
307 return std::max_element(
309 std::execution::par_unseq,
310#endif
311 first,
312 last,
313 comp);
314 }
315
316 //============================================================================
317 // Method Description:
323 template<class ForwardIt>
325 {
326 return std::min_element(
328 std::execution::par_unseq,
329#endif
330 first,
331 last);
332 }
333
334 //============================================================================
335 // Method Description:
343 template<class ForwardIt, class Compare>
345 {
346 return std::min_element(
348 std::execution::par_unseq,
349#endif
350 first,
351 last,
352 comp);
353 }
354
355 //============================================================================
356 // Method Description:
363 template<class ForwardIt>
365 {
366 return std::minmax_element(
368 std::execution::par_unseq,
369#endif
370 first,
371 last);
372 }
373
374 //============================================================================
375 // Method Description:
383 template<class ForwardIt, class Compare>
385 {
386 return std::minmax_element(
388 std::execution::par_unseq,
389#endif
390 first,
391 last,
392 comp);
393 }
394
395 //============================================================================
396 // Method Description:
404 template<class InputIt, class UnaryPredicate>
406 {
407 return std::none_of(
409 std::execution::par_unseq,
410#endif
411 first,
412 last,
413 p);
414 }
415
416 //============================================================================
417 // Method Description:
424 template<class RandomIt>
426 {
427 std::nth_element(
429 std::execution::par_unseq,
430#endif
431 first,
432 nth,
433 last);
434 }
435
436 //============================================================================
437 // Method Description:
445 template<class RandomIt, class Compare>
447 {
448 std::nth_element(
450 std::execution::par_unseq,
451#endif
452 first,
453 nth,
454 last,
455 comp);
456 }
457
458 //============================================================================
459 // Method Description:
467 template<class ForwardIt, class T>
469 {
470 std::replace(
472 std::execution::par_unseq,
473#endif
474 first,
475 last,
476 oldValue,
477 newValue);
478 }
479
480 //============================================================================
481 // Method Description:
487 template<class BidirIt>
489 {
490 std::reverse(
492 std::execution::par_unseq,
493#endif
494 first,
495 last);
496 }
497
498 //============================================================================
499 // Method Description:
506 template<class ForwardIt>
508 {
509 std::rotate(
511 std::execution::par_unseq,
512#endif
513 first,
514 firstN,
515 last);
516 }
517
518 //============================================================================
519 // Method Description:
529 template<class InputIt1, class InputIt2, class OutputIt>
531 {
532 return std::set_difference(
534 std::execution::par_unseq,
535#endif
536 first1,
537 last1,
538 first2,
539 last2,
541 }
542
543 //============================================================================
544 // Method Description:
555 template<class InputIt1, class InputIt2, class OutputIt, class Compare>
562 {
563 return std::set_difference(
565 std::execution::par_unseq,
566#endif
567 first1,
568 last1,
569 first2,
570 last2,
572 comp);
573 }
574
575 //============================================================================
576 // Method Description:
586 template<class InputIt1, class InputIt2, class OutputIt>
589 {
590 return std::set_intersection(
592 std::execution::par_unseq,
593#endif
594 first1,
595 last1,
596 first2,
597 last2,
599 }
600
601 //============================================================================
602 // Method Description:
613 template<class InputIt1, class InputIt2, class OutputIt, class Compare>
620 {
621 return std::set_intersection(
623 std::execution::par_unseq,
624#endif
625 first1,
626 last1,
627 first2,
628 last2,
630 comp);
631 }
632
633 //============================================================================
634 // Method Description:
644 template<class InputIt1, class InputIt2, class OutputIt>
647 {
648 return std::set_union(
650 std::execution::par_unseq,
651#endif
652 first1,
653 last1,
654 first2,
655 last2,
657 }
658
659 //============================================================================
660 // Method Description:
671 template<class InputIt1, class InputIt2, class OutputIt, class Compare>
675 {
676 return std::set_union(
678 std::execution::par_unseq,
679#endif
680 first1,
681 last1,
682 first2,
683 last2,
685 comp);
686 }
687
688 //============================================================================
689 // Method Description:
695 template<class RandomIt>
697 {
698 return std::sort(
700 std::execution::par_unseq,
701#endif
702 first,
703 last);
704 }
705
706 //============================================================================
707 // Method Description:
714 template<class RandomIt, class Compare>
716 {
717 return std::sort(
719 std::execution::par_unseq,
720#endif
721 first,
722 last,
723 comp);
724 }
725
726 //============================================================================
727 // Method Description:
733 template<class RandomIt>
735 {
736 std::stable_sort(
738 std::execution::par_unseq,
739#endif
740 first,
741 last);
742 }
743
744 //============================================================================
745 // Method Description:
752 template<class RandomIt, class Compare>
754 {
755 std::stable_sort(
757 std::execution::par_unseq,
758#endif
759 first,
760 last,
761 comp);
762 }
763
764 //============================================================================
765 // Method Description:
774 template<class InputIt, class OutputIt, class UnaryOperation>
776 {
777 return std::transform(
779 std::execution::par_unseq,
780#endif
781 first,
782 last,
785 }
786
787 //============================================================================
788 // Method Description:
798 template<class InputIt1, class InputIt2, class OutputIt, class BinaryOperation>
801 {
802 return std::transform(
804 std::execution::par_unseq,
805#endif
806 first1,
807 last1,
808 first2,
811 }
812
813 //============================================================================
814 // Method Description:
822 template<class InputIt, class OutputIt>
824 {
825 return std::unique_copy(
827 std::execution::par_unseq,
828#endif
829 first,
830 last,
832 }
833
834 //============================================================================
835 // Method Description:
844 template<class InputIt, class OutputIt, class BinaryPredicate>
847 {
848 return std::unique_copy(
850 std::execution::par_unseq,
851#endif
852 first,
853 last,
856 }
857} // namespace nc::stl_algorithms
#define CONDITIONAL_NO_EXCEPT
Definition StlAlgorithms.hpp:40
Definition StlAlgorithms.hpp:44
bool any_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition StlAlgorithms.hpp:76
std::iterator_traits< InputIt >::difference_type count(InputIt first, InputIt last, const T &value) noexcept
Definition StlAlgorithms.hpp:119
void sort(RandomIt first, RandomIt last) noexcept
Definition StlAlgorithms.hpp:696
OutputIt set_union(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination) noexcept
Definition StlAlgorithms.hpp:645
bool none_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition StlAlgorithms.hpp:405
ForwardIt max_element(ForwardIt first, ForwardIt last) noexcept
Definition StlAlgorithms.hpp:285
void stable_sort(RandomIt first, RandomIt last) noexcept
Definition StlAlgorithms.hpp:734
void reverse(BidirIt first, BidirIt last) noexcept
Definition StlAlgorithms.hpp:488
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition StlAlgorithms.hpp:775
bool all_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition StlAlgorithms.hpp:55
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition StlAlgorithms.hpp:225
InputIt find(InputIt first, InputIt last, const T &value) noexcept
Definition StlAlgorithms.hpp:205
constexpr OutputIt unique_copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition StlAlgorithms.hpp:823
OutputIt set_difference(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination)
Definition StlAlgorithms.hpp:530
void replace(ForwardIt first, ForwardIt last, const T &oldValue, const T &newValue) noexcept
Definition StlAlgorithms.hpp:468
OutputIt set_intersection(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination) noexcept
Definition StlAlgorithms.hpp:587
bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2) noexcept
Definition StlAlgorithms.hpp:140
std::pair< ForwardIt, ForwardIt > minmax_element(ForwardIt first, ForwardIt last) noexcept
Definition StlAlgorithms.hpp:364
bool is_sorted(ForwardIt first, ForwardIt last) noexcept
Definition StlAlgorithms.hpp:245
void rotate(ForwardIt first, ForwardIt firstN, ForwardIt last) noexcept
Definition StlAlgorithms.hpp:507
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition StlAlgorithms.hpp:97
void nth_element(RandomIt first, RandomIt nth, RandomIt last) noexcept
Definition StlAlgorithms.hpp:425
ForwardIt min_element(ForwardIt first, ForwardIt last) noexcept
Definition StlAlgorithms.hpp:324
void fill(ForwardIt first, ForwardIt last, const T &value) noexcept
Definition StlAlgorithms.hpp:183
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59