AceCommon  1.4.5
Arduino library for low-level common functions and features with no external dependencies
Functions
isSorted.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename K >
bool ace_common::isSortedByKey (size_t size, K &&key)
 Determine if the abstract array is sorted according to its 'key'. More...
 
template<typename X >
bool ace_common::isSorted (const X list[], size_t size)
 Simplified version of isSortedByKey() where the elements of the array and the type returned by the key lambda expression is the same. More...
 

Detailed Description

Templatized function that determines of an array of things is sorted according to the given key.

Definition in file isSorted.h.

Function Documentation

◆ isSorted()

template<typename X >
bool ace_common::isSorted ( const X  list[],
size_t  size 
)

Simplified version of isSortedByKey() where the elements of the array and the type returned by the key lambda expression is the same.

So the key lambda expression is just list[i].

This function assumes that 'operator<()' for the value type X is defined.

Template Parameters
Xtype of element in list
Parameters
listsorted array of elements of type X (accepts both const array or a pointer to the array)
sizenumber of elements

Definition at line 84 of file isSorted.h.

◆ isSortedByKey()

template<typename K >
bool ace_common::isSortedByKey ( size_t  size,
K &&  key 
)

Determine if the abstract array is sorted according to its 'key'.

Returns true if sorted, false if not sorted. Returns false if the size of the array is 0.

This function assumes that 'operator<()' for the value type of key is defined.

Performance Note: Many compilers (all?) are not able to opimize away the function call overhead of the lambda expression. If performance is critical, you should copy and modify this code instead.

Template Parameters
Klambda expression or function pointer that returns some unspecified value at index 'i'. The type of the value is inferred automatically using the 'auto' keyword.
Parameters
sizenumber of elements in the array
keya function or lambda expression that returns the value at index 'i'. If the 'key' inlined, I think the compiler is smart enough to inline the 'key' into this code, and avoid a function call.

Definition at line 59 of file isSorted.h.