PageRenderTime 21ms CodeModel.GetById 2ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/src/contrib/boost/spirit/home/phoenix/core/reference.hpp

http://pythonocc.googlecode.com/
C++ Header | 80 lines | 58 code | 14 blank | 8 comment | 1 complexity | 9e2acaea4710fe52b9e85d1ff5e386fb MD5 | raw file
 1/*=============================================================================
 2    Copyright (c) 2001-2007 Joel de Guzman
 3
 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 PHOENIX_CORE_REFERENCE_HPP
 8#define PHOENIX_CORE_REFERENCE_HPP
 9
10#include <boost/spirit/home/phoenix/core/actor.hpp>
11#include <boost/static_assert.hpp>
12#include <boost/type_traits/is_reference.hpp>
13#include <boost/mpl/bool.hpp>
14
15namespace boost { namespace phoenix
16{
17    template <typename T>
18    struct reference
19    {
20        // $$$ TODO: a better (user friendly) static assert
21        BOOST_STATIC_ASSERT(
22            mpl::not_<is_reference<T> >::value != 0);
23
24        typedef mpl::false_ no_nullary;
25
26        template <typename Env>
27        struct result
28        {
29            typedef T& type;
30        };
31
32        reference(T& arg)
33            : ref(arg) {}
34
35        template <typename Env>
36        T& eval(Env const&) const
37        {
38            return ref;
39        }
40
41        T& ref;
42
43    private:
44        // silence MSVC warning C4512: assignment operator could not be generated
45        reference& operator= (reference const&);
46    };
47
48    template <typename T>
49    inline actor<reference<T> > const
50    ref(T& v)
51    {
52        return reference<T>(v);
53    }
54
55    template <typename T>
56    inline actor<reference<T const> > const
57    cref(T const& v)
58    {
59        return reference<T const>(v);
60    }
61
62    namespace detail
63    {
64        struct error_attempting_to_convert_an_actor_to_a_reference {};
65    }
66
67    template <typename Base>
68    void
69    ref(actor<Base> const& v
70        , detail::error_attempting_to_convert_an_actor_to_a_reference
71            = detail::error_attempting_to_convert_an_actor_to_a_reference());
72
73    template <typename Base>
74    void
75    cref(actor<Base> const& v
76        , detail::error_attempting_to_convert_an_actor_to_a_reference
77            = detail::error_attempting_to_convert_an_actor_to_a_reference());
78}}
79
80#endif