make_pair.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_LAMBDA_MAKE_PAIR_HPP
  11. #define BOOST_COMPUTE_LAMBDA_MAKE_PAIR_HPP
  12. #include <boost/compute/types/pair.hpp>
  13. namespace boost {
  14. namespace compute {
  15. namespace lambda {
  16. namespace detail {
  17. // function wrapper for make_pair() in lambda expressions
  18. struct make_pair_func
  19. {
  20. template<class Expr, class Args>
  21. struct lambda_result
  22. {
  23. typedef typename proto::result_of::child_c<Expr, 1>::type Arg1;
  24. typedef typename proto::result_of::child_c<Expr, 2>::type Arg2;
  25. typedef typename lambda::result_of<Arg1, Args>::type T1;
  26. typedef typename lambda::result_of<Arg2, Args>::type T2;
  27. typedef std::pair<T1, T2> type;
  28. };
  29. template<class Context, class Arg1, class Arg2>
  30. static void apply(Context &ctx, const Arg1 &arg1, const Arg2 &arg2)
  31. {
  32. typedef typename lambda::result_of<Arg1, typename Context::args_tuple>::type T1;
  33. typedef typename lambda::result_of<Arg2, typename Context::args_tuple>::type T2;
  34. ctx.stream << "boost_make_pair(";
  35. ctx.stream << type_name<T1>() << ", ";
  36. proto::eval(arg1, ctx);
  37. ctx.stream << ", ";
  38. ctx.stream << type_name<T2>() << ", ";
  39. proto::eval(arg2, ctx);
  40. ctx.stream << ")";
  41. }
  42. };
  43. } // end detail namespace
  44. // make_pair(first, second)
  45. template<class Arg1, class Arg2>
  46. inline typename proto::result_of::make_expr<
  47. proto::tag::function, detail::make_pair_func, const Arg1&, const Arg2&
  48. >::type const
  49. make_pair(const Arg1 &first, const Arg2 &second)
  50. {
  51. return proto::make_expr<proto::tag::function>(
  52. detail::make_pair_func(), ::boost::ref(first), ::boost::ref(second)
  53. );
  54. }
  55. } // end lambda namespace
  56. } // end compute namespace
  57. } // end boost namespace
  58. #endif // BOOST_COMPUTE_LAMBDA_MAKE_PAIR_HPP