|
Devel Lib
|
This namespace includes utilities for working with vectors. More...
Functions | |
| template<typename T > | |
| bool | IsDataInVector (const std::vector< T > &i_atVector, const T &i_tData, size_t *i_pOutIndex=nullptr) |
| This function checks if a given data is present in the vector. More... | |
| template<typename T > | |
| bool | IsDataInSortedVector (const std::vector< T > &i_atVector, const T &i_tData, size_t *i_pOutIndex=nullptr) |
| This function checks if a given data is present in the sorted vector. More... | |
This namespace includes utilities for working with vectors.
Example
| bool Devel::VectorUtils::IsDataInSortedVector | ( | const std::vector< T > & | i_atVector, |
| const T & | i_tData, | ||
| size_t * | i_pOutIndex = nullptr |
||
| ) |
This function checks if a given data is present in the sorted vector.
Your vector must be sorted in ascending order for this function to work. It uses std::lower_bound to locate the input data in the vector. If it finds a match, it sets the index of the matching element to the out index (if provided) and returns true.
| [in] | i_atVector | The input vector. |
| [in] | i_tData | The data to search for in the vector. |
| [out] | i_pOutIndex | Pointer to an index variable where the index of the found element will be stored. If this parameter is not provided, the function simply checks if the data exists in the vector. |
| bool Devel::VectorUtils::IsDataInVector | ( | const std::vector< T > & | i_atVector, |
| const T & | i_tData, | ||
| size_t * | i_pOutIndex = nullptr |
||
| ) |
This function checks if a given data is present in the vector.
It uses std::find to locate the input data in the vector. If it finds a match, it sets the index of the matching element to the out index (if provided) and returns true.
| [in] | i_atVector | The input vector. |
| [in] | i_tData | The data to search for in the vector. |
| [out] | i_pOutIndex | Pointer to an index variable where the index of the found element will be stored. If this parameter is not provided, the function simply checks if the data exists in the vector. |