For a sequence `Seq`, initial state, and binary function object or function pointer `f`, fold repeatedly applies binary `f` to each element of `Seq` and the previous state.
[[`seq`][A model of __forward_sequence__,`f(e,s)` must be a valid expression for each element `e` in `seq`, and current state `s`][Operation's argument]]
[[`f`][`__boost_result_of_call__<F(E,S)>::type` is the return type of `f(e,s)` for each element `e` of type `E` in `seq`, and current state `s` of type `S`][Operation's argument]]
For a sequence `Seq`, initial state, and binary function object or function pointer `f`, accumulate repeatedly applies binary `f` to each element of `Seq` and the previous state.
Sequence& seq, State const& initial_state, F const& f);
[table Parameters
[[Parameter][Requirement][Description]]
[[`seq`][A model of __forward_sequence__, `f(eN ....f(e2,f(e1,initial_state)))` must be a valid expression for each element `e1` to `eN` in `seq`][Operation's argument]]
[[`f`][`__boost_result_of_call__<F(E,S)>::type` is the return type of `f(e,s)` for each element `e` of type `E` in `seq`, and current state `s` of type `S`][Operation's argument]]
[[`F`] [`__boost_result_of_call__<F(E,S)>::type` is the return type of `f(e,s)` for each element `e` of type `E` in `seq`, and current state `s` of type `S`] [The operation to be applied on forward traversal]]
[[`F`] [`__boost_result_of_call__<F(E,S)>::type` is the return type of `f(e,s)` for each element `e` of type `E` in `seq`, and current state `s` of type `S`] [The operation to be applied on forward traversal]]
The query algorithms provide support for searching and analyzing sequences.
[heading Header]
#include <boost/fusion/algorithm/query.hpp>
[section Functions]
[section any]
[heading Description]
For a sequence `seq` and unary function object `f`, `any` returns true if `f` returns true for at least one element of `seq`.
[heading Synopsis]
template<
typename Sequence,
typename F
>
typename __result_of_any__<Sequence,F>::type any(
Sequence const& seq, F f);
[table Parameters
[[Parameter][Requirement][Description]]
[[`seq`][A model of __forward_sequence__, `f(e)` must be a valid expression, convertible to `bool`, for each element `e` in `seq`][The sequence to search]]
[[`f`][A unary function object][The search predicate]]
]
[heading Expression semantics]
__any__(seq, f);
[*Return type]: `bool`
[*Semantics]: Returns true if and only if `f(e)` evaluates to `true` for some element `e` in `seq`.
[heading Complexity]
Linear. At most `__result_of_size__<Sequence>::value` comparisons.
[heading Header]
#include <boost/fusion/algorithm/query/any.hpp>
[heading Example]
struct odd
{
template<typename T>
bool operator()(T t) const
{
return t % 2;
}
};
...
assert(__any__(__make_vector__(1,2), odd()));
assert(!__any__(__make_vector__(2,4), odd()));
[endsect]
[section all]
[heading Description]
For a sequence `seq` and unary function object `f`, `all` returns true if `f` returns true for every element of `seq`.
[heading Synopsis]
template<
typename Sequence,
typename F
>
typename __result_of_all__<Sequence,F>::type all(
Sequence const& seq, F f);
[table Parameters
[[Parameter][Requirement][Description]]
[[`seq`][A model of __forward_sequence__, `f(e)` is a valid expression, convertible to `bool`, for every element `e` in `seq`][The sequence to search]]
[[`f`][A unary function object][The search predicate]]
]
[heading Expression Semantics]
__all__(seq, f);
[*Return type]: `bool`
[*Semantics]: Returns true if and only if `f(e)` evaluates to `true` for every element `e` in `seq`.
[heading Complexity]
Linear. At most `__result_of_size__<Sequence>::value` comparisons.
[heading Header]
#include <boost/fusion/algorithm/query/all.hpp>
[heading Example]
struct odd
{
template<typename T>
bool operator()(T t) const
{
return t % 2;
}
};
...
assert(__all__(__make_vector__(1,3), odd()));
assert(!__all__(__make_vector__(1,2), odd()));
[endsect]
[section none]
[heading Description]
For a sequence `seq` and unary function object `f`, `none` returns true if `f` returns false for every element of `seq`.
[[`seq`][A model of __forward_sequence__, `f(e)` is a valid expression, convertible to `bool`, for every element `e` in `seq`][The sequence to search]]
[[`f`][A unary function object][The search predicate]]
]
[heading Expression Semantics]
__none__(seq, f);
[*Return type]: `bool`
[*Semantics]: Returns true if and only if `f(e)` evaluates to `false` for every element `e` in `seq`. Result equivalent to `!any(seq, f)`.
[heading Complexity]
Linear. At most `__result_of_size__<Sequence>::value` comparisons.
[heading Header]
#include <boost/fusion/algorithm/query/none.hpp>
[heading Example]
struct odd
{
template<typename T>
bool operator()(T t) const
{
return t % 2;
}
};
...
assert(__none__(__make_vector__(2,4), odd()));
assert(!__none__(__make_vector__(1,2), odd()));
[endsect]
[section find]
[heading Description]
Finds the first element of a given type within a sequence.
[[`seq`][A model of __forward_sequence__, `e == t` must be a valid expression, convertible to `bool`, for each element `e` in `seq`][The sequence to search]]
[[`T`][Any type][The type to count]]
]
[heading Expression Semantics]
__count__(seq, t);
[*Return type]: `int`
[*Semantics]: Returns the number of elements of type `T` and equal to `t` in `seq`.
[heading Complexity]
Linear. At most `__result_of_size__<Sequence>::value` comparisons.
[heading Header]
#include <boost/fusion/algorithm/query/count.hpp>
[heading Example]
const __vector__<double,int,int> vec(1.0,2,3);
assert(__count__(vec,2) == 1);
[endsect]
[section count_if]
[heading Description]
Returns the number of elements within a sequence with a type for which a given unary function object evaluates to
A metafunction returning the result type of __any__.
[heading Synopsis]
template<
typename Sequence,
typename F
>
struct any
{
typedef bool type;
};
[table Parameters
[[Parameter] [Requirement] [Description]]
[[`Sequence`] [A model of __forward_sequence__] [Operation's argument]]
[[`F`] [A model of unary __poly_func_obj__] [Operation's argument]]
]
[heading Expression Semantics]
__result_of_any__<Sequence, F>::type
[*Return type]: `bool`.
[*Semantics]: Returns the return type of __any__ given a sequence of type `Sequence` and a unary __poly_func_obj__ of type `F`. The return type is always `bool`.
[heading Complexity]
Constant.
[heading Header]
#include <boost/fusion/algorithm/query/any.hpp>
[endsect]
[section all]
[heading Description]
A metafunction returning the result type of __all__.
[heading Synopsis]
template<
typename Sequence,
typename F
>
struct all
{
typedef bool type;
};
[table Parameters
[[Parameter] [Requirement] [Description]]
[[`Sequence`] [A model of __forward_sequence__] [Operation's argument]]
[[`F`] [A model of unary __poly_func_obj__] [Operation's argument]]
]
[heading Expression Semantics]
__result_of_all__<Sequence, F>::type
[*Return type]: `bool`.
[*Semantics]: Returns the return type of __all__ given a sequence of type `Sequence` and a unary __poly_func_obj__ of type `F`. The return type is always `bool`.
[heading Complexity]
Constant.
[heading Header]
#include <boost/fusion/algorithm/query/all.hpp>
[endsect]
[section none]
[heading Description]
A metafunction returning the result type of __none__.
[heading Synopsis]
template<
typename Sequence,
typename F
>
struct none
{
typedef bool type;
};
[table Parameters
[[Parameter] [Requirement] [Description]]
[[`Sequence`] [A model of __forward_sequence__] [Operation's argument]]
[[`F`] [A model of unary __poly_func_obj__] [Operation's argument]]
]
[heading Expression Semantics]
__result_of_none__<Sequence, F>::type
[*Return type]: `bool`.
[*Semantics]: Returns the return type of __none__ given a sequence of type `Sequence` and a unary __poly_func_obj__ of type `F`. The return type is always `bool`.
[heading Complexity]
Constant.
[heading Header]
#include <boost/fusion/algorithm/query/none.hpp>
[endsect]
[section find]
[heading Description]
Returns the result type of `find`, given the sequence and search types.
[heading Synopsis]
template<
typename Sequence,
typename T
>
struct find
{
typedef __unspecified__ type;
};
[table Parameters
[[Parameter] [Requirement] [Description]]
[[`Sequence`] [Model of __forward_sequence__] [Operation's argument]]
[[`T`] [Any type] [Operation's argument]]
]
[heading Expression Semantics]
__result_of_find__<Sequence, T>::type
[*Return type]: A model of the same iterator category as the iterators of `Sequence`.
[*Semantics]: Returns an iterator to the first element of type `T` in `Sequence`, or `__result_of_end__<Sequence>::type` if there is no such element.
[heading Complexity]
Linear, at most `__result_of_size__<Sequence>::value` comparisons.
[heading Header]
#include <boost/fusion/algorithm/query/find.hpp>
[endsect]
[section find_if]
[heading Description]
Returns the result type of `find_if` given the sequence and predicate types.
[heading Synopsis]
template<
typename Sequence,
typename Pred
>
struct find_if
{
typedef __unspecified__ type;
};
[table Parameters
[[Parameter] [Requirement] [Description]]
[[`Sequence`] [A model of __forward_sequence__] [Operation's argument]]
[[`Pred`] [A model of __mpl_lambda_expression__] [Operation's arguments]]
]
[heading Expression Semantics]
__result_of_find_if__<Sequence, Pred>::type
[*Return type]: A model of the same iterator category as the iterators of `Sequence`.
[*Semantics]: Returns an iterator to the first element in `Sequence` for which `Pred` evaluates to true. Returns `__result_of_end__<Sequence>::type` if there is no such element.
[heading Complexity]
Linear. At most `__result_of_size__<Sequence>::value` comparisons.
The transformation algorithms create new sequences out of existing sequences by performing some sort of transformation. In reality the new sequences are views onto the data in the original sequences.
[note As the transformation algorithms return views onto their input arguments,
it is important that the lifetime of the input arguments is greater than the
[[`f`][`f(e)` is a valid expression for each element `e` of `seq`. `__boost_result_of_call__<F(E)>::type` is the return type of `f` when called with a value of each element type `E`.][Transformation function]]
[[`f`][`f(e1,e2)` is a valid expression for each pair of elements `e1` of `seq1` and `e2` of `seq2`. `__boost_result_of_call__<F(E1,E2)>::type` is the return type of `f` when called with elements of type `E1` and `E2`][Transformation function]]
[*Semantics]: Returns a new sequence, containing the return values of `f(e1, e2)` for each pair of elements `e1` and `e2` within `seq1` and `seq2` respectively.
[heading Complexity]
Constant. Returns a view which is lazily evaluated.
Sequence const& seq, T const& old_value, T const& new_value);
[table Parameters
[[Parameter][Requirement][Description]]
[[`seq`][A model of __forward_sequence__, `e == old_value` is a valid expression, convertible to `bool`, for each element `e` in `seq` with type convertible to `T`][Operation's argument]]
[[`old_value`][Any type][Value to replace]]
[[`new_value`][Any type][Replacement value]]
]
[heading Expression Semantics]
__replace__(seq, old_value, new_value);
[*Return type]: A model of __forward_sequence__.
[*Semantics]: Returns a new sequence with all the values of `seq` with `new_value` assigned to elements with the same type and equal to `old_value`.
[heading Complexity]
Constant. Returns a view which is lazily evaluated.
[[`seq1` to `seqN`][Each sequence is a model of __forward_sequence__.][Operation's argument]]
]
[heading Expression Semantics]
__zip__(seq1, seq2, ... seqN);
[*Return type]: A model of __forward_sequence__.
[*Semantics]: Returns a sequence containing tuples of elements from sequences `seq1` to `seqN`. For example, applying zip to tuples `(1, 2, 3)` and `('a', 'b', 'c')` would return `((1, 'a'),(2, 'b'),(3, 'c'))`
[heading Complexity]
Constant. Returns a view which is lazily evaluated.
[[`seq`][A model of __forward_sequence__][Operation's argument]]
]
[heading Expression Semantics]
__pop_back__(seq);
[*Return type]: A model of __forward_sequence__.
[*Semantics]: Returns a new sequence containing all the elements of `seq`, except the last element. The elements in the new sequence are in the same order as they were in `seq`.
[heading Complexity]
Constant. Returns a view which is lazily evaluated.
[[`seq`][A model of __forward_sequence__][Operation's argument]]
]
[heading Expression Semantics]
__pop_front__(seq);
[*Return type]: A model of __forward_sequence__.
[*Semantics]: Returns a new sequence containing all the elements of `seq`, except the first element. The elements in the new sequence are in the same order as they were in `seq`.
[heading Complexity]
Constant. Returns a view which is lazily evaluated.
[[`seq`][A model of __forward_sequence__][Operation's argument]]
[[`t`][Any type][The value to add to the end]]
]
[heading Expression Semantics]
__push_back__(seq, t);
[*Return type]: A model of __forward_sequence__.
[*Semantics]: Returns a new sequence, containing all the elements of `seq`, and new element `t` appended to the end. The elements are in the same order as they were in `seq`.
[heading Complexity]
Constant. Returns a view which is lazily evaluated.
[[`seq`][A model of __forward_sequence__][Operation's argument]]
[[`t`][Any type][The value to add to the beginning]]
]
[heading Expression Semantics]
__push_back__(seq, t);
[*Return type]: A model of __forward_sequence__.
[*Semantics]: Returns a new sequence, containing all the elements of `seq`, and new element `t` appended to the beginning. The elements are in the same order as they were in `seq`.
[heading Complexity]
Constant. Returns a view which is lazily evaluated.
Returns the result type of __filter__ given the sequence type and type to retain.
[heading Synopsis]
template<
typename Sequence,
typename T
>
struct filter
{
typedef __unspecified__ type;
};
[table Parameter
[[Parameter] [Requirement] [Description]]
[[`Sequence`][A model of __forward_sequence__] [Operation's argument]]
[[`T`][Any type][Type to retain]]
]
[heading Expression Semantics]
__result_of_filter__<Sequence, T>::type
[*Return type]: A model of __forward_sequence__.
[*Semantics]: Returns a sequence containing the elements of `Sequence` that are of type `T`. Equivalent to `__result_of_filter_if__<Sequence, boost::is_same<mpl::_, T> >::type`.
[[`seq`][A model of __forward_sequence__][Operation's argument]]
[[`f`][`f(e)` is a valid expression for each element `e` of `seq`. `__boost_result_of_call__<F(E)>::type` is the return type of `f` when called with a value of each element type `E`.][Transformation function]]
Sequence1 const& seq1, Sequence2 const& seq2, F f);
[table Parameters
[[Parameter][Requirement][Description]]
[[`seq1`][A model of __forward_sequence__][Operation's argument]]
[[`seq2`][A model of __forward_sequence__][Operation's argument]]
[[`f`][`f(e1,e2)` is a valid expression for each pair of elements `e1` of `seq1` and `e2` of `seq2`. `__boost_result_of_call__<F(E1,E2)>::type` is the return type of `f` when called with elements of type `E1` and `E2`][Transformation function]]
[*Semantics]: Returns a new sequence, containing the return values of `f(e1, e2)` for each pair of elements `e1` and `e2` within `seq1` and `seq2` respectively.
Returns the result type of __remove__, given the sequence and removal types.
[heading Synopsis]
template<
typename Sequence,
typename T
>
struct remove
{
typedef __unspecified__ type;
};
[table Parameters
[[Parameter][Requirement][Description]]
[[`Sequence`][A model of __forward_sequence__][Operation's argument]]
[[`T`][Any type][Remove elements of this type]]
]
[heading Expression Semantics]
__result_of_remove__<Sequence, T>::type
[*Return type]: A model of __forward_sequence__.
[*Semantics]: Returns a sequence containing the elements of `Sequence` not of type `T`. Equivalent to `__result_of_replace_if__<Sequence, boost::is_same<mpl::_, T> >::type`.
Returns the result of joining 2 sequences, given the sequence types.
[heading Synopsis]
template<
typename LhSequence,
typename RhSequence
>
struct join
{
typedef __unspecified__ type;
};
[heading Expression Semantics]
__result_of_join__<LhSequence, RhSequence>::type
[*Return type]: A model of __forward_sequence__.
[*Semantics]: Returns a sequence containing the elements of `LhSequence` followed by the elements of `RhSequence`. The order of the elements in the 2 sequences is preserved.
[*Return type]: A model of the most restrictive traversal category of sequences `Sequence1` to `SequenceN`.
[*Semantics]: Return a sequence containing tuples of elements from each sequence. For example, applying zip to tuples `(1, 2, 3)` and `('a', 'b', 'c')` would return `((1, 'a'),(2, 'b'),(3, 'c'))`