new.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*==============================================================================
  2. Copyright (c) 2001-2010 Joel de Guzman
  3. Copyright (c) 2010 Thomas Heller
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #ifndef BOOST_PHOENIX_OBJECT_NEW_HPP
  8. #define BOOST_PHOENIX_OBJECT_NEW_HPP
  9. #include <boost/phoenix/core/limits.hpp>
  10. #include <boost/phoenix/core/expression.hpp>
  11. #include <boost/phoenix/core/meta_grammar.hpp>
  12. #include <boost/phoenix/core/call.hpp>
  13. #include <boost/phoenix/object/detail/target.hpp>
  14. #include <boost/phoenix/support/iterate.hpp>
  15. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  16. BOOST_PHOENIX_DEFINE_EXPRESSION_VARARG(
  17. (boost)(phoenix)(new_)
  18. , (proto::terminal<detail::target<proto::_> >)
  19. (meta_grammar)
  20. , BOOST_PHOENIX_COMPOSITE_LIMIT
  21. )
  22. namespace boost { namespace phoenix
  23. {
  24. struct new_eval
  25. {
  26. template <typename Sig>
  27. struct result;
  28. template <typename This, typename A0, typename Context>
  29. struct result<This(A0, Context)>
  30. {
  31. typedef typename detail::result_of::target<A0> target_type;
  32. typedef typename target_type::type * type;
  33. };
  34. template <typename Target, typename Context>
  35. typename detail::result_of::target<Target>::type *
  36. operator()(Target, Context const &) const
  37. {
  38. return new typename detail::result_of::target<Target>::type;
  39. }
  40. // Bring in the rest
  41. #include <boost/phoenix/object/detail/new_eval.hpp>
  42. };
  43. template <typename Dummy>
  44. struct default_actions::when<rule::new_, Dummy>
  45. : call<new_eval, Dummy>
  46. {};
  47. template <typename T>
  48. inline
  49. typename expression::new_<detail::target<T> >::type const
  50. new_()
  51. {
  52. return
  53. expression::
  54. new_<detail::target<T> >::
  55. make(detail::target<T>());
  56. }
  57. // Bring in the rest
  58. #include <boost/phoenix/object/detail/new.hpp>
  59. }}
  60. #endif