📄 functional.qbk
字号:
struct result< Self(Seq) > : result_of::invoke< Function, typename result_of::push_front< typename remove_reference<Seq>::type, T>::type > { }; template <class Seq> typename result< void(Seq) >::type operator()(Seq const & s) const { return invoke(fnc_deferred, push_front(s,xxx_bound)); } }; template <typename Function, typename T> unfused_generic< fused_bound_1st<Function,T> > bind_1st(Function f, T const & x) { return unfused_generic< fused_bound_1st<Function,T> >( fused_bound_1st<Function,T>(f,x) ); } int test_func(int a, int b, int c) { return a+b+c; } void try_it() { assert(bind_1st(& test_func,3)(-2,-1) == 0); assert(bind_1st(std::plus<float>(), 1)(0.5f) == 1.5f); }[heading See also]* __unfused_lvalue_args__* __unfused_rvalue_args__* __unfused_typed__* __deduce__* __deduce_sequence__[endsect][section unfused_lvalue_args][heading Description]An n-ary __poly_func_obj__ adapter template for an unary __poly_func_obj__target function. When called, its arguments are bundled to a__random_access_sequence__ of references that is passed to the target functionobject. Only __lvalue__ arguments are accepted.The type of the target function is allowed to be const qualified or areference. Const qualification is preserved and propagated appropriately(in other words, only const versions of [^operator()] can be used ifthe target function object is const - or, in case the target functionobject is held by value, the adapter is const)./functional/adapter/unfused_lvalue_args.hpp>[heading Synopsis] template <class Function> class unfused_lvalue_args;[heading Template parameters][table [[Parameter] [Description] [Default]] [[`Function`] [A unary __poly_func_obj__] []]][heading Model of]* __poly_func_obj__* __def_callable_obj__[variablelist Notation [[`F`] [A possibly const qualified, unary __poly_func_obj__ type or reference type thereof]] [[`f`] [An object convertible to `F`]] [[`UL`] [The type `unfused_lvalue_args<F>`]] [[`ul`] [An instance of `UL`, initialized with `f`]] [[`a0`...`aN`] [Arguments to `ul`]]][heading Expression Semantics][table [[Expression] [Semantics]] [[`UL(f)`] [Creates a fused function as described above, initializes the target function with `f`.]] [[`UL()`] [Creates a fused function as described above, attempts to use `F`'s default constructor.]] [[`ul(a0`...`aN)`] [Calls `f` with a __sequence__ that contains references to the arguments `a0`...`aN`.]]][heading Example] struct fused_incrementer { template <class Seq> struct result { typedef void type; }; template <class Seq> void operator()(Seq const & s) const { __for_each__(s,++boost::lambda::_1); } }; void try_it() { unfused_lvalue_args<fused_incrementer> increment; int a = 2; char b = 'X'; increment(a,b); assert(a == 3 && b == 'Y'); }[heading See also]* __unfused_rvalue_args__* __unfused_generic__* __unfused_typed__[endsect][section unfused_rvalue_args][heading Description]An n-ary __poly_func_obj__ adapter template for an unary __poly_func_obj__target function. When called, its arguments are bundled to a__random_access_sequence__ of references that is passed to the targetfunction object. All referenced objects in the sequence are const qualified.The type of the target function is allowed to be const qualified or areference. Const qualification is preserved and propagated appropriately(in other words, only const versions of [^operator()] can be used ifthe target function object is const - or, in case the target function objectis held by value, the adapter is const)./functional/adapter/unfused_rvalue_args.hpp>[heading Synopsis] template <class Function> class unfused_rvalue_args;[heading Template parameters][table [[Parameter] [Description] [Default]] [[`Function`] [A unary __poly_func_obj__] []]][heading Model of]* __poly_func_obj__* __def_callable_obj__[variablelist Notation [[`F`] [A possibly const qualified, unary __poly_func_obj__ type or reference type thereof]] [[`f`] [An object convertible to `F`]] [[`UR`] [The type `unfused_rvalue_args<F>`]] [[`ur`] [An instance of `UR`, initialized with `f`]] [[`a0`...`aN`] [Arguments to `ur`]]][heading Expression Semantics][table [[Expression] [Semantics]] [[`UR(f)`] [Creates a fused function as described above, initializes the target function with `f`.]] [[`UR()`] [Creates a fused function as described above, attempts to use `F`'s default constructor.]] [[`ur(a0`...`aN)`] [Calls `f` with a __sequence__ that contains references to the arguments `a0`...`aN`.]]][heading Example] struct sequence_printer { template <class Seq> struct result { typedef void type; }; template <class Seq> void operator()(Seq const & s) const { std::cout << s << std::endl; } }; void try_it() { unfused_rvalue_args<sequence_printer> print; print(24,"bottles of beer in",'a',"box."); }[heading See also]* __unfused_lvalue_args__* __unfused_generic__* __unfused_typed__* __deduce__* __deduce_sequence__[endsect][section unfused_typed][heading Description]An n-ary __poly_func_obj__ adapter template for an unary __poly_func_obj__target function. When called, its arguments are bundled to a__random_access_sequence__ that is passed to the target function object.The call operators of esulting function objects are strictly typed(in other words, non-templatized) with the types from a __sequence__.The type of the target function is allowed to be const qualified or areference. Const qualification is preserved and propagated appropriately(in other words, only const versions of [^operator()] can be used ifthe target function object is const - or, in case the target function objectis held by value, the adapter is const).[blurb __note__ For Microsoft Visual C++ 7.1 (Visual Studio 2003) the detectionof the Function Object's const qualification easily causes an internal error.Therefore the adapter is always treated as if it was const. ][blurb __tip__ If the type sequence passed to this template containsnon-reference elements, the element is copied only once - the call operator'ssignature is optimized automatically to avoid by-value parameters.]/functional/adapter/unfused_typed.hpp>[heading Synopsis] template <class Function, class Sequence> class unfused_typed;[heading Template parameters][table [[Parameter] [Description] [Default]] [[`Function`] [A unary __poly_func_obj__] []] [[`Sequence`] [A __sequence__] []]][heading Model of]* __poly_func_obj__* __def_callable_obj__[variablelist Notation [[`F`] [A possibly const qualified, unary __poly_func_obj__ type or reference type thereof]] [[`f`] [An object convertible to `F`]] [[`S`] [A __sequence__ of parameter types]] [[`UT`] [The type `unfused_typed<F,S>`]] [[`ut`] [An instance of `UT`, initialized with `f`]] [[`a0`...`aN`] [Arguments to `ut`, convertible to the types in `S`]]][heading Expression Semantics][table [[Expression] [Semantics]] [[`UT(f)`] [Creates a fused function as described above, initializes the target function with `f`.]] [[`UT()`] [Creates a fused function as described above, attempts to use `F`'s default constructor.]] [[`ut(a0`...`aN)`] [Calls `f` with an instance of `S` (or a subsequence of `S` starting at the first element, if fewer arguments are given and the overload hasn't been disabled) initialized with `a0`...`aN`.]]][heading Example] struct add_assign // applies operator+= { typedef void result_type; // for simplicity template <typename T> void operator()(T & lhs, T const & rhs) const { lhs += rhs; } }; template <class Tie> class fused_parallel_adder { Tie tie_dest; public: explicit fused_parallel_adder(Tie const & dest) : tie_dest(dest) { } typedef void result_type; template <class Seq> void operator()(Seq const & s) const { for_each( zip(tie_dest,s), fused<add_assign>() ); } }; // accepts a tie and creates a typed function object from it struct fused_parallel_adder_maker { template <typename Sig> struct result; template <class Self, class Seq> struct result< Self(Seq) > { typedef typename remove_reference<Seq>::type seq; typedef unfused_typed< fused_parallel_adder<seq>, typename mpl::transform<seq, remove_reference<_> >::type > type; }; template <class Seq> typename result< void(Seq) >::type operator()(Seq const & tie) { return typename result< void(Seq) >::type( fused_parallel_adder<Seq>(tie) ); } }; unfused_lvalue_args<fused_parallel_adder_maker> parallel_add; void try_it() { int a = 2; char b = 'X'; // the second call is strictly typed with the types deduced from the // first call parallel_add(a,b)(3,2); parallel_add(a,b)(3); parallel_add(a,b)(); assert(a == 8 && b == 'Z'); }[heading See also]* __unfused_generic__* __unfused_lvalue_args__* __unfused_rvalue_args__* __deduce__* __deduce_sequence__[endsect][endsect] [/ Adapters][/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ][section Generation][section Functions][section:mk_fused make_fused][heading Description]Creates a __fused__ adapter for a given __def_callable_obj__. The usual__element_conversion__ is applied to the target function.[heading Synopsis] template <typename F> inline typename __result_of_make_fused__<F>::type make_fused(F const & f);[heading Parameters][table [[Parameter] [Requirement] [Description]] [[`f`] [Model of __def_callable_obj__] [The function to transform.]]][heading Expression Semantics] make_fused(f);[*Return type]: A specialization of __fused__.[*Semantics]: Returns a __fused__ adapter for `f`.[heading Header] #include <boost/fusion/functional/generation/make_fused.hpp> #include <boost/fusion/include/make_fused.hpp>[heading Example] float sub(float a, float b) { return a - b; } void try_it() { __vector__<int,float> a(2,2.0f); __vector__<int,float> b(1,1.5f); __vector__<float,float> c(1.0f,0.5f); assert(c == __transform__(__zip__(a,b), make_fused(& sub))); assert(c == __transform__(__zip__(a,b), make_fused(__std_minus_doc__<float>()))); }[heading See also]* __fused__* __deduce__* __result_of_make_fused__[endsect][section:mk_fused_proc make_fused_procedure][heading Description]Creates a __fused_procedure__ adapter for a given __def_callable_obj__.The usual __element_conversion__ applied to the target function.[heading Synopsis] template <typename F> inline typename __result_of_make_fused_procedure__<F>::type make_fused_procedure(F const & f);[heading Parameters][table [[Parameter] [Requirement] [Description]] [[`f`] [Model of __callable_obj__] [The function to transform.]]][heading Expression Semantics] make_fused_procedure(f);[*Return type]: A specialization of __fused_procedure__.[*Semantics]: Returns a __fused_procedure__ adapter for `f`.[heading Header] #include <boost/fusion/functional/generation/make_fused_procedure.hpp>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -