~ubuntu-branches/debian/sid/boost1.49/sid

« back to all changes in this revision

Viewing changes to boost/phoenix/object/dynamic_cast.hpp

  • Committer: Package Import Robot
  • Author(s): Steve M. Robbins
  • Date: 2012-02-26 00:31:44 UTC
  • Revision ID: package-import@ubuntu.com-20120226003144-eaytp12cbf6ubpms
Tags: upstream-1.49.0
ImportĀ upstreamĀ versionĀ 1.49.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_DYNAMIC_CAST_HPP
 
9
#define BOOST_PHOENIX_OBJECT_DYNAMIC_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)(dynamic_cast_)
 
20
  , (proto::terminal<detail::target<proto::_> >)
 
21
    (meta_grammar)
 
22
)
 
23
    
 
24
namespace boost { namespace phoenix
 
25
{
 
26
    struct dynamic_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, Source, 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
                dynamic_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::dynamic_cast_, Dummy>
 
49
        : call<dynamic_cast_eval, Dummy>
 
50
    {};
 
51
 
 
52
    template <typename T, typename U>
 
53
    inline
 
54
    typename expression::dynamic_cast_<detail::target<T>, U>::type const
 
55
    dynamic_cast_(U const& u)
 
56
    {
 
57
        return
 
58
            expression::
 
59
                dynamic_cast_<detail::target<T>, U>::
 
60
                    make(detail::target<T>(), u);
 
61
    }
 
62
}}
 
63
 
 
64
#endif