]> git.sesse.net Git - casparcg/blob - dependencies/boost/boost/phoenix/object/reinterpret_cast.hpp
Manually merged pull request #222
[casparcg] / dependencies / boost / boost / phoenix / object / reinterpret_cast.hpp
1 /*==============================================================================
2     Copyright (c) 2001-2010 Joel de Guzman
3     Copyright (c) 2010 Thomas Heller
4
5     Distributed under the Boost Software License, Version 1.0. (See accompanying
6     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 #ifndef BOOST_PHOENIX_OBJECT_REINTERPRET_CAST_HPP
9 #define BOOST_PHOENIX_OBJECT_REINTERPRET_CAST_HPP
10
11 #include <boost/phoenix/core/limits.hpp>
12 #include <boost/phoenix/core/call.hpp>
13 #include <boost/phoenix/core/expression.hpp>
14 #include <boost/phoenix/core/meta_grammar.hpp>
15 #include <boost/phoenix/object/detail/target.hpp>
16 #include <boost/proto/transform/lazy.hpp>
17
18 BOOST_PHOENIX_DEFINE_EXPRESSION(
19     (boost)(phoenix)(reinterpret_cast_)
20   , (proto::terminal<detail::target<proto::_> >)
21     (meta_grammar)
22 )
23
24 namespace boost { namespace phoenix
25 {
26     struct reinterpret_cast_eval
27     {
28         template <typename Sig>
29         struct result;
30
31         template <typename This, typename Target, typename Source, typename Context>
32         struct result<This(Target const &, Source const&, Context)>
33             : detail::result_of::target<Target>
34         {};
35
36         template <typename Target, typename Source, typename Context>
37         typename detail::result_of::target<Target>::type
38         operator()(Target, Source const& u, Context const& ctx) const
39         {
40             return
41                 reinterpret_cast<
42                     typename detail::result_of::target<Target>::type
43                 >(boost::phoenix::eval(u, ctx));
44         }
45     };
46
47     template <typename Dummy>
48     struct default_actions::when<rule::reinterpret_cast_, Dummy>
49         : call<reinterpret_cast_eval, Dummy>
50     {};
51
52     template <typename T, typename U>
53     inline
54     typename expression::reinterpret_cast_<detail::target<T>, U>::type const
55     reinterpret_cast_(U const& u)
56     {
57         return
58             expression::
59                 reinterpret_cast_<detail::target<T>, U>::
60                     make(detail::target<T>(), u);
61     }
62 }}
63
64 #endif