functional.qbk
来自「Boost provides free peer-reviewed portab」· QBK 代码 · 共 1,703 行 · 第 1/4 页
QBK
1,703 行
return lhs - rhs; } }; void try_it() { sub f; assert(f(2,1) == invoke_function_object(f,__make_vector__(2,1))); }[heading See also]* __invoke__* __invoke_procedure__* __result_of_invoke_function_object__* __fused_function_object__[endsect][endsect] [/ Functions][section Metafunctions][section invoke][heading Description]Returns the result type of __invoke__.[heading Synopsis] namespace result_of { template< typename Function, class Sequence > struct invoke { typedef __unspecified__ type; }; }[heading See also]* __invoke__* __fused__[endsect][section:invoke_proc invoke_procedure][heading Description]Returns the result type of __invoke_procedure__.[heading Synopsis] namespace result_of { template< typename Function, class Sequence > struct invoke_procedure { typedef __unspecified__ type; }; }[heading See also]* __invoke_procedure__* __fused_procedure__[endsect][section:invoke_fobj invoke_function_object][heading Description]Returns the result type of __invoke_function_object__.[heading Synopsis] namespace result_of { template< class Function, class Sequence > struct invoke_function_object { typedef __unspecified__ type; }; }[heading See also]* __invoke_function_object__* __fused_function_object__[endsect][endsect] [/ Metafunctions ][endsect] [/ Invocation ][/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ][section:adapters Adapters]Function object templates to transform a particular target function.[section fused][heading Description]An unary __poly_func_obj__ adapter template for __def_callable_obj__ targetfunctions. It takes a __forward_sequence__ that contains the arguments for thetarget function.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 for atarget function object that is const or, if the target function objectis held by value, the adapter is const - these semantics have nothing todo with the const qualification of a member function, which is referringto the type of object pointed to by [^this] which is specified with thefirst element in the sequence passed to the adapter).If the target function is a pointer to a class members, the correspondingobject can be specified as a reference, pointer, or smart pointer.In case of the latter, a freestanding [^get_pointer] function must bedefined (Boost provides this function for [^std::auto_ptr] and__boost_shared_ptr_call__)./functional/adapter/fused.hpp>[heading Synopsis] template <typename Function> class fused;[heading Template parameters][table [[Parameter] [Description] [Default]] [[`Function`] [A __def_callable_obj__] []]][heading Model of]* __poly_func_obj__* __def_callable_obj__[variablelist Notation [[`R`] [A possibly const qualified __def_callable_obj__ type or reference type thereof]] [[`r`] [An object convertible to `R`]] [[`s`] [A __sequence__ of arguments that are accepted by `r`]] [[`f`] [An instance of `fused<R>`]]][heading Expression Semantics][table [[Expression] [Semantics]] [[`fused<R>(r)`] [Creates a fused function as described above, initializes the target function with `r`.]] [[`fused<R>()`] [Creates a fused function as described above, attempts to use `R`'s default constructor.]] [[`f(s)`] [Calls `r` with the elements in `s` as its arguments.]]][heading Example] fused< __std_plus_doc__<long> > f; assert(f(__make_vector__(1,2l)) == 3l);[heading See also]* __fused_procedure__* __fused_function_object__* __invoke__* __deduce__[endsect][section fused_procedure][heading Description]An unary __poly_func_obj__ adapter template for __callable_obj__ targetfunctions. It takes a __forward_sequence__ that contains the arguments forthe target function.The result is discared and the adapter's return type is `void`.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 for atarget function object that is const or, if the target function objectis held by value, the adapter is const - these semantics have nothing todo with the const qualification of a member function, which is referringto the type of object pointed to by [^this] which is specified with thefirst element in the sequence passed to the adapter).If the target function is a pointer to a members function, the correspondingobject can be specified as a reference, pointer, or smart pointer.In case of the latter, a freestanding [^get_pointer] function must bedefined (Boost provides this function for [^std::auto_ptr] and__boost_shared_ptr_call__).The target function must not be a pointer to a member object (dereferencingsuch a pointer without returning anything does not make sense, so this caseis not implemented)./functional/adapter/fused_procedure.hpp>[heading Synopsis] template <typename Function> class fused_procedure;[heading Template parameters][table [[Parameter] [Description] [Default]] [[`Function`] [__callable_obj__ type] []]][heading Model of]* __poly_func_obj__* __def_callable_obj__[variablelist Notation [[`R`] [A possibly const qualified __callable_obj__ type or reference type thereof]] [[`r`] [An object convertible to `R`]] [[`s`] [A __sequence__ of arguments that are accepted by `r`]] [[`f`] [An instance of `fused<R>`]]][heading Expression Semantics][table [[Expression] [Semantics]] [[`fused_procedure<R>(r)`] [Creates a fused function as described above, initializes the target function with `r`.]] [[`fused_procedure<R>()`] [Creates a fused function as described above, attempts to use `R`'s default constructor.]] [[`f(s)`] [Calls `r` with the elements in `s` as its arguments.]]][heading Example] template<class SequenceOfSequences, class Func> void n_ary_for_each(SequenceOfSequences const & s, Func const & f) { __for_each__(__zip_view__<SequenceOfSequences>(s), fused_procedure<Func const &>(f)); } void try_it() { __vector__<int,float> a(2,2.0f); __vector__<int,float> b(1,1.5f); using namespace boost::lambda; n_ary_for_each(__vector_tie__(a,b), _1 -= _2); assert(a == __make_vector__(1,0.5f)); }[heading See also]* __fused__* __fused_function_object__* __invoke_procedure__[endsect][section fused_function_object][heading Description]An unary __poly_func_obj__ adapter template for a __poly_func_obj__ targetfunction. It takes a __forward_sequence__ that contains the arguments for thetarget function.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 for antarget function object that is const or, if the target function objectis held by value, the adapter is const)./functional/adapter/fused_function_object.hpp>[heading Synopsis] template <class Function> class fused_function_object;[heading Template parameters][table [[Parameter] [Description] [Default]] [[`Function`] [__poly_func_obj__ type] []]][heading Model of]* __poly_func_obj__* __def_callable_obj__[variablelist Notation [[`R`] [A possibly const qualified __poly_func_obj__ type or reference type thereof]] [[`r`] [An object convertible to `R`]] [[`s`] [A __sequence__ of arguments that are accepted by `r`]] [[`f`] [An instance of `fused<R>`]]][heading Expression Semantics][table [[Expression] [Semantics]] [[`fused_function_object<R>(r)`] [Creates a fused function as described above, initializes the target function with `r`.]] [[`fused_function_object<R>()`] [Creates a fused function as described above, attempts to use `R`'s default constructor.]] [[`f(s)`] [Calls `r` with the elements in `s` as its arguments.]]][heading Example] template<class SeqOfSeqs, class Func> typename __result_of_transform__< zip_view<SeqOfSeqs> const, fused_function_object<Func const &> >::type n_ary_transform(SeqOfSeqs const & s, Func const & f) { return __transform__(zip_view<SeqOfSeqs>(s), fused_function_object<Func const &>(f)); } struct sub { template <typename Sig> struct result; template <class Self, typename T> struct result< Self(T,T) > { typedef typename remove_reference<T>::type type; }; template<typename T> T operator()(T lhs, T rhs) const { return lhs - rhs; } }; void try_it() { __vector__<int,float> a(2,2.0f); __vector__<int,float> b(1,1.5f); __vector__<int,float> c(1,0.5f); assert(c == n_ary_transform(__vector_tie__(a,b), sub())); }[heading See also]* __fused__* __fused_procedure__* __invoke_function_object__* __deduce__[endsect][section unfused_generic][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 function.Non-const __lvalue__ arguments are transported as references to non-const, otherwisereferences to const are used.[blurb __tip__ Detecting mutable LValues on a per-argument basis is currently acompile time expensive operation (see __the_forwarding_problem__ fordetails). Therefore, there are two, lightweight and more restricted variantsof this class template, __unfused_lvalue_args__ and __unfused_rvalue_args__.]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_generic.hpp>[heading Synopsis] template <class Function> class unfused_generic;[heading Template parameters][table [[Parameter] [Description] [Default]] [[`Function`] [An 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`]] [[`UG`] [The type `unfused_generic<F>`]] [[`ug`] [An instance of `UG`, initialized with `f`]] [[`a0`...`aN`] [Arguments to `ug`]]][heading Expression Semantics][table [[Expression] [Semantics]] [[`UG(f)`] [Creates a fused function as described above, initializes the target function with `f`.]] [[`UG()`] [Creates a fused function as described above, attempts to use `F`'s default constructor.]] [[`ug(a0`...`aN)`] [Calls `f` with a __sequence__ that contains references to the arguments `a0`...`aN`.]]][heading Example] template <typename Function, typename T> class fused_bound_1st { typename traits::deduce<Function>::type fnc_deferred; typename traits::deduce<T>::type xxx_bound; public: fused_bound_1st(Function deferred, T bound) : fnc_deferred(deferred), xxx_bound(bound) { } template <typename Sig> struct result; template <class Self, class Seq>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?