|
| auto | get_it () const |
| |
| auto | get_it (size_t pos) const |
| |
| auto | get_itor () const |
| |
|
Type & | nth_ne (const size_t n) noexcept |
| |
| const Type & | nth_ne (const size_t n) const noexcept |
| |
| Type & | nth (const size_t n) |
| |
| const Type & | nth (const size_t n) const |
| |
| template<class Operation > |
| Type * | find_ptr (Operation &operation) noexcept(noexcept(operation)) |
| |
| template<class Operation > |
| const Type * | find_ptr (Operation &operation) const noexcept(noexcept(operation)) |
| |
| template<class Operation > |
| const Type * | find_ptr (Operation &&operation) const noexcept(noexcept(operation)) |
| |
| template<class Operation > |
| Type * | find_ptr (Operation &&operation) noexcept(noexcept(operation)) |
| |
| template<class Operation > |
| size_t | find_index (Operation &operation) const noexcept(noexcept(operation)) |
| |
| template<class Operation > |
| size_t | find_index (Operation &&operation) const noexcept(noexcept(operation)) |
| |
| template<class Operation > |
| std::tuple< bool, Type > | find_item (Operation &operation) noexcept(noexcept(operation)) |
| |
| template<class Operation > |
| std::tuple< bool, Type > | find_item (Operation &operation) const noexcept(noexcept(operation)) |
| |
| template<class Operation > |
| std::tuple< bool, Type > | find_item (Operation &&operation) noexcept(noexcept(operation)) |
| |
| template<class Operation > |
| std::tuple< bool, Type > | find_item (Operation &&operation) const noexcept(noexcept(operation)) |
| |
template<class Container, typename Type>
class LocateFunctions< Container, Type >
Common sequential searching methods on containers.
This classs implements common sequential searching on containers.
- Note
- Take in account that any of these searches takes
of complexity for the worst case and that this is independent of type of container. For example, a hash table or a binary search tree, exports its own search that is much more faster that any of these primitives. As an advice: do not use this method inside loops. If you find yourself in this situation, then consider to revise your design and to use another search method. Use these primitives very few times, for algorithms whose complexity is by far greater that
and when you cannot index with an adequate data structure.
- Warning
- Be very careful about the fact that many of these primitives return pointers or references to container's data. In many cases, alteration of that data will corrupt the internal state of container.
template<class Container , typename Type >
template<class Operation >
| size_t LocateFunctions< Container, Type >::find_index |
( |
Operation & |
operation | ) |
const |
|
inlinenoexcept |
Find the position of an item in the container according to a searching criteria.
find_index(operation) traverses the container and on each item perform operation(item). If the result of operation is true, then the traversal is stopped and the position of the current item (which mathes operation) is returned.
operation must have the following signature:
bool operation(const typename Container::Item_Type & item)
- Warning
- Frequent use of this method will definitively degrade the performance. Try not to use this method inside loops. In general, if you falls in this situation, the consider your design and use a faster approach.
- Parameters
-
| [in] | <tt>operation</tt> | to be performed on each item for matching a searching criteria. |
- Returns
- the last seen position. If the item is not found, then the number of items is returned.
template<class Container , typename Type >
template<class Operation >
| std::tuple<bool, Type> LocateFunctions< Container, Type >::find_item |
( |
Operation & |
operation | ) |
|
|
inlinenoexcept |
Safe sequential searching of an item matching a criteria.
find_item(operation) traverses the container and on each item perform operation(item). If the result of operation is true, then the traversal is stopped and duple containg a copy of found item is returned.
The method is said safe because returns a copy of item.
operation must have the following signature:
bool operation(const typename Container::Item_Type & item)
- Parameters
-
| [in] | <tt>operation</tt> | to be used as searching criteria |
- Returns
- a duple tuple<bool, Type>. The first field indicates if the item was found and the second contains a copy of found item. If no item is found, then the first field is
false and the second is the result of default constructor on the type stored in the container.
template<class Container , typename Type >
template<class Operation >
| Type* LocateFunctions< Container, Type >::find_ptr |
( |
Operation & |
operation | ) |
|
|
inlinenoexcept |
Find a pointer to an item in the container according to a searching criteria.
find_ptr(operation) traverses the container and on each item perform operation(item). If the result of operation is true, then the traversal is stopped and a pointer to the current item (which mathes operation) is returned.
operation must have the following signature:
bool operation(const typename Container::Item_Type & item)
- Warning
- Frequent use of this method will definitively degrade the performance. Try not to use this method inside loops. In general, if you falls in thie situation, the consider your design and to use an faster approach.
- Parameters
-
| [in] | <tt>operation</tt> | to be performed on each item for matching a searching criteria. |
- Returns
- a valid pointer to an item if this was found or
nullptr otherwise.
template<class Container , typename Type >
Return the n-th item of container.
The notion of ordinal depends of type of container. On list, probably will be the insertion order. On binary search trees will be the nth smaller item. On hash tables will be pseudo random.
- Warning
- Frequent use of this method will definitively degrade the performance. Try not to use this method inside loops. In general, if you falls in this situation, then consider your design and to use an faster approach.
- Parameters
-
| [in] | n | the nth item to find |
- Returns
- a valid reference to the item into the container.
- Exceptions
-
| out_of_range | if n is greater or equal that the size of container. |