6.5. Querying Algorithms
Table 6.1 describes the MPL's sequence querying algorithms. Most of these should be immediately familiar to STL users, with the possible exception of contains, which is so simple and useful that it probably should have been one of the STL algorithms to begin with. Similarly to the corresponding STL algorithms, compare predicates default to mpl::less<_,_> but, if supplied, must induce a strict weak ordering on their arguments.
Table 6.1. Sequence Querying AlgorithmsMetafunction | Result ::type | Complexity |
---|
mpl::find<seq, T> | An iterator to the first occurrence of T in seq, or mpl::end<seq>::type if not found. | Linear. | mpl::find_if<seq, T, pred> | An iterator to the first element of seq that satisfies predicate pred, or mpl::end<seq>::type if not found. | Linear. | mpl::contains<seq, T> | True iff seq contains T. | Linear. | mpl::count<seq, T> | The number of occurrences of T in seq. | Linear. | mpl::count_if<seq, pred> | The number of elements in seq that satisfy predicate pred. | Linear. | mpl::equal<seq1, seq2> | True iff seq1 and seq2 contain the same elements in the same order. | Linear. | mpl::lower_bound< seq, T , compare > | The earliest order-preserving position at which T could be inserted in a sequence seq sorted according to comparison compare. | Logarithmic in invocations to compare. Logarithmic traversal of Random Access Sequences; linear traversal otherwise. | mpl::upper_bound< seq, T , compare > | The latest order-preserving position at which T could be inserted in a sequence seq sorted according to comparison compare. | Logarithmic in invocations to compare. Logarithmic traversal of Random Access Sequences; linear traversal otherwise. | mpl::max_element< seq , compare > | The first position i in seq such that for all positions j: mpl::apply< compare , mpl::deref<i>::type , mpl::deref<j>::type >::type::value == false | Linear. | mpl::min_element< seq , compare > | The first position i in seq such that for all positions j: mpl::apply< compare , mpl::deref<j>::type , mpl::deref<i>::type >::type::value == false | Linear. |
 |