lambda_visitor.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*=============================================================================
  2. Copyright (c) 2014 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(BOOST_SPIRIT_X3_LAMBDA_VISITOR_MAY_19_2014_1116AM)
  7. #define BOOST_SPIRIT_X3_LAMBDA_VISITOR_MAY_19_2014_1116AM
  8. namespace boost { namespace spirit { namespace x3
  9. {
  10. template <typename RT, typename... Lambdas>
  11. struct lambda_visitor;
  12. template <typename RT, typename F, typename... Lambdas>
  13. struct lambda_visitor<RT, F, Lambdas...> : F, lambda_visitor<RT, Lambdas...>
  14. {
  15. typedef lambda_visitor<RT , Lambdas...> base_type;
  16. using F::operator();
  17. using base_type::operator();
  18. lambda_visitor(F f, Lambdas... lambdas)
  19. : F(f), base_type(lambdas...)
  20. {}
  21. };
  22. template <typename RT, typename F>
  23. struct lambda_visitor<RT, F> : F
  24. {
  25. typedef RT result_type;
  26. using F::operator();
  27. lambda_visitor(F f)
  28. : F(f)
  29. {}
  30. };
  31. template <typename RT>
  32. struct lambda_visitor<RT>
  33. {
  34. typedef RT result_type;
  35. };
  36. template <typename RT, typename... Lambdas>
  37. lambda_visitor<RT, Lambdas...> make_lambda_visitor(Lambdas... lambdas)
  38. {
  39. return { lambdas... };
  40. }
  41. }}}
  42. #endif