📄 switch.hpp
字号:
// Boost Lambda Library -- switch.hpp -----------------------------------//// Copyright (C) 2000 Gary Powell (powellg@amazon.com)// Copyright (C) 1999, 2000 Jaakko J鋜vi (jaakko.jarvi@cs.utu.fi)//// Distributed under the Boost Software License, Version 1.0. (See// accompanying file LICENSE_1_0.txt or copy at// http://www.boost.org/LICENSE_1_0.txt)//// For more information, see www.boost.org// --------------------------------------------------------------------------#if !defined(BOOST_LAMBDA_SWITCH_HPP)#define BOOST_LAMBDA_SWITCH_HPP#include "boost/lambda/core.hpp"#include "boost/lambda/detail/control_constructs_common.hpp"#include "boost/preprocessor/enum_shifted_params.hpp"#include "boost/preprocessor/repeat_2nd.hpp"#include "boost/preprocessor/tuple.hpp"namespace boost { namespace lambda {// Switch actionstemplate <int N, class Switch1 = null_type, class Switch2 = null_type, class Switch3 = null_type, class Switch4 = null_type, class Switch5 = null_type, class Switch6 = null_type, class Switch7 = null_type, class Switch8 = null_type, class Switch9 = null_type>struct switch_action {};namespace detail { // templates to represent special lambda functors for the cases in // switch statements template <int Value> struct case_label {};struct default_label {};template<class Type> struct switch_case_tag {}; // a normal case is represented as: // tagged_lambda_functor<switch_case_tag<case_label<N> > >, LambdaFunctor> // the default case as: // tagged_lambda_functor<switch_case_tag<default_label> >, LambdaFunctor>} // end detail/// create switch_case_tag tagged_lambda_functorstemplate <int CaseValue, class Arg>inline const tagged_lambda_functor< detail::switch_case_tag<detail::case_label<CaseValue> >, lambda_functor<Arg> > case_statement(const lambda_functor<Arg>& a) { return tagged_lambda_functor< detail::switch_case_tag<detail::case_label<CaseValue> >, lambda_functor<Arg> >(a); }// No case body case.template <int CaseValue>inline const tagged_lambda_functor< detail::switch_case_tag<detail::case_label<CaseValue> >, lambda_functor< lambda_functor_base< do_nothing_action, null_type > > > case_statement() { return tagged_lambda_functor< detail::switch_case_tag<detail::case_label<CaseValue> >, lambda_functor< lambda_functor_base< do_nothing_action, null_type > > > () ;}// default labeltemplate <class Arg>inline const tagged_lambda_functor< detail::switch_case_tag<detail::default_label>, lambda_functor<Arg> > default_statement(const lambda_functor<Arg>& a) { return tagged_lambda_functor< detail::switch_case_tag<detail::default_label>, lambda_functor<Arg> >(a); }// default lable, no case body case.inline const tagged_lambda_functor< detail::switch_case_tag<detail::default_label>, lambda_functor< lambda_functor_base< do_nothing_action, null_type > > > default_statement() { return lambda_functor_base< do_nothing_action, null_type > () ;}// Specializations for lambda_functor_base of case_statement -----------------// 0 case type:// useless (just the condition part) but provided for completeness.template<class Args>class lambda_functor_base< switch_action<1>, Args> {public: Args args; template <class SigArgs> 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 { detail::select(::boost::tuples::get<1>(args), CALL_ACTUAL_ARGS); }};// 1 case type:// template<class Args, int Case1>// class // lambda_functor_base<// action<// 2, // return_void_action<switch_action<detail::case_label<Case1> > > // >, // Args// > // {// Args args;// public:// explicit lambda_functor_base(const Args& a) : args(a) {}// template<class RET, class A, class B, class C>// RET call(A& a, B& b, C& c) const {// switch( detail::select(::boost::tuples::get<0>(args), a, b, c) ) // {// case Case1: // detail::select(::boost::tuples::get<1>(args), a, b, c);// break;// }// }// };// switch with default being the sole label - doesn't make much sense but// it is there for completeness// template<class Args>// class// lambda_functor_base<// action<// 2,// return_void_action<switch_action<detail::default_label> >// >,// Args// >// {// Args args;// public:// explicit lambda_functor_base(const Args& a) : args(a) {}// // template<class RET, class A, class B, class C>// RET call(A& a, B& b, C& c) const {// switch( detail::select(::boost::tuples::get<0>(args), a, b, c) )// {// default:// detail::select(::boost::tuples::get<1>(args), a, b, c);// break;// }// }// };// // 2 case type:// The different specializations are generated with Vesa Karvonen's // preprocessor library.// This is just a comment to show what the generated classes look like// template<class Args, int Case1, int Case2>// class // lambda_functor_base<// action<3, // return_void_action< // switch_action< // detail::case_label<Case1>,// detail::case_label<Case2>// > // > // >, // Args// > // {// Args args;// public:// explicit lambda_functor_base(const Args& a) : args(a) {}// template<class RET, class A, class B, class C>// RET call(A& a, B& b, C& c) const {// switch( detail::select(::boost::tuples::get<0>(args), a, b, c) ) // {// case Case1: // detail::select(::boost::tuples::get<1>(args), a, b, c);// break;// case Case2: // detail::select(::boost::tuples::get<2>(args), a, b, c);// break;// }// }// };// template<class Args, int Case1>// class // lambda_functor_base<// action<3, // return_void_action< // switch_action<
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -