Documentation
Tools for embedded systems
|
A basic implementation of basic algorithms for raw-arrays without recursion and dynamic memory allocation. More...
Functions | |
template<typename T > | |
void | qlibs::algorithm::swap (T &x, T &y) noexcept |
Exchanges the values of a and b. | |
template<typename T , size_t n> | |
void | qlibs::algorithm::sort (T(&array)[n], size_t first=0U, size_t last=n - 1U, bool(*comp)(const T &, const T &)=nullptr) noexcept |
Sorts the given array in the range [first,last) into ascending order. | |
template<typename T , size_t n> | |
void | qlibs::algorithm::reverse (T(&array)[n], const size_t first=0U, const size_t last=n - 1U) noexcept |
Reverses the order of the elements in the range [first,last). | |
template<typename T , size_t n> | |
void | qlibs::algorithm::rotate (T(&array)[n], const int k=1) noexcept |
Rotates k elements of the array. Rotation direction is determined by the sign of k, the means a positive value performs a right-rotation and a negative value a left-rotation. | |
template<typename T , size_t n> | |
void | qlibs::algorithm::fill (T(&array)[n], const T value, const size_t first=0U, const size_t last=n - 1U) noexcept |
Assigns value to all the elements of the array in the range [first,last). | |
template<typename T , size_t n> | |
T * | qlibs::algorithm::find (T(&array)[n], const T key, const size_t first=0U, const size_t last=n - 1U) noexcept |
Returns a pointer to the first element in the range [first,last) that compares equal to key. If no such element is found, the function returns nullptr . | |
template<typename T , size_t n> | |
bool | qlibs::algorithm::any_of (T(&array)[n], bool(*pred)(const T), const size_t first=0U, const size_t last=n - 1U) noexcept |
Returns true if pred returns true for any of the elements in the range [first,last), and false otherwise. | |
template<typename T , size_t n> | |
bool | qlibs::algorithm::all_of (T(&array)[n], bool(*pred)(const T), const size_t first=0U, const size_t last=n - 1U) noexcept |
Returns true if pred returns true for all the elements in the range [first,last), and false otherwise. | |
template<typename T , size_t n> | |
void | qlibs::algorithm::replace (T(&array)[n], const T &old_value, const T &new_value, const size_t first=0U, const size_t last=n - 1U) noexcept |
Replaces all elements satisfying specific criteria with new_value in the range [first, last). Replaces all elements that are equal to old_value (using operator==) | |
template<typename T , size_t n> | |
void | qlibs::algorithm::replace_if (T(&array)[n], bool(*pred)(const T &), const T &new_value, const size_t first=0U, const size_t last=n - 1U) noexcept |
Replaces all elements satisfying specific criteria with new_value in the range [first, last). Replaces all elements for which predicate pred returns true . | |
template<typename T , size_t n> | |
size_t | qlibs::algorithm::count_if (T(&array)[n], bool(*pred)(const T), const size_t first=0U, const size_t last=n - 1U) noexcept |
Returns the number of elements in the range [first,last) for which pred is true . | |
template<typename T , size_t n> | |
T * | qlibs::algorithm::find_if (T(&array)[n], bool(*pred)(const T), const size_t first=0U, const size_t last=n - 1U) noexcept |
Returns an iterator to the first element in the range [first,last) for which pred returns true . If no such element is found, the function returns nullptr . | |
template<typename T , size_t n> | |
void | qlibs::algorithm::for_each (T(&array)[n], void(*fn)(T &), const size_t first=0U, const size_t last=n - 1U) noexcept |
Applies function fn to each of the elements in the range [first,last). | |
template<typename T , size_t n> | |
T * | qlibs::algorithm::binary_search (T(&array)[n], const T key, const size_t first=0U, const size_t last=n - 1U) noexcept |
Returns a pointer to the first element in the range [first,last) that compares equal to key. If no such element is found, the function returns nullptr . | |
A basic implementation of basic algorithms for raw-arrays without recursion and dynamic memory allocation.
|
inlinenoexcept |
Returns true
if pred returns true
for all the elements in the range [first,last), and false
otherwise.
[in] | array | The array where the check is performed |
[in] | pred | Unary function that accepts an element in the range as argument and returns a value convertible to bool. The value returned indicates whether the element fulfills the condition checked by this function. |
[in] | first | Initial position of the portion to check |
[in] | last | Final position of the portion to check |
true
if pred returns true for all the elements in the range [first,last), and false
otherwise.
|
inlinenoexcept |
Returns true
if pred returns true
for any of the elements in the range [first,last), and false
otherwise.
[in] | array | The array where the check is performed |
[in] | pred | Unary function that accepts an element in the range as argument and returns a value convertible to bool. The value returned indicates whether the element fulfills the condition checked by this function. |
[in] | first | Initial position of the portion to check |
[in] | last | Final position of the portion to check |
true
if pred returns true for any of the elements in the range [first,last), and false
otherwise.
|
inlinenoexcept |
Returns a pointer to the first element in the range [first,last) that compares equal to key. If no such element is found, the function returns nullptr
.
[in] | array | The array where the search is performed |
[in] | key | Value to search for in the range. T shall be a type supporting comparisons using operator== and operator<. |
[in] | first | Initial position of the portion to search |
[in] | last | Final position of the portion to search |
nullptr
pointer is returned.
|
inlinenoexcept |
Returns the number of elements in the range [first,last) for which pred
is true
.
[in] | array | The array where the count will be performed |
[in] | pred | Unary function that accepts an element in the range as argument, and returns a value convertible to bool. The value returned indicates whether the element is counted by this function. |
[in] | first | Initial position of the portion to check |
[in] | last | Final position of the portion to check |
false
.
|
inlinenoexcept |
Assigns value to all the elements of the array in the range [first,last).
[in,out] | array | The array to fill. |
[in] | value | The value to set all elements to. |
[in] | first | Initial position of the portion to fill |
[in] | last | Final position of the portion to fill |
|
inlinenoexcept |
Returns a pointer to the first element in the range [first,last) that compares equal to key. If no such element is found, the function returns nullptr
.
[in] | array | The array where the search is performed |
[in] | key | Value to search for in the range. T shall be a type supporting comparisons using operator==. |
[in] | first | Initial position of the portion to search |
[in] | last | Final position of the portion to search |
nullptr
pointer is returned.
|
inlinenoexcept |
Returns an iterator to the first element in the range [first,last) for which pred returns true
. If no such element is found, the function returns nullptr
.
[in] | array | The array where the search is performed |
[in] | pred | Unary function that accepts an element in the range as argument and returns a value convertible to bool. The value returned indicates whether the element is considered a match in the context of this function. |
[in] | first | Initial position of the portion to check |
[in] | last | Final position of the portion to check |
false
. If pred is false
for all elements, the function returns nullptr
.
|
inlinenoexcept |
Applies function fn to each of the elements in the range [first,last).
[in] | array | The array |
[in] | fn | Unary function that accepts an element in the range as argument. |
[in] | first | Initial position of the portion to check |
[in] | last | Final position of the portion to check |
|
inlinenoexcept |
Replaces all elements satisfying specific criteria with new_value in the range [first, last). Replaces all elements that are equal to old_value (using operator==)
[in] | array | The array where the check is performed |
[in] | old_value | The value of elements to replace |
[in] | new_value | The value to use as replacement |
[in] | first | Initial position of the portion to check |
[in] | last | Final position of the portion to check |
none
.
|
inlinenoexcept |
Replaces all elements satisfying specific criteria with new_value in the range [first, last). Replaces all elements for which predicate pred returns true
.
[in] | array | The array where the check is performed |
[in] | pred | Unary predicate which returns true if the element value should be replaced. |
[in] | new_value | The value to use as replacement |
[in] | first | Initial position of the portion to check |
[in] | last | Final position of the portion to check |
none
.
|
inlinenoexcept |
Reverses the order of the elements in the range [first,last).
[in,out] | array | The array to reverse. |
[in] | first | Initial position of the portion to reverse |
[in] | last | Final position of the portion to reverse |
|
noexcept |
Rotates k elements of the array. Rotation direction is determined by the sign of k, the means a positive value performs a right-rotation and a negative value a left-rotation.
[in,out] | array | The array to rotate. |
[in] | k | Positions to rotate. Sign determines the rotate direction. |
|
noexcept |
Sorts the given array in the range [first,last) into ascending order.
[in,out] | array | The array to be sorted. |
[in] | first | Initial position of the portion to be sorted |
[in] | last | Final position of the portion to be sorted |
[in] | comp | Comparison function which returns true if the first argument is less than (i.e. is ordered before) the second. The signature of the comparison function should be equivalent to the following: bool cmp(const Type1& a, const Type2& b); bool cmp( const T& a, const T& b );
|
|
noexcept |
Exchanges the values of a and b.
[in,out] | x | Object to be swapped. |
[in,out] | y | Object to be swapped. |