1 [/==============================================================================
2 Copyright (C) 2001-2011 Joel de Guzman
3 Copyright (C) 2006 Dan Marsden
4 Copyright (C) 2010 Christopher Schmidt
6 Use, modification and distribution is subject to the Boost Software
7 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 http://www.boost.org/LICENSE_1_0.txt)
9 ===============================================================================/]
12 [heading Lazy Evaluation]
14 Unlike __mpl__, Fusion algorithms are lazy[footnote Except for some
15 special cases such as __for_each__ and __copy__ which are inherently
16 imperative algorithms.] and non sequence-type preserving [footnote What
17 does that mean? It means that when you operate on a sequence through a
18 Fusion algorithm that returns a sequence, the sequence returned may not
19 be of the same class as the original]. This is by design. Runtime
20 efficiency is given a high priority. Like __mpl__, and unlike __stl__,
21 fusion algorithms are mostly functional in nature such that algorithms
22 are non mutating (no side effects). However, due to the high cost of
23 returning full sequences such as vectors and lists, /Views/ are returned
24 from Fusion algorithms instead. For example, the __transform__ algorithm
25 does not actually return a transformed version of the original sequence.
26 __transform__ returns a __transform_view__. This view holds a reference
27 to the original sequence plus the transform function. Iteration over the
28 __transform_view__ will apply the transform function over the sequence
29 elements on demand. This /lazy/ evaluation scheme allows us to chain as
30 many algorithms as we want without incurring a high runtime penalty.
32 [heading Sequence Extension]
34 The /lazy/ evaluation scheme where __algorithms__ return __views__ also
35 allows operations such as __push_back__ to be totally generic. In Fusion,
36 __push_back__ is actually a generic algorithm that works on all sequences.
37 Given an input sequence `s` and a value `x`, Fusion's __push_back__
38 algorithm simply returns a __joint_view__: a view that holds a reference to
39 the original sequence `s` and the value `x`. Functions that were once
40 sequence specific and need to be implemented N times over N different
41 sequences are now implemented only once. That is to say that Fusion
42 sequences are cheaply extensible.
44 To regain the original sequence, __conversion__ functions are provided. You
45 may use one of the __conversion__ functions to convert back to the original
50 #include <boost/fusion/algorithm.hpp>
51 #include <boost/fusion/include/algorithm.hpp>
55 The auxiliary algorithms provide the utility algorithms for sequences.
59 #include <boost/fusion/algorithm/auxiliary.hpp>
60 #include <boost/fusion/include/auxiliary.hpp>
67 Copy a sequence `src` to a sequence `dest`.
68 It is also used to convert sequence into other.
71 template <typename Seq1, typename Seq2>
72 typename __result_of_copy__<Seq1, Seq2>::type copy(Seq1 const& src, Seq2& dest);
75 [[Parameter][Requirement][Description]]
76 [[`src`][A model of __forward_sequence__, all elements contained in the `src` sequence should be convertible into the element contained in the `dest` sequence.][Operation's argument]]
77 [[`dest`][A model of __forward_sequence__, `e2 = e1` is valid expression for each pair of elements `e1` of `src` and `e2` of `dest`.][Operation's argument]]
80 [heading Expression Semantics]
83 [*Return type]: `void`
85 [*Semantics]: `e2 = e1` for each element `e1` in `src` and `e2` in `dest`.
88 Linear, exactly `__result_of_size__<Sequence>::value`.
92 #include <boost/fusion/algorithm/auxiliary/copy.hpp>
93 #include <boost/fusion/include/copy.hpp>
96 __vector__<int,int> vec(1,2);
99 assert(ls == __make_list__(1,2));
105 [heading Description]
106 move a sequence `src` to a sequence `dest`.
107 It is also used to convert sequence into other.
110 template <typename Seq1, typename Seq2>
111 typename __result_of_move__<Seq1, Seq2>::type move(Seq1&& src, Seq2& dest);
114 [[Parameter][Requirement][Description]]
115 [[`src`][A model of __forward_sequence__, all elements contained in the `src` sequence should be convertible into the element contained in the `dest` sequence.][Operation's argument]]
116 [[`dest`][A model of __forward_sequence__, `e2 = std::move(e1)` is valid expression for each pair of elements `e1` of `src` and `e2` of `dest`.][Operation's argument]]
119 [heading Expression Semantics]
122 [*Return type]: `void`
124 [*Semantics]: `e2 = std::move(e1)` for each element `e1` in `src` and `e2` in `dest`.
127 Linear, exactly `__result_of_size__<Sequence>::value`.
131 #include <boost/fusion/algorithm/auxiliary/move.hpp>
132 #include <boost/fusion/include/move.hpp>
135 __vector__<int,int> vec(1,2);
136 __list__<int,int> ls;
137 __move__(std::move(vec), ls);
138 assert(ls == __make_list__(1,2));
144 [section Metafunctions]
148 [heading Description]
149 A metafunction returning the result type of applying __copy__, which is always `void`.
152 template <typename Seq1, typename Seq2>
159 [[Parameter] [Requirement] [Description]]
160 [[`Seq1`] [A model of __forward_sequence__] [Operation's argument]]
161 [[`Seq2`] [A model of __forward_sequence__] [Operation's argument]]
164 [heading Expression Semantics]
165 result_of::copy<Seq1, Seq2>::type
167 [*Return type]: `void` iff both of `Seq1` and `Seq2` are sequence.
170 [*Semantics]: Returns the return type of __copy__ for 2 sequences of types `Seq1` and `Seq2`.
177 #include <boost/fusion/algorithm/auxiliary/copy.hpp>
178 #include <boost/fusion/include/copy.hpp>
184 [heading Description]
185 A metafunction returning the result type of applying __move__, which is always `void`.
188 template <typename Seq1, typename Seq2>
195 [[Parameter] [Requirement] [Description]]
196 [[`Seq1`] [A model of __forward_sequence__] [Operation's argument]]
197 [[`Seq2`] [A model of __forward_sequence__] [Operation's argument]]
200 [heading Expression Semantics]
201 result_of::move<Seq1, Seq2>::type
203 [*Return type]: `void` iff both of `Seq1` and `Seq2` are sequence.
206 [*Semantics]: Returns the return type of __move__ for 2 sequences of types `Seq1` and `Seq2`.
213 #include <boost/fusion/algorithm/auxiliary/move.hpp>
214 #include <boost/fusion/include/move.hpp>
225 The iteration algorithms provide the fundamental algorithms for traversing
226 a sequence repeatedly applying an operation to its elements.
230 #include <boost/fusion/algorithm/iteration.hpp>
231 #include <boost/fusion/include/iteration.hpp>
235 [template fold_desc[name result_of_name arg_desc seq_concept arg_id arg_type_id invoke_desc semantics_elements_desc example_arg_transform example_result I0 I1 IN]
236 [heading Description]
237 For a sequence `seq`, initial state `initial_state`, and binary function object
238 or function pointer `f`, [^[name]] returns the result of the repeated application of
239 binary `f` to the result of the previous `f` invocation (`inital_state` if it is
240 the first call) and [arg_desc] of `seq`.
242 [def name_macro [name]]
243 [def result_of_name_macro [result_of_name]]
250 typename result_of_name_macro<Sequence, State const, F>::type name_macro(
251 Sequence& seq, State const& initial_state, F f);
258 typename result_of_name_macro<Sequence const, State const, F>::type name_macro(
259 Sequence const& seq, State const& initial_state, F f);
266 typename result_of_name_macro<Sequence, State, F>::type name_macro(
267 Sequence& seq, State& initial_state, F f);
274 typename result_of_name_macro<Sequence const, State, F>::type name_macro(
275 Sequence const& seq, State& initial_state, F f);
277 [def seq_concept_macro [seq_concept]]
278 [def arg_type_id_macro [arg_type_id]]
279 [def arg_id_macro [arg_id]]
280 [def invoke_desc_macro [invoke_desc]]
282 [[Parameter][Requirement][Description]]
283 [[`seq`][A model of seq_concept_macro][Operation's argument]]
284 [[`initial_state`][Any type][Initial state]]
285 [[`f`][`f(s,arg_id_macro)` with return type `__boost_result_of_call__<F(S,arg_type_id_macro)>::type` for current state `s` of type `S`, and for each invoke_desc_macro][Operation's argument]]
288 [heading Expression Semantics]
289 name_macro(seq, initial_state, f);
291 [*Return type]: Any type
293 [*Semantics]: Equivalent to [^f(... f(f(initial_state,[arg_id][I0]),[arg_id][I1]) ...[arg_id][IN])] where [^[arg_id]1 ...[arg_id]N] are [semantics_elements_desc].
296 Linear, exactly `__result_of_size__<Sequence>::value` applications of `f`.
300 #include <boost/fusion/algorithm/iteration/name_macro.hpp>
301 #include <boost/fusion/include/name_macro.hpp>
303 [def example_result_macro [example_result]]
304 [def example_arg_transform_macro [example_arg_transform]]
308 typedef std::string result_type;
311 std::string operator()(const std::string& str, const T& t) const
313 return str + boost::lexical_cast<std::string>(example_arg_transform_macro);
317 const __vector__<int,int> vec(1,2);
318 assert(name_macro(vec,std::string(""), make_string()) == example_result_macro);
322 [fold_desc fold..__result_of_fold__..each element..__forward_sequence__..e..E..element `e` of type `E` in `seq`..the consecutive elements of `seq`..t.."12"..1..2..N]
325 [section reverse_fold]
326 [fold_desc reverse_fold..__result_of_reverse_fold__..each element..__bidirectional_sequence__..e..E..element `e` of type `E` in `seq`..the consecutive elements of `seq`..t.."21"..N..N-1..1]
330 [fold_desc iter_fold..__result_of_iter_fold__..iterators on each element..__forward_sequence__..it..It..iterator `it` of type `It` on an element of `seq`..consecutive iterators on the elements of `seq`..__deref__(t).."12"..1..2..N]
333 [section reverse_iter_fold]
334 [fold_desc reverse_iter_fold..__result_of_reverse_iter_fold__..iterators on each element..__bidirectional_sequence__..it..It..iterator `it` of type `It` on an element of `seq`..consecutive iterators on the elements of `seq`..__deref__(t).."21"..N..N-1..1]
338 [fold_desc accumulate..__result_of_accumulate__..each element..__forward_sequence__..e..E..element `e` of type `E` in `seq`..the consecutive elements of `seq`..t.."12"..1..2..N]
343 [heading Description]
344 Applies a unary function object to each element of a sequence.
351 typename __result_of_for_each__<Sequence, F>::type for_each(
355 [[Parameter][Requirement][Description]]
356 [[`seq`][A model of __forward_sequence__, `f(e)` must be a valid expression for each element `e` in `seq`][Operation's argument]]
357 [[`f`][A unary __reg_callable_obj__][Operation's argument]]
360 [heading Expression Semantics]
361 __for_each__(seq, f);
363 [*Return type]: `void`
365 [*Semantics]: Calls `f(e)` for each element `e` in `seq`.
368 Linear, exactly `__result_of_size__<Sequence>::value` applications of `f`.
372 #include <boost/fusion/algorithm/iteration/for_each.hpp>
373 #include <boost/fusion/include/for_each.hpp>
379 void operator()(T& t) const
385 __vector__<int,int> vec(1,2);
386 __for_each__(vec, increment());
387 assert(vec == __make_vector__(2,3));
393 [section Metafunctions]
395 [template meta_fold_desc[name name_func seq_concept arg_id arg_type_id invoke_meta_desc]
396 [heading Description]
397 Returns the result type of [name_func].
399 [def name_macro [name]]
407 typedef __unspecified__ type;
410 [def seq_concept_macro [seq_concept]]
411 [def arg_type_id_macro [arg_type_id]]
412 [def arg_id_macro [arg_id]]
413 [def invoke_meta_desc_macro [invoke_meta_desc]]
415 [[Parameter] [Requirement] [Description]]
416 [[`Sequence`] [A model of seq_concept_macro] [The sequence to iterate]]
417 [[`State`] [Any type] [The initial state for the first application of `F`]]
418 [[`F`] [`__boost_result_of_call__<F(S,arg_type_id_macro)>::type` is the return type of `f(s,arg_id_macro)` with current state `s` of type `S`, and an invoke_meta_desc_macro][The operation to be applied on traversal]]
421 [heading Expression Semantics]
422 name_macro<Sequence, State, F>::type
424 [*Return type]: Any type
426 [*Semantics]: Returns the result of applying [name_func] to a sequence of type
427 `Sequence`, with an initial state of type `State` and binary function object or
428 function pointer of type `F`.
431 Linear, exactly `__result_of_size__<Sequence>::value` applications of `F`.
435 #include <boost/fusion/algorithm/iteration/name_macro.hpp>
436 #include <boost/fusion/include/name_macro.hpp>
440 [meta_fold_desc fold..__fold__..__forward_sequence__..e..E..element `e` of type `E` in `seq`]
443 [section reverse_fold]
444 [meta_fold_desc reverse_fold..__reverse_fold__..__bidirectional_sequence__..e..E..element `e` of type `E` in `seq`]
448 [meta_fold_desc iter_fold..__iter_fold__..__forward_sequence__..it..It..iterator `it` of type `It` on an element of `seq`]
451 [section reverse_iter_fold]
452 [meta_fold_desc reverse_iter_fold..__reverse_iter_fold__..__bidirectional_sequence__..it..It..iterator `it` of type `It` on an element of `seq`]
456 [meta_fold_desc accumulate..__accumulate__..__forward_sequence__..e..E..element `e` of type `E` in `seq`]
461 [heading Description]
462 A metafunction returning the result type of applying __for_each__ to a sequence. The
463 return type of __for_each__ is always `void`.
476 [[Parameter] [Requirement] [Description]]
477 [[`Sequence`] [A model of __forward_sequence__] [Operation's argument]]
478 [[`F`] [Any type] [Operation's argument]]
481 [heading Expression Semantics]
482 __result_of_for_each__<Sequence, F>::type
484 [*Return type]: `void`.
486 [*Semantics]: Returns the return type of __for_each__ for a sequence of type `Sequence` and a unary function object `F`.
487 The return type is always `void`.
494 #include <boost/fusion/algorithm/iteration/for_each.hpp>
495 #include <boost/fusion/include/for_each.hpp>
504 The query algorithms provide support for searching and analyzing sequences.
508 #include <boost/fusion/algorithm/query.hpp>
509 #include <boost/fusion/include/query.hpp>
515 [heading Description]
516 For a sequence `seq` and unary function object `f`, `any` returns true if `f` returns true for at least one element of `seq`.
523 typename __result_of_any__<Sequence,F>::type any(
524 Sequence const& seq, F f);
527 [[Parameter][Requirement][Description]]
528 [[`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]]
529 [[`f`][A unary function object][The search predicate]]
532 [heading Expression semantics]
535 [*Return type]: `bool`
537 [*Semantics]: Returns true if and only if `f(e)` evaluates to `true` for some element `e` in `seq`.
540 Linear. At most `__result_of_size__<Sequence>::value` comparisons.
544 #include <boost/fusion/algorithm/query/any.hpp>
545 #include <boost/fusion/include/any.hpp>
551 bool operator()(T t) const
557 assert(__any__(__make_vector__(1,2), odd()));
558 assert(!__any__(__make_vector__(2,4), odd()));
564 [heading Description]
565 For a sequence `seq` and unary function object `f`, `all` returns true if `f` returns true for every element of `seq`.
572 typename __result_of_all__<Sequence,F>::type all(
573 Sequence const& seq, F f);
576 [[Parameter][Requirement][Description]]
577 [[`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]]
578 [[`f`][A unary function object][The search predicate]]
581 [heading Expression Semantics]
584 [*Return type]: `bool`
586 [*Semantics]: Returns true if and only if `f(e)` evaluates to `true` for every element `e` in `seq`.
589 Linear. At most `__result_of_size__<Sequence>::value` comparisons.
593 #include <boost/fusion/algorithm/query/all.hpp>
594 #include <boost/fusion/include/all.hpp>
600 bool operator()(T t) const
606 assert(__all__(__make_vector__(1,3), odd()));
607 assert(!__all__(__make_vector__(1,2), odd()));
613 [heading Description]
614 For a sequence `seq` and unary function object `f`, `none` returns true if `f` returns false for every element of `seq`.
621 typename __result_of_none__<Sequence,F>::type none(
622 Sequence const& seq, F f);
625 [[Parameter][Requirement][Description]]
626 [[`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]]
627 [[`f`][A unary function object][The search predicate]]
630 [heading Expression Semantics]
633 [*Return type]: `bool`
635 [*Semantics]: Returns true if and only if `f(e)` evaluates to `false` for every element `e` in `seq`. Result equivalent to `!any(seq, f)`.
638 Linear. At most `__result_of_size__<Sequence>::value` comparisons.
642 #include <boost/fusion/algorithm/query/none.hpp>
643 #include <boost/fusion/include/none.hpp>
649 bool operator()(T t) const
655 assert(__none__(__make_vector__(2,4), odd()));
656 assert(!__none__(__make_vector__(1,2), odd()));
662 [heading Description]
663 Finds the first element of a given type within a sequence.
670 typename __result_of_find__<Sequence const, T>::type find(Sequence const& seq);
676 typename __result_of_find__<Sequence, T>::type find(Sequence& seq);
679 [[Parameter][Requirement][Description]]
680 [[`seq`][A model of __forward_sequence__][The sequence to search]]
681 [[`T`][Any type][The type to search for]]
684 [heading Expression Semantics]
687 [*Return type]: A model of the same iterator category as the iterators of `seq`.
689 [*Semantics]: Returns an iterator to the first element of `seq` of type `T`, or `__end__(seq)` if there is no such element.
690 Equivalent to `__find_if__<boost::is_same<_, T> >(seq)`
693 Linear. At most `__result_of_size__<Sequence>::value` comparisons.
697 #include <boost/fusion/algorithm/query/find.hpp>
698 #include <boost/fusion/include/find.hpp>
701 const __vector__<char,int> vec('a','0');
702 assert(*__find__<int>(vec) == '0');
703 assert(__find__<double>(vec) == __end__(vec));
709 [heading Description]
710 Finds the first element within a sequence with a type for which a given __mpl_lambda_expression__ evaluates to
718 typename __result_of_find_if__<Sequence const, F>::type find_if(Sequence const& seq);
724 typename __result_of_find_if__<Sequence, F>::type find_if(Sequence& seq);
727 [[Parameter][Requirement][Description]]
728 [[`seq`][A model of __forward_sequence__][The sequence to search]]
729 [[`F`][A unary __mpl_lambda_expression__][The search predicate]]
732 [heading Expression Semantics]
735 [*Return type]: An iterator of the same iterator category as the iterators of `seq`.
737 [*Semantics]: Returns the first element of `seq` for which __mpl_lambda_expression__ `F` evaluates to `boost::mpl::true_`,
738 or `__end__(seq)` if there is no such element.
741 Linear. At most `__result_of_size__<Sequence>::value` comparisons.
745 #include <boost/fusion/algorithm/query/find_if.hpp>
746 #include <boost/fusion/include/find_if.hpp>
749 const __vector__<double,int> vec(1.0,2);
750 assert(*__find_if__<is_integral<mpl::_> >(vec) == 2);
751 assert(__find_if__<is_class<mpl::_> >(vec) == __end__(vec));
757 [heading Description]
758 Returns the number of elements of a given type within a sequence.
765 typename __result_of_count__<Sequence, T>::type count(
766 Sequence const& seq, T const& t);
769 [[Parameter][Requirement][Description]]
770 [[`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]]
771 [[`T`][Any type][The type to count]]
774 [heading Expression Semantics]
777 [*Return type]: `int`
779 [*Semantics]: Returns the number of elements of type `T` and equal to `t` in `seq`.
782 Linear. At most `__result_of_size__<Sequence>::value` comparisons.
786 #include <boost/fusion/algorithm/query/count.hpp>
787 #include <boost/fusion/include/count.hpp>
790 const __vector__<double,int,int> vec(1.0,2,3);
791 assert(__count__(vec,2) == 1);
797 [heading Description]
798 Returns the number of elements within a sequence with a type for which a given unary function object evaluates to
806 typename __result_of_count_if__<Sequence, F>::type count_if(
807 Sequence const& seq, F f);
810 [[Parameter][Requirement][Description]]
811 [[`seq`][A model of __forward_sequence__, `f(e)` is a valid expression, convertible to `bool`, for each element `e` in `seq`][The sequence to search]]
812 [[`f`][A unary function object][The search predicate]]
815 [heading Expression Semantics]
818 [*Return type]: `int`
820 [*Semantics]: Returns the number of elements in `seq` where `f` evaluates to `true`.
823 Linear. At most `__result_of_size__<Sequence>::value` comparisons.
827 #include <boost/fusion/algorithm/query/count_if.hpp>
828 #include <boost/fusion/include/count_if.hpp>
831 const __vector__<int,int,int> vec(1,2,3);
832 assert(__count_if__(vec,odd()) == 2);
838 [section Metafunctions]
842 [heading Description]
843 A metafunction returning the result type of __any__.
856 [[Parameter] [Requirement] [Description]]
857 [[`Sequence`] [A model of __forward_sequence__] [Operation's argument]]
858 [[`F`] [A model of unary __poly_func_obj__] [Operation's argument]]
861 [heading Expression Semantics]
862 __result_of_any__<Sequence, F>::type
864 [*Return type]: `bool`.
866 [*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`.
873 #include <boost/fusion/algorithm/query/any.hpp>
874 #include <boost/fusion/include/any.hpp>
880 [heading Description]
881 A metafunction returning the result type of __all__.
894 [[Parameter] [Requirement] [Description]]
895 [[`Sequence`] [A model of __forward_sequence__] [Operation's argument]]
896 [[`F`] [A model of unary __poly_func_obj__] [Operation's argument]]
899 [heading Expression Semantics]
900 __result_of_all__<Sequence, F>::type
902 [*Return type]: `bool`.
904 [*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`.
911 #include <boost/fusion/algorithm/query/all.hpp>
912 #include <boost/fusion/include/all.hpp>
918 [heading Description]
919 A metafunction returning the result type of __none__.
932 [[Parameter] [Requirement] [Description]]
933 [[`Sequence`] [A model of __forward_sequence__] [Operation's argument]]
934 [[`F`] [A model of unary __poly_func_obj__] [Operation's argument]]
937 [heading Expression Semantics]
938 __result_of_none__<Sequence, F>::type
940 [*Return type]: `bool`.
942 [*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`.
949 #include <boost/fusion/algorithm/query/none.hpp>
950 #include <boost/fusion/include/none.hpp>
956 [heading Description]
957 Returns the result type of __find__, given the sequence and search types.
966 typedef __unspecified__ type;
970 [[Parameter] [Requirement] [Description]]
971 [[`Sequence`] [Model of __forward_sequence__] [Operation's argument]]
972 [[`T`] [Any type] [Operation's argument]]
975 [heading Expression Semantics]
976 __result_of_find__<Sequence, T>::type
978 [*Return type]: A model of the same iterator category as the iterators of `Sequence`.
980 [*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.
983 Linear, at most `__result_of_size__<Sequence>::value` comparisons.
987 #include <boost/fusion/algorithm/query/find.hpp>
988 #include <boost/fusion/include/find.hpp>
994 [heading Description]
995 Returns the result type of __find_if__ given the sequence and predicate types.
1004 typedef __unspecified__ type;
1008 [[Parameter] [Requirement] [Description]]
1009 [[`Sequence`] [A model of __forward_sequence__] [Operation's argument]]
1010 [[`Pred`] [A model of __mpl_lambda_expression__] [Operation's arguments]]
1013 [heading Expression Semantics]
1014 __result_of_find_if__<Sequence, Pred>::type
1016 [*Return type]: A model of the same iterator category as the iterators of `Sequence`.
1018 [*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.
1020 [heading Complexity]
1021 Linear. At most `__result_of_size__<Sequence>::value` comparisons.
1025 #include <boost/fusion/algorithm/query/find_if.hpp>
1026 #include <boost/fusion/include/find_if.hpp>
1032 [heading Description]
1033 A metafunction that returns the result type of `count` given the sequence and search types.
1046 [[Parameter] [Requirement] [heading Description]]
1047 [[`Sequence`] [A model of __forward_sequence__] [Operation's argument]]
1048 [[`T`] [Any type] [Operation's argument]]
1051 [heading Expression Semantics]
1052 __result_of_count__<T>::type
1054 [*Return type]: `int`.
1056 [*Semantics]: Returns the return type of __count__. The return type is always `int`.
1058 [heading Complexity]
1063 #include <boost/fusion/algorithm/query/count.hpp>
1064 #include <boost/fusion/include/count.hpp>
1070 [heading Description]
1071 A metafunction that returns the result type of `count_if` given the sequence and predicate types.
1084 [[Parameter] [Requirement] [Description]]
1085 [[`Sequence`] [A model of __forward_sequence__] [Operation's argument]]
1086 [[`Pred`] [A unary function object] [Operation's argument]]
1089 [heading Expression Semantics]
1090 __result_of_count_if__<Sequence, Pred>::type
1092 [*Return type]: `int`.
1094 [*Semantics]: Returns the return type of __count_if__. The return type is always `int`.
1096 [heading Complexity]
1101 #include <boost/fusion/algorithm/query/count_if.hpp>
1102 #include <boost/fusion/include/count_if.hpp>
1110 [section Transformation]
1111 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.
1113 [note As the transformation algorithms return views onto their input arguments,
1114 it is important that the lifetime of the input arguments is greater than the
1115 period during which you wish to use the results.]
1119 #include <boost/fusion/algorithm/transformation.hpp>
1120 #include <boost/fusion/include/transformation.hpp>
1126 [heading Description]
1127 For a given sequence, filter returns a new sequences containing only the elements of a specified type.
1134 typename __result_of_filter__<Sequence const, T>::type filter(Sequence const& seq);
1137 [[Parameter][Requirement][Description]]
1138 [[`seq`][A model of __forward_sequence__][Operation's argument]]
1139 [[`T`][Any type][The type to retain]]
1142 [heading Expression Semantics]
1147 * A model of __forward_sequence__.
1148 * A model of __associative_sequence__ if `seq` implements the __associative_sequence__ model.
1150 [*Semantics]: Returns a sequence containing all the elements of `seq` of type `T`.
1151 Equivalent to `__filter_if__<boost::same_type<_, T> >(seq)`.
1153 [heading Complexity]
1154 Constant. Returns a view which is lazily evaluated.
1158 #include <boost/fusion/algorithm/transformation/filter.hpp>
1159 #include <boost/fusion/include/filter.hpp>
1162 const __vector__<int,int,long,long> vec(1,2,3,4);
1163 assert(__filter__<int>(vec) == __make_vector__(1,2));
1169 [heading Description]
1170 For a given sequence, __filter_if__ returns a new sequences containing
1171 only the elements with types for which a given __mpl_lambda_expression__ evaluates to `boost::mpl::true_`.
1178 typename __result_of_filter_if__<Sequence const, Pred>::type filter_if(Sequence const& seq);
1181 [[Parameter][Requirement][Description]]
1182 [[`seq`][A model of __forward_sequence__][Operation's argument]]
1183 [[`Pred`][A unary __mpl_lambda_expression__][The predicate to filter by]]
1186 [heading Expression Semantics]
1187 __filter_if__<Pred>(seq);
1191 * A model of __forward_sequence__.
1192 * A model of __associative_sequence__ if `seq` implements the __associative_sequence__ model.
1194 [*Semantics]: Returns a sequence containing all the elements of `seq` with types for which `Pred` evaluates
1195 to `boost::mpl::true_`. The order of the retained elements is the same as in the original sequence.
1197 [heading Complexity]
1198 Constant. Returns a view which is lazily evaluated.
1202 #include <boost/fusion/algorithm/transformation/filter_if.hpp>
1203 #include <boost/fusion/include/filter_if.hpp>
1206 const __vector__<int,int,double,double> vec(1,2,3.0,4.0);
1207 assert(__filter_if__<is_integral<mpl::_> >(vec) == __make_vector__(1,2));
1213 [heading Description]
1214 For a sequence `seq` and function object or function pointer `f`, `transform` returns a new sequence
1215 with elements created by applying `f(e)` to each element of `e` of `seq`.
1217 [heading Unary version synopsis]
1222 typename __result_of_transform__<Sequence const, F>::type transform(
1223 Sequence const& seq, F f);
1226 [[Parameter][Requirement][Description]]
1227 [[`seq`][A model of __forward_sequence__][Operation's argument]]
1228 [[`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]]
1231 [heading Expression Semantics]
1232 __transform__(seq, f);
1234 [*Return type]: A model of __forward_sequence__
1236 [*Semantics]: Returns a new sequence, containing the return values of `f(e)` for each element `e` within `seq`.
1238 [heading Binary version synopsis]
1244 typename __result_of_transform__<Sequence1 const, Sequence2 const, F>::type transform(
1245 Sequence1 const& seq1, Sequence2 const& seq2, F f);
1248 [[Parameter][Requirement][Description]]
1249 [[`seq1`][A model of __forward_sequence__][Operation's argument]]
1250 [[`seq2`][A model of __forward_sequence__][Operation's argument]]
1251 [[`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]]
1254 [*Return type]: A model of __forward_sequence__.
1256 [*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.
1258 [heading Complexity]
1259 Constant. Returns a view which is lazily evaluated.
1263 #include <boost/fusion/algorithm/transformation/transform.hpp>
1264 #include <boost/fusion/include/transform.hpp>
1269 typedef int result_type;
1271 int operator()(int t) const
1277 assert(__transform__(__make_vector__(1,2,3), triple()) == __make_vector__(3,6,9));
1283 [heading Description]
1284 Replaces each value within a sequence of a given type and value with a new value.
1291 typename __result_of_replace__<Sequence const, T>::type replace(
1292 Sequence const& seq, T const& old_value, T const& new_value);
1295 [[Parameter][Requirement][Description]]
1296 [[`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]]
1297 [[`old_value`][Any type][Value to replace]]
1298 [[`new_value`][Any type][Replacement value]]
1301 [heading Expression Semantics]
1302 __replace__(seq, old_value, new_value);
1304 [*Return type]: A model of __forward_sequence__.
1306 [*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`.
1308 [heading Complexity]
1309 Constant. Returns a view which is lazily evaluated.
1313 #include <boost/fusion/algorithm/transformation/replace.hpp>
1314 #include <boost/fusion/include/replace.hpp>
1317 assert(__replace__(__make_vector__(1,2), 2, 3) == __make_vector__(1,3));
1321 [section replace_if]
1323 [heading Description]
1324 Replaces each element of a given sequence for which an unary function object evaluates to `true` replaced with
1332 typename __result_of_replace_if__<Sequence const, F, T>::type replace_if(
1333 Sequence const& seq, F f, T const& new_value);
1336 [[Parameter][Requirement][Description]]
1337 [[`seq`][A model of __forward_sequence__][Operation's argument]]
1338 [[`f`][A function object for which `f(e)` is a valid expression, convertible to `bool`, for each element `e` in `seq`][Operation's argument]]
1339 [[`new_value`][Any type][Replacement value]]
1342 [heading Expression Semantics]
1343 __replace_if__(seq, f, new_value);
1345 [*Return type]: A model of __forward_sequence__.
1347 [*Semantics]: Returns a new sequence with all the elements of `seq`,
1348 with `new_value` assigned to each element for which `f` evaluates to `true`.
1350 [heading Complexity]
1351 Constant. Returns a view which is lazily evaluated.
1355 #include <boost/fusion/algorithm/transformation/replace_if.hpp>
1356 #include <boost/fusion/include/replace_if.hpp>
1361 template<typename T>
1362 bool operator()(T t) const
1368 assert(__replace_if__(__make_vector__(1,2), odd(), 3) == __make_vector__(3,2));
1374 [heading Description]
1375 Returns a new sequence, with all the elements of the original sequence, except those of a given type.
1382 typename __result_of_remove__<Sequence const, T>::type remove(Sequence const& seq);
1385 [[Parameter][Requirement][Description]]
1386 [[`seq`][A model of __forward_sequence__][Operation's argument]]
1387 [[`T`][Any type][Type to remove]]
1390 [heading Expression Semantics]
1395 * A model of __forward_sequence__.
1396 * A model of __associative_sequence__ if `Sequence` implements the __associative_sequence__ model.
1398 [*Semantics]: Returns a new sequence, containing all the elements of `seq`, in their original order, except
1399 those of type `T`. Equivalent to `__remove_if__<boost::is_same<_,T> >(seq)`.
1401 [heading Complexity]
1402 Constant. Returns a view which is lazily evaluated.
1406 #include <boost/fusion/algorithm/transformation/remove.hpp>
1407 #include <boost/fusion/include/remove.hpp>
1410 const __vector__<int,double> vec(1,2.0);
1411 assert(__remove__<double>(vec) == __make_vector__(1));
1417 [heading Description]
1418 Returns a new sequence, containing all the elements of the original except those where a given unary
1419 function object evaluates to `true`.
1426 typename __result_of_remove_if__<Sequence const, Pred>::type remove_if(Sequence const& seq);
1429 [[Parameter][Requirement][Description]]
1430 [[`seq`][A model of __forward_sequence__][Operation's argument]]
1431 [[`Pred`][A model of unary __mpl_lambda_expression__][Removal predicate]]
1434 [heading Expression Semantics]
1435 __remove_if__<Pred>(seq);
1439 * A model of __forward_sequence__.
1440 * A model of __associative_sequence__ if `seq` implements the __associative_sequence__ model.
1442 [*Semantics]: Returns a new sequence, containing all the elements of `seq`, in their original order, except
1443 those elements with types for which `Pred` evaluates to `boost::mpl::true_`.
1444 Equivalent to `__filter__<boost::mpl::not_<Pred> >(seq)`.
1446 [heading Complexity]
1447 Constant. Returns a view which is lazily evaluated.
1451 #include <boost/fusion/algorithm/transformation/remove_if.hpp>
1452 #include <boost/fusion/include/remove_if.hpp>
1455 const __vector__<int,double> vec(1,2.0);
1456 assert(__remove_if__<is_floating_point<mpl::_> >(vec) == __make_vector__(1));
1462 [heading Description]
1463 Returns a new sequence with the elements of the original in reverse order.
1469 typename __result_of_reverse__<Sequence const>::type reverse(Sequence const& seq);
1472 [[Parameter][Requirement][Description]]
1473 [[`seq`][A model of __bidirectional_sequence__][Operation's argument]]
1476 [heading Expression Semantics]
1481 * A model of __bidirectional_sequence__ if `seq` is a __bidirectional_sequence__
1482 else, __random_access_sequence__ if `seq` is a __random_access_sequence__.
1483 * A model of __associative_sequence__ if `seq` implements the __associative_sequence__ model.
1485 [*Semantics]: Returns a new sequence containing all the elements of `seq` in reverse order.
1487 [heading Complexity]
1488 Constant. Returns a view which is lazily evaluated.
1492 #include <boost/fusion/algorithm/transformation/reverse.hpp>
1493 #include <boost/fusion/include/reverse.hpp>
1496 assert(__reverse__(__make_vector__(1,2,3)) == __make_vector__(3,2,1));
1502 [heading Description]
1503 __clear__ returns an empty sequence.
1509 typename __result_of_clear__<Sequence const>::type clear(Sequence const& seq);
1512 [[Parameter][Requirement][Description]]
1513 [[`seq`][A model of __forward_sequence__][Operation's argument]]
1516 [heading Expression Semantics]
1519 [*Return type]: A model of __forward_sequence__.
1521 [*Expression Semantics]: Returns a sequence with no elements.
1523 [heading Complexity]
1528 #include <boost/fusion/algorithm/transformation/clear.hpp>
1529 #include <boost/fusion/include/clear.hpp>
1532 assert(__clear__(__make_vector__(1,2,3)) == __make_vector__());
1538 [heading Description]
1539 Returns a new sequence, containing all the elements of the original except those at a specified iterator, or
1540 between two iterators.
1547 typename __result_of_erase__<Sequence const, First>::type erase(
1548 Sequence const& seq, First const& it1);
1555 typename __result_of_erase__<Sequence const, First, Last>::type erase(
1556 Sequence const& seq, First const& it1, Last const& it2);
1559 [[Parameters][Requirement][Description]]
1560 [[`seq`][A model of __forward_sequence__][Operation's argument]]
1561 [[`it1`][A model of __forward_iterator__][Iterator into `seq`]]
1562 [[`it2`][A model of __forward_iterator__][Iterator into `seq` after `it1`]]
1565 [heading Expression Semantics]
1566 __erase__(seq, pos);
1570 * A model of __forward_sequence__.
1571 * A model of __associative_sequence__ if `seq` implements the __associative_sequence__ model.
1573 [*Semantics]: Returns a new sequence, containing all the elements of `seq` except the element at `pos`.
1575 __erase__(seq, first, last);
1579 * A model of __forward_sequence__.
1580 * A model of __associative_sequence__ if `seq` implements the __associative_sequence__ model.
1582 [*Semantics]: Returns a new sequence, with all the elements of `seq`, in their original order, except those
1583 in the range [`first`,`last`).
1585 [heading Complexity]
1586 Constant. Returns a view which is lazily evaluated.
1590 #include <boost/fusion/algorithm/transformation/erase.hpp>
1591 #include <boost/fusion/include/erase.hpp>
1594 const __vector__<int, double, char> vec(1, 2.0, 'c');
1595 assert(__erase__(vec, __next__(__begin__(vec))) == __make_vector__(1, 'c'));
1596 assert(__erase__(vec, __next__(__begin__(vec)), __end__(vec)) == __make_vector__(1));
1602 [heading Description]
1603 For an [link fusion.sequence.concepts.associative_sequence associative] __forward_sequence__ `seq`,
1604 returns a [link fusion.sequence.concepts.associative_sequence associative] __forward_sequence__ containing
1605 all the elements of the original except those with a given key.
1612 typename __result_of_erase_key__<Sequence const, Key>::type erase_key(Sequence const& seq);
1615 [[Parameter][Requirement][Description]]
1616 [[`seq`][A model of __forward_sequence__ and __associative_sequence__][Operation's argument]]
1617 [[`Key`][Any type][Key to erase]]
1620 [heading Expression Semantics]
1621 __erase_key__<Key>(seq);
1623 [*Return type]: A model of __forward_sequence__ and __associative_sequence__.
1625 [*Semantics]: Returns a new sequence, containing all the elements of `seq`, except those with key `Key`.
1627 [heading Complexity]
1628 Constant. Returns a view which is lazily evaluated.
1632 #include <boost/fusion/algorithm/transformation/erase_key.hpp>
1633 #include <boost/fusion/include/erase_key.hpp>
1636 assert(__erase_key__<int>(__make_map__<int, long>('a', 'b')) == __make_map__<long>('b'));
1642 [heading Description]
1643 Returns a new sequence with all the elements of the original, an a new element inserted the
1644 position described by a given iterator.
1652 typename __result_of_insert__<Sequence const, Pos, T>::type insert(
1653 Sequence const& seq, Pos const& pos, T const& t);
1656 [[Parameter][Requirement][Description]]
1657 [[`seq`][A model of __forward_sequence__][Operation's argument]]
1658 [[`pos`][A model of __forward_iterator__][The position to insert at]]
1659 [[`t`][Any type][The value to insert]]
1662 [heading Expression Semantics]
1663 __insert__(seq, pos, t);
1667 * A model of __forward_sequence__.
1669 [*Semantics]: Returns a new sequence, containing all the elements of `seq`, in their original order, and a new element with the
1670 type and value of `t` inserted at iterator `pos`.
1672 [heading Complexity]
1673 Constant. Returns a view which is lazily evaluated.
1677 #include <boost/fusion/algorithm/transformation/insert.hpp>
1678 #include <boost/fusion/include/insert.hpp>
1681 const __vector__<int,int> vec(1,2);
1682 assert(__insert__(vec, __next__(__begin__(vec)), 3) == __make_vector__(1,3,2));
1686 [section insert_range]
1688 [heading Description]
1689 Returns a new sequence with another sequence inserted at a specified iterator.
1697 typename __result_of_insert_range__<Sequence const, Pos, Range>::type insert_range(
1698 Sequence const& seq, Pos const& pos, Range const& range);
1701 [[Parameter][Requirement][Description]]
1702 [[`seq`][A model of __forward_sequence__][Operation's argument]]
1703 [[`pos`][A model of __forward_iterator__][The position to insert at]]
1704 [[`range`][A model of __forward_sequence__][Range to insert]]
1707 [heading Expression Semantics]
1708 __insert_range__(seq, pos, range);
1712 * A model of __forward_sequence__.
1713 * A model of __associative_sequence__ if `seq` implements the __associative_sequence__ model.
1715 [*Semantics]: Returns a new sequence, containing all the elements of `seq`, and the elements of
1716 `range` inserted at iterator `pos`. All elements retaining their ordering from the original sequences.
1718 [heading Complexity]
1719 Constant. Returns a view which is lazily evaluated.
1723 #include <boost/fusion/algorithm/transformation/insert_range.hpp>
1724 #include <boost/fusion/include/insert_range.hpp>
1727 const __vector__<int,int> vec(1,2);
1728 assert(__insert_range__(vec, __next__(__begin__(vec)), __make_vector__(3,4)) == __make_vector__(1,3,4,2));
1734 [heading Description]
1735 Takes 2 sequences and returns a sequence containing the elements of the first followed by the elements of the second.
1739 typename LhSequence,
1740 typename RhSequence>
1741 typename __result_of_join__<LhSequence const, RhSequence const>::type join(LhSequence const& lhs, RhSequence const& rhs);
1744 [[Parameter][Requirement][Description]]
1745 [[`lhs`][A model of __forward_sequence__][Operation's argument]]
1746 [[`rhs`][A model of __forward_sequence__][Operation's argument]]
1749 [heading Expression Semantics]
1754 * A model of __forward_sequence__.
1755 * A model of __associative_sequence__ if `lhs` and `rhs` implement the __associative_sequence__ model.
1757 [*Semantics]: Returns a sequence containing all the elements of `lhs` followed by all the elements of `rhs`. The order of the elements is preserved.
1759 [heading Complexity]
1760 Constant. Returns a view which is lazily evaluated.
1764 #include <boost/fusion/algorithm/transformation/join.hpp>
1765 #include <boost/fusion/include/join.hpp>
1768 __vector__<int,char> v1(1, 'a');
1769 __vector__<int,char> v2(2, 'b');
1770 assert(__join__(v1, v2) == __make_vector__(1,'a',2,'b'));
1776 [heading Description]
1777 Zips sequences together to form a single sequence, whose members are tuples of the members of the component sequences.
1786 typename __result_of_zip__<Sequence1 const, Sequence2 const, ... SequenceN const>::type
1787 zip(Sequence1 const& seq1, Sequence2 const& seq2, ... SequenceN const& seqN);
1790 [[Parameter][Requirement][Description]]
1791 [[`seq1` to `seqN`][Each sequence is a model of __forward_sequence__.][Operation's argument]]
1794 [heading Expression Semantics]
1795 __zip__(seq1, seq2, ... seqN);
1797 [*Return type]: A model of __forward_sequence__.
1799 [*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'))`
1801 [heading Complexity]
1802 Constant. Returns a view which is lazily evaluated.
1806 #include <boost/fusion/algorithm/transformation/zip.hpp>
1807 #include <boost/fusion/include/zip.hpp>
1810 __vector__<int,char> v1(1, 'a');
1811 __vector__<int,char> v2(2, 'b');
1812 assert(__zip__(v1, v2) == __make_vector__(__make_vector__(1, 2),__make_vector__('a', 'b'));
1818 [heading Description]
1819 Returns a new sequence, with the last element of the original removed.
1825 typename __result_of_pop_back__<Sequence const>::type pop_back(Sequence const& seq);
1828 [[Parameter][Requirement][Description]]
1829 [[`seq`][A model of __forward_sequence__][Operation's argument]]
1832 [heading Expression Semantics]
1837 * A model of __forward_sequence__.
1838 * A model of __associative_sequence__ if `seq` implements the __associative_sequence__ model.
1840 [*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`.
1842 [heading Complexity]
1843 Constant. Returns a view which is lazily evaluated.
1847 #include <boost/fusion/algorithm/transformation/pop_back.hpp>
1848 #include <boost/fusion/include/pop_back.hpp>
1851 assert(__pop_back__(__make_vector__(1,2,3)) == __make_vector__(1,2));
1857 [heading Description]
1858 Returns a new sequence, with the first element of the original removed.
1864 typename __result_of_pop_front__<Sequence const>::type pop_front(Sequence const& seq);
1868 [[Parameter][Requirement][Description]]
1869 [[`seq`][A model of __forward_sequence__][Operation's argument]]
1872 [heading Expression Semantics]
1877 * A model of __forward_sequence__.
1878 * A model of __associative_sequence__ if `seq` implements the __associative_sequence__ model.
1880 [*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`.
1882 [heading Complexity]
1883 Constant. Returns a view which is lazily evaluated.
1887 #include <boost/fusion/algorithm/transformation/pop_front.hpp>
1888 #include <boost/fusion/include/pop_front.hpp>
1891 assert(__pop_front__(__make_vector__(1,2,3)) == __make_vector__(2,3));
1897 [heading Description]
1898 Returns a new sequence with an element added at the end.
1905 typename __result_of_push_back__<Sequence const, T>::type push_back(
1906 Sequence const& seq, T const& t);
1909 [[Parameter][Requirement][Description]]
1910 [[`seq`][A model of __forward_sequence__][Operation's argument]]
1911 [[`t`][Any type][The value to add to the end]]
1914 [heading Expression Semantics]
1915 __push_back__(seq, t);
1919 * A model of __forward_sequence__.
1921 [*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`.
1923 [heading Complexity]
1924 Constant. Returns a view which is lazily evaluated.
1928 #include <boost/fusion/algorithm/transformation/push_back.hpp>
1929 #include <boost/fusion/include/push_back.hpp>
1932 assert(__push_back__(__make_vector__(1,2,3),4) == __make_vector__(1,2,3,4));
1936 [section push_front]
1938 [heading Description]
1939 Returns a new sequence with an element added at the beginning.
1946 typename __result_of_push_front__<Sequence const, T>::type push_front(
1947 Sequence const& seq, T const& t);
1950 [[Parameter][Requirement][Description]]
1951 [[`seq`][A model of __forward_sequence__][Operation's argument]]
1952 [[`t`][Any type][The value to add to the beginning]]
1955 [heading Expression Semantics]
1956 __push_back__(seq, t);
1960 * A model of __forward_sequence__.
1962 [*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`.
1964 [heading Complexity]
1965 Constant. Returns a view which is lazily evaluated.
1969 #include <boost/fusion/algorithm/transformation/push_front.hpp>
1970 #include <boost/fusion/include/push_front.hpp>
1973 assert(__push_front__(__make_vector__(1,2,3),0) == __make_vector__(0,1,2,3));
1979 [heading Description]
1980 Returns a new sequence without nested sequences.
1986 typename __result_of_flatten__<Sequence>::type flatten(Sequence& seq);
1991 typename __result_of_flatten__<Sequence const>::type flatten(Sequence const& seq);
1994 [[Parameter][Requirement][Description]]
1995 [[`seq`][A model of __forward_sequence__][Operation's argument]]
1998 [heading Expression Semantics]
2003 * A model of __forward_sequence__.
2005 [*Semantics]: Returns a new sequence containing all the leaf elements of `seq`.
2007 [heading Complexity]
2008 Constant. Returns a view which is lazily evaluated.
2012 #include <boost/fusion/algorithm/transformation/flatten.hpp>
2013 #include <boost/fusion/include/flatten.hpp>
2016 const __vector__<int, int, __vector__<int, int>, int> vec(1, 2, __make_vector__(3, 4), 5);
2017 assert(__flatten__(vec) == __make_vector__(1, 2, 3, 4, 5)));
2023 [section Metafunctions]
2027 [heading Description]
2028 Returns the result type of __filter__ given the sequence type and type to retain.
2037 typedef __unspecified__ type;
2041 [[Parameter] [Requirement] [Description]]
2042 [[`Sequence`][A model of __forward_sequence__] [Operation's argument]]
2043 [[`T`][Any type][Type to retain]]
2046 [heading Expression Semantics]
2047 __result_of_filter__<Sequence, T>::type
2051 * A model of __forward_sequence__.
2052 * A model of __associative_sequence__ if `Sequence` implements the __associative_sequence__ model.
2054 [*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`.
2056 [heading Complexity]
2061 #include <boost/fusion/algorithm/transformation/filter.hpp>
2062 #include <boost/fusion/include/filter.hpp>
2068 [heading Description]
2069 Returns the result type of __filter_if__ given the sequence and unary __mpl_lambda_expression__ predicate type.
2078 typedef __unspecified__ type;
2082 [[Parameter] [Requirement] [Description]]
2083 [[`Sequence`][A model of __forward_sequence__] [Operation's argument]]
2084 [[`Pred`][A unary __mpl_lambda_expression__][Type to retain]]
2087 [heading Expression Semantics]
2088 __result_of_filter_if__<Sequence, Pred>::type
2092 * A model of __forward_sequence__.
2093 * A model of __associative_sequence__ if `Sequence` implements the __associative_sequence__ model.
2095 [*Semantics]: Returns a sequence containing the elements of `Sequence` for which `Pred` evaluates to `boost::mpl::true_`.
2097 [heading Complexity]
2102 #include <boost/fusion/algorithm/transformation/filter_if.hpp>
2103 #include <boost/fusion/include/filter_if.hpp>
2109 [heading Description]
2110 Returns the result type of __transform__, given the types of the input sequence and unary __poly_func_obj__.
2112 [heading Unary version synopsis]
2119 typedef __unspecified__ type;
2123 [[Parameter][Requirement][Description]]
2124 [[`Sequence`][A model of __forward_sequence__][Operation's argument]]
2125 [[`F`][A model of unary __poly_func_obj__][Transformation metafunction]]
2128 [heading Expression Semantics]
2129 __result_of_transform__<Sequence, F>::type
2133 * A model of __forward_sequence__
2134 * A model of __associative_sequence__ if `Sequence` implements the __associative_sequence__ model.
2136 [*Semantics]: Returns a sequence that contains the types of `__result_of__<F(E)>::type` for each element `E` within `Sequence`.
2138 [heading Binary version synopsis]
2146 typedef __unspecified__ type;
2150 [[Parameter][Requirement][Description]]
2151 [[`Sequence1`][A model of __forward_sequence__][Operation's argument]]
2152 [[`Sequence2`][A model of __forward_sequence__][Operation's argument]]
2153 [[`F`][A model of binary __poly_func_obj__][Transformation metafunction]]
2156 [heading Expression Semantics]
2157 __result_of_transform__<Sequence1, Sequence2, F>::type
2159 [*Return type]: A model of __forward_sequence__.
2161 [*Semantics]: Returns a sequence, that contains the types of `__result_of__<F(E1, E2)>::type` for each pair of elements `E1` and `E2` within `Sequence1` and `Sequence2` respectively.
2163 [heading Complexity]
2168 #include <boost/fusion/algorithm/transformation/transform.hpp>
2169 #include <boost/fusion/include/transform.hpp>
2175 [heading Description]
2176 Returns the result type of __replace__, given the types of the input sequence and element to replace.
2185 typedef __unspecified__ type;
2189 [[Parameter][Requirement][Description]]
2190 [[`Sequence`][A model of __forward_sequence__][Operation's argument]]
2191 [[`T`][Any type][The type of the search and replacement objects]]
2194 [heading Expression Semantics]
2195 __result_of_replace__<Sequence,T>::type
2197 [*Return type]: A model of __forward_sequence__.
2199 [*Semantics]: Returns the return type of __replace__.
2201 [heading Complexity]
2206 #include <boost/fusion/algorithm/transformation/replace.hpp>
2207 #include <boost/fusion/include/replace.hpp>
2211 [section replace_if]
2213 [heading Description]
2214 Returns the result type of __replace_if__, given the types of the sequence, unary __mpl_lambda_expression__ predicate and replacement object.
2223 typedef __unspecified__ type;
2227 [[Parameter][Requirement][Description]]
2228 [[`Sequence`][A model of __forward_sequence__][Operation's argument]]
2229 [[`F`][A model of unary __mpl_lambda_expression__][Replacement predicate]]
2230 [[`T`][Any type][The type of the replacement object]]
2233 [heading Expression Semantics]
2234 __result_of_replace_if__<Sequence,F,T>::type
2236 [*Return type]: A model of __forward_sequence__.
2238 [*Semantics]: Returns the return type of __replace_if__.
2240 [heading Complexity]
2245 #include <boost/fusion/algorithm/transformation/replace_if.hpp>
2246 #include <boost/fusion/include/replace_if.hpp>
2252 [heading Description]
2253 Returns the result type of __remove__, given the sequence and removal types.
2262 typedef __unspecified__ type;
2266 [[Parameter][Requirement][Description]]
2267 [[`Sequence`][A model of __forward_sequence__][Operation's argument]]
2268 [[`T`][Any type][Remove elements of this type]]
2271 [heading Expression Semantics]
2272 __result_of_remove__<Sequence, T>::type
2276 * A model of __forward_sequence__.
2277 * A model of __associative_sequence__ if `Sequence` implements the __associative_sequence__ model.
2279 [*Semantics]: Returns a sequence containing the elements of `Sequence` not of type `T`. Equivalent to `__result_of_remove_if__<Sequence, boost::is_same<mpl::_, T> >::type`.
2281 [heading Complexity]
2286 #include <boost/fusion/algorithm/transformation/remove.hpp>
2287 #include <boost/fusion/include/remove.hpp>
2293 [heading Description]
2294 Returns the result type of __remove_if__, given the input sequence and unary __mpl_lambda_expression__ predicate types.
2303 typedef __unspecified__ type;
2307 [[Parameter][Requirement][Description]]
2308 [[`Sequence`][A model of __forward_sequence__][Operation's argument]]
2309 [[`Pred`][A model of unary __mpl_lambda_expression__][Remove elements which evaluate to `boost::mpl::true_`]]
2312 [heading Expression Semantics]
2313 __result_of_remove_if__<Sequence, Pred>::type
2317 * A model of __forward_sequence__.
2318 * A model of __associative_sequence__ if `Sequence` implements the __associative_sequence__ model.
2320 [*Semantics]: Returns a sequence containing the elements of `Sequence` for which `Pred` evaluates to `boost::mpl::false_`.
2322 [heading Complexity]
2327 #include <boost/fusion/algorithm/transformation/remove_if.hpp>
2328 #include <boost/fusion/include/remove_if.hpp>
2334 [heading Description]
2335 Returns the result type of __reverse__, given the input sequence type.
2343 typedef __unspecified__ type;
2347 [[Parameter][Requirement][Description]]
2348 [[`Sequence`][A model of __bidirectional_sequence__][Operation's argument]]
2351 [heading Expression Semantics]
2352 __result_of_reverse__<Sequence>::type
2356 * A model of __bidirectional_sequence__ if `Sequence` is a __bidirectional_sequence__
2357 else, __random_access_sequence__ if `Sequence` is a __random_access_sequence__.
2358 * A model of __associative_sequence__ if `Sequence` implements the __associative_sequence__ model.
2360 [*Semantics]: Returns a sequence with the elements in the reverse order to `Sequence`.
2362 [heading Complexity]
2367 #include <boost/fusion/algorithm/transformation/reverse.hpp>
2368 #include <boost/fusion/include/reverse.hpp>
2374 [heading Description]
2375 Returns the result type of __clear__, given the input sequence type.
2383 typedef __unspecified__ type;
2387 [[Parameter][Requirement][Description]]
2388 [[`Sequence`][Any type][Operation's argument]]
2391 [heading Expression Semantics]
2392 __result_of_clear__<Sequence>::type
2394 [*Return type]: A model of __forward_sequence__.
2396 [*Semantics]: Returns an empty sequence.
2398 [heading Complexity]
2403 #include <boost/fusion/algorithm/transformation/clear.hpp>
2404 #include <boost/fusion/include/clear.hpp>
2409 Returns the result type of __erase__, given the input sequence and range delimiting iterator types.
2411 [heading Description]
2417 typename It2 = __unspecified__>
2420 typedef __unspecified__ type;
2424 [[Parameter][Requirement][Description]]
2425 [[`Sequence`][A model of __forward_sequence__][Operation's argument]]
2426 [[`It1`][A model of __forward_iterator__][Operation's argument]]
2427 [[`It2`][A model of __forward_iterator__][Operation's argument]]
2430 [heading Expression Semantics]
2431 __result_of_erase__<Sequence, It1>::type
2435 * A model of __forward_sequence__.
2436 * A model of __associative_sequence__ if `Sequence` implements the __associative_sequence__ model.
2438 [*Semantics]: Returns a new sequence with the element at `It1` removed.
2440 __result_of_erase__<Sequence, It1, It2>::type
2442 [*Return type]: A model of __forward_sequence__.
2444 [*Semantics]: Returns a new sequence with the elements between `It1` and `It2` removed.
2446 [heading Complexity]
2451 #include <boost/fusion/algorithm/transformation/erase.hpp>
2452 #include <boost/fusion/include/erase.hpp>
2458 [heading Description]
2459 Returns the result type of __erase_key__, given the sequence and key types.
2468 typedef __unspecified__ type;
2472 [[Parameter][Requirement][Description]]
2473 [[`Sequence`][A model of __forward_sequence__ and __associative_sequence__][Operation's argument]]
2474 [[`Key`][Any type][Key type]]
2477 [heading Expression Semantics]
2478 __result_of_erase_key__<Sequence, Key>::type
2480 [*Return type]: A model of __forward_sequence__ and __associative_sequence__.
2482 [*Semantics]: Returns a sequence with the elements of `Sequence`, except those with key `Key`.
2484 [heading Complexity]
2489 #include <boost/fusion/algorithm/transformation/erase_key.hpp>
2490 #include <boost/fusion/include/erase_key.hpp>
2496 [heading Description]
2497 Returns the result type of __insert__, given the sequence, position iterator and insertion types.
2507 typedef __unspecified__ type;
2511 [[Parameter][Requirement][Description]]
2512 [[`Sequence`][A model of __forward_sequence__][Operation's argument]]
2513 [[`Position`][A model of __forward_iterator__][Operation's argument]]
2514 [[`T`][Any type][Operation's argument]]
2517 [heading Expression Semantics]
2518 __result_of_insert__<Sequence, Position, T>::type
2522 * A model of __forward_sequence__.
2524 [*Semantics]: Returns a sequence with an element of type `T` inserted at position `Position` in `Sequence`.
2526 [heading Complexity]
2531 #include <boost/fusion/algorithm/transformation/insert.hpp>
2532 #include <boost/fusion/include/insert.hpp>
2536 [section insert_range]
2538 [heading Description]
2539 Returns the result type of __insert_range__, given the input sequence, position iterator and insertion range types.
2549 typedef __unspecified__ type;
2553 [[Parameter][Requirement][Description]]
2554 [[`Sequence`][A model of __forward_sequence__][Operation's argument]]
2555 [[`Position`][A model of __forward_iterator__][Operation's argument]]
2556 [[`Range`][A model of __forward_sequence__][Operation's argument]]
2559 [heading Expression Semantics]
2560 __result_of_insert_range__<Sequence, Position, Range>::type
2564 * A model of __forward_sequence__.
2565 * A model of __associative_sequence__ if `Sequence` implements the __associative_sequence__ model.
2567 [*Semantics]: Returns a sequence with the elements of `Range` inserted at position `Position` into `Sequence`.
2569 [heading Complexity]
2574 #include <boost/fusion/algorithm/transformation/insert_range.hpp>
2575 #include <boost/fusion/include/insert_range.hpp>
2581 [heading Description]
2582 Returns the result of joining 2 sequences, given the sequence types.
2586 typename LhSequence,
2591 typedef __unspecified__ type;
2594 [heading Expression Semantics]
2595 __result_of_join__<LhSequence, RhSequence>::type
2599 * A model of __forward_sequence__.
2600 * A model of __associative_sequence__ if `LhSequence` and `RhSequence` implement the __associative_sequence__ model.
2602 [*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.
2604 [heading Complexity]
2609 #include <boost/fusion/algorithm/transformation/join.hpp>
2610 #include <boost/fusion/include/join.hpp>
2616 [heading Description]
2617 Zips sequences together to form a single sequence, whose members are tuples of the members of the component sequences.
2628 typedef __unspecified__ type;
2631 [heading Expression Semantics]
2632 __result_of_zip__<Sequence1, Sequence2, ... SequenceN>::type
2634 [*Return type]: A model of the most restrictive traversal category of sequences `Sequence1` to `SequenceN`.
2636 [*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'))`
2638 [heading Complexity]
2643 #include <boost/fusion/algorithm/transformation/zip.hpp>
2644 #include <boost/fusion/include/zip.hpp>
2650 [heading Description]
2651 Returns the result type of __pop_back__, given the input sequence type.
2659 typedef __unspecified__ type;
2663 [[Parameter][Requirement][Description]]
2664 [[`Sequence`][A model of __forward_sequence__][Operation's argument]]
2667 [heading Expression Semantics]
2668 __result_of_pop_back__<Sequence>::type
2672 * A model of __forward_sequence__.
2673 * A model of __associative_sequence__ if `Sequence` implements the __associative_sequence__ model.
2675 [*Semantics]: Returns a sequence with all the elements of `Sequence` except the last element.
2677 [heading Complexity]
2682 #include <boost/fusion/algorithm/transformation/pop_back.hpp>
2683 #include <boost/fusion/include/pop_back.hpp>
2689 [heading Description]
2690 Returns the result type of __pop_front__, given the input sequence type.
2698 typedef __unspecified__ type;
2702 [[Parameter][Requirement][Description]]
2703 [[`Sequence`][A model of __forward_sequence__][Operation's argument]]
2706 [heading Expression Semantics]
2707 __result_of_pop_front__<Sequence>::type
2711 * A model of __forward_sequence__.
2712 * A model of __associative_sequence__ if `Sequence` implements the __associative_sequence__ model.
2714 [*Semantics]: Returns a sequence with all the elements of `Sequence` except the first element.
2716 [heading Complexity]
2721 #include <boost/fusion/algorithm/transformation/pop_front.hpp>
2722 #include <boost/fusion/include/pop_front.hpp>
2728 [heading Description]
2729 Returns the result type of __push_back__, given the types of the input sequence and element to push.
2738 typedef __unspecified__ type;
2742 [[Parameter][Requirement][Description]]
2743 [[`Sequence`][A model of __forward_sequence__][Operation's argument]]
2744 [[`T`][Any type][Operation's argument]]
2747 [heading Expression Semantics]
2748 __result_of_push_back__<Sequence, T>::type
2752 * A model of __forward_sequence__.
2754 [*Semantics]: Returns a sequence with the elements of `Sequence` and an element of type `T` added to the end.
2756 [heading Complexity]
2761 #include <boost/fusion/algorithm/transformation/push_back.hpp>
2762 #include <boost/fusion/include/push_back.hpp>
2766 [section push_front]
2768 [heading Description]
2769 Returns the result type of __push_front__, given the types of the input sequence and element to push.
2778 typedef __unspecified__ type;
2782 [[Parameter][Requirement][Description]]
2783 [[`Sequence`][A model of __forward_sequence__][Operation's argument]]
2784 [[`T`][Any type][Operation's argument]]
2787 [heading Expression Semantics]
2788 __result_of_push_front__<Sequence, T>::type
2792 * A model of __forward_sequence__.
2794 [*Semantics]: Returns a sequence with the elements of `Sequence` and an element of type `T` added to the beginning.
2796 [heading Complexity]
2801 #include <boost/fusion/algorithm/transformation/push_front.hpp>
2802 #include <boost/fusion/include/push_front.hpp>
2808 [heading Description]
2809 Returns the result type of __flatten__, given the input sequence type.
2817 typedef __unspecified__ type;
2821 [[Parameter][Requirement][Description]]
2822 [[`Sequence`][A model of __forward_sequence__][Operation's argument]]
2825 [heading Expression Semantics]
2826 __result_of_flatten__<Sequence>::type
2830 * A model of __forward_sequence__.
2832 [*Semantics]: Returns a sequence with all the leaf elements of `Sequence`.
2834 [heading Complexity]
2839 #include <boost/fusion/algorithm/transformation/flatten.hpp>
2840 #include <boost/fusion/include/flatten.hpp>