📄 control_structures_impl.hpp
字号:
typedef detail::return_type_deduction_failure<return_type_2_ifthenelsereturn> type; // types_do_not_match_in_conditional_expression };// PHASE 5: now we know that types are not arithmetic.template<class A, class B>struct non_numeric_types { typedef typename return_type_2_ifthenelsereturn< 1, // phase 1 is_convertible<A,B>::value, is_convertible<B,A>::value, is_same<A,B>::value, A, B>::type type;};// PHASE 4 : // the base case covers arithmetic types with differing promote codes// use the type deduction of arithmetic_actionstemplate<int CodeA, int CodeB, class A, class B>struct arithmetic_or_not { typedef typename return_type_2<arithmetic_action<plus_action>, A, B>::type type; // plus_action is just a random pick, has to be a concrete instance};// this case covers the case of artihmetic types with the same promote codes. // non numeric deduction is used since e.g. integral promotion is not // performed with operator ?: template<int CodeA, class A, class B>struct arithmetic_or_not<CodeA, CodeA, A, B> { typedef typename non_numeric_types<A, B>::type type; };// if either A or B has promote code -1 it is not an arithmetic typetemplate<class A, class B>struct arithmetic_or_not <-1, -1, A, B> { typedef typename non_numeric_types<A, B>::type type;};template<int CodeB, class A, class B>struct arithmetic_or_not <-1, CodeB, A, B> { typedef typename non_numeric_types<A, B>::type type;};template<int CodeA, class A, class B>struct arithmetic_or_not <CodeA, -1, A, B> { typedef typename non_numeric_types<A, B>::type type;};// PHASE 3 : Are the types same?// No, check if they are arithmetic or nottemplate <class A, class B>struct same_or_not { typedef typename detail::remove_reference_and_cv<A>::type plainA; typedef typename detail::remove_reference_and_cv<B>::type plainB; typedef typename arithmetic_or_not< detail::promote_code<plainA>::value, detail::promote_code<plainB>::value, A, B>::type type;};// Yes, clear.template <class A> struct same_or_not<A, A> { typedef A type;};} // detail// PHASE 2 : Perform first the potential array_to_pointer conversion template<class A, class B>struct return_type_2<other_action<ifthenelsereturn_action>, A, B> { typedef typename detail::array_to_pointer<A>::type A1; typedef typename detail::array_to_pointer<B>::type B1; typedef typename boost::add_const<typename detail::same_or_not<A1, B1>::type>::type type;};// PHASE 1 : Deduction is based on the second and third operand// return type specialization for conditional expression ends -----------// Control loop lambda_functor_base specializations.// Specialization for for_loop.template<class Args>class lambda_functor_base<forloop_action, Args> {public: Args args; template <class T> struct sig { typedef void type; };public: explicit lambda_functor_base(const Args& a) : args(a) {} template<class RET, CALL_TEMPLATE_ARGS> RET call(CALL_FORMAL_ARGS) const { for(detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS); detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS); detail::select(boost::tuples::get<2>(args), CALL_ACTUAL_ARGS)) detail::select(boost::tuples::get<3>(args), CALL_ACTUAL_ARGS); }};// No body casetemplate<class Args>class lambda_functor_base<forloop_no_body_action, Args> {public: Args args; template <class T> struct sig { typedef void type; };public: explicit lambda_functor_base(const Args& a) : args(a) {} template<class RET, CALL_TEMPLATE_ARGS> RET call(CALL_FORMAL_ARGS) const { for(detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS); detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS); detail::select(boost::tuples::get<2>(args), CALL_ACTUAL_ARGS)) {} }};// Specialization for while_loop.template<class Args>class lambda_functor_base<whileloop_action, Args> {public: Args args; template <class T> struct sig { typedef void type; };public: explicit lambda_functor_base(const Args& a) : args(a) {} template<class RET, CALL_TEMPLATE_ARGS> RET call(CALL_FORMAL_ARGS) const { while(detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS)) detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS); }};// No body casetemplate<class Args> class lambda_functor_base<whileloop_no_body_action, Args> {public: Args args; template <class T> struct sig { typedef void type; };public: explicit lambda_functor_base(const Args& a) : args(a) {} template<class RET, CALL_TEMPLATE_ARGS> RET call(CALL_FORMAL_ARGS) const { while(detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS)) {} }};// Specialization for do_while_loop.// Note that the first argument is the condition.template<class Args>class lambda_functor_base<dowhileloop_action, Args> {public: Args args; template <class T> struct sig { typedef void type; };public: explicit lambda_functor_base(const Args& a) : args(a) {} template<class RET, CALL_TEMPLATE_ARGS> RET call(CALL_FORMAL_ARGS) const { do { detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS); } while (detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS) ); }};// No body casetemplate<class Args>class lambda_functor_base<dowhileloop_no_body_action, Args> {public: Args args; template <class T> struct sig { typedef void type; };public: explicit lambda_functor_base(const Args& a) : args(a) {} template<class RET, CALL_TEMPLATE_ARGS> RET call(CALL_FORMAL_ARGS) const { do {} while (detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS) ); }};// Specialization for if_then.template<class Args>class lambda_functor_base<ifthen_action, Args> {public: Args args; template <class T> struct sig { typedef void type; };public: explicit lambda_functor_base(const Args& a) : args(a) {} template<class RET, CALL_TEMPLATE_ARGS> RET call(CALL_FORMAL_ARGS) const { if (detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS)) detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS); }};// Specialization for if_then_else.template<class Args>class lambda_functor_base<ifthenelse_action, Args> {public: Args args; template <class T> struct sig { typedef void type; };public: explicit lambda_functor_base(const Args& a) : args(a) {} template<class RET, CALL_TEMPLATE_ARGS> RET call(CALL_FORMAL_ARGS) const { if (detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS)) detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS); else detail::select(boost::tuples::get<2>(args), CALL_ACTUAL_ARGS); }};// Specialization of lambda_functor_base for if_then_else_return.template<class Args>class lambda_functor_base<other_action<ifthenelsereturn_action>, Args> {public: Args args; template <class SigArgs> struct sig { private: typedef typename detail::nth_return_type_sig<1, Args, SigArgs>::type ret1; typedef typename detail::nth_return_type_sig<2, Args, SigArgs>::type ret2; public: typedef typename return_type_2< other_action<ifthenelsereturn_action>, ret1, ret2 >::type type; };public: explicit lambda_functor_base(const Args& a) : args(a) {} template<class RET, CALL_TEMPLATE_ARGS> RET call(CALL_FORMAL_ARGS) const { return (detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS)) ? detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS) : detail::select(boost::tuples::get<2>(args), CALL_ACTUAL_ARGS); }};} // lambda} // boost#endif // BOOST_LAMBDA_CONTROL_CONSTRUCTS_HPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -