multidim

Multidim algorithms library

Multidim provides equivalent algorithms for most of the algorithms in the C++ algorithms library (<algorithm> and <numeric>).

Because of the ‘fake’ references (e.g. array_ref and dynarray_ref) used in Multidim, many of the functions provided in the C++ algorithms library may not work with Multidim’s iterators. Hence, Multidim provides its own algorithms that mimic those in the standard. See this page for the differences between Multidim’s iterators and a LegacyRandomAccessIterator.

Unlike many functions in the C++ algorithms library, functions in Multidim’s algorithms library have the following relaxation in requirements:

As such, whenever an algorithm in std:: may be used, the equivalent algorithm in multidim:: (if it exists) will most likely work too. However, there are a few std:: algorithms that do not have an equivalent, or require stronger iterator category requirements, in multidim:: because Multidim algorithms must never construct temporary elements.

Note: The Multidim algorithms library does not provide overloads for execution policies.

For the algorithms listed below, if the remarks column contains “Equivalent”, it means that code that use Multidim’s references with the std:: algorithm will probably work (even though it may be undefined behaviour).

Non-modifying sequence operations

Standard Algorithm Multidim Algorithm Remarks
std::all_of
std::any_of
std::none_of
multidim::all_of
multidim::any_of
multidim::none_of
Equivalent
std::for_each
std::for_each_n
multidim::for_each
multidim::for_each_n
Equivalent
- multidim::for_eachs
multidim::for_eachs_n
Like for_each/for_each_n, but allows multiple sequences to be iterated together
std::count_if
std::count_if
multidim::count_if
multidim::count_if
Equivalent
std::mismatch multidim::mismatch Equivalent
std::find
std::find_if
std::find_if_not
multidim::find
multidim::find_if
multidim::find_if_not
Equivalent
std::find_end multidim::find_end Equivalent
std::find_first_of multidim::find_first_of Equivalent
std::adjacent_find multidim::adjacent_find Equivalent
std::search multidim::search Equivalent, but Multidim does not provide the Searcher overload
std::search_n multidim::search_n Equivalent
- multidim::find_consecutive
multidim::find_consecutive_if
Finds a range of consecutive elements satisfying specific criteria; similar to multidim::search_n

Modifying sequence operations

Standard Algorithm Multidim Algorithm Remarks
std::copy
std::copy_if
std::copy_n
std::copy_backward
multidim::copy
multidim::copy_if
multidim::copy_n
multidim::copy_backward
Equivalent
std::move
std::move_backward
multidim::move
multidim::move_if
multidim::move_n
multidim::move_backward
Equivalent, but Multidim provides the extra versions move_if and move_n that are like copy_if and copy_n but moves elements
std::fill
std::fill_n
multidim::fill
multidim::fill_n
Equivalent
std::transform - Not provided by Multidim as the unary operation returns by value, which would construct a temporary; use multidim::for_eachs instead
std::generate
std::generate_n
- Not provided by Multidim as the generator returns by value, which would construct a temporary
std::remove
std::remove_if
multidim::remove
multidim::remove_if
Equivalent
std::remove_copy
std::remove_copy_if
multidim::remove_copy
multidim::remove_copy_if
Equivalent
std::replace
std::replace_if
multidim::replace
multidim::replace_if
Equivalent
std::replace_copy
std::replace_copy_if
multidim::replace_copy
multidim::replace_copy_if
Equivalent
std::swap - Use argument dependent lookup (ADL) to swap instead
std::swap_ranges multidim::swap_ranges Equivalent
std::iter_swap multidim::iter_swap Equivalent
std::reverse
std::reverse_copy
multidim::reverse
multidim::reverse_copy
Equivalent
std::rotate
std::rotate_copy
multidim::rotate
multidim::rotate_copy
Equivalent
std::shift_left
std::shift_right
multidim::shift_left
multidim::shift_right
Equivalent
std::unique multidim::unique Equivalent
std::unique_copy multidim::unique_copy Multidim requires either InputIt or OutputIt to satisfy LegacyForwardIterator

Randomizing sequence operations

Standard Algorithm Multidim Algorithm Remarks
std::shuffle multidim::shuffle Equivalent
std::sample multidim::sample Equivalent

Partitioning operations

Standard Algorithm Multidim Algorithm Remarks
std::is_partitioned multidim::is_partitioned Equivalent
std::partition multidim::partition Equivalent
std::partition_copy multidim::partition_copy Equivalent
std::stable_partition multidim::stable_partition The O(N) algorithm is not provided by Multidim because it allocates additional memory; an O(N log N) algorithm that does not allocate memory is used instead, and it only requires LegacyForwardIterator but not LegacyBidirectionalIterator
std::partition_point multidim::partition_point Equivalent