]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | /// \file expr.hpp | |
3 | /// Contains definition of expr\<\> class template. | |
4 | // | |
5 | // Copyright 2008 Eric Niebler. Distributed under the Boost | |
6 | // Software License, Version 1.0. (See accompanying file | |
7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
8 | ||
9 | #ifndef BOOST_PROTO_EXPR_HPP_EAN_04_01_2005 | |
10 | #define BOOST_PROTO_EXPR_HPP_EAN_04_01_2005 | |
11 | ||
12 | #include <boost/preprocessor/cat.hpp> | |
13 | #include <boost/preprocessor/arithmetic/dec.hpp> | |
14 | #include <boost/preprocessor/selection/max.hpp> | |
15 | #include <boost/preprocessor/iteration/iterate.hpp> | |
16 | #include <boost/preprocessor/facilities/intercept.hpp> | |
17 | #include <boost/preprocessor/repetition/repeat.hpp> | |
18 | #include <boost/preprocessor/repetition/repeat_from_to.hpp> | |
19 | #include <boost/preprocessor/repetition/enum_trailing.hpp> | |
20 | #include <boost/preprocessor/repetition/enum_params.hpp> | |
21 | #include <boost/preprocessor/repetition/enum_binary_params.hpp> | |
22 | #include <boost/preprocessor/repetition/enum_trailing_params.hpp> | |
23 | #include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp> | |
24 | #include <boost/utility/addressof.hpp> | |
25 | #include <boost/proto/proto_fwd.hpp> | |
26 | #include <boost/proto/args.hpp> | |
27 | #include <boost/proto/traits.hpp> | |
28 | ||
29 | #if defined(_MSC_VER) | |
30 | # pragma warning(push) | |
31 | # pragma warning(disable : 4510) // default constructor could not be generated | |
32 | # pragma warning(disable : 4512) // assignment operator could not be generated | |
33 | # pragma warning(disable : 4610) // user defined constructor required | |
34 | # pragma warning(disable : 4714) // function 'xxx' marked as __forceinline not inlined | |
35 | #endif | |
36 | ||
37 | namespace boost { namespace proto | |
38 | { | |
39 | ||
40 | namespace detail | |
41 | { | |
42 | struct not_a_valid_type | |
43 | { | |
44 | private: | |
45 | not_a_valid_type() | |
46 | {} | |
47 | }; | |
48 | ||
49 | template<typename Tag, typename Arg> | |
50 | struct address_of_hack | |
51 | { | |
52 | typedef not_a_valid_type type; | |
53 | }; | |
54 | ||
55 | template<typename Expr> | |
56 | struct address_of_hack<proto::tag::address_of, Expr &> | |
57 | { | |
58 | typedef Expr *type; | |
59 | }; | |
60 | ||
61 | template<typename T, typename Expr, typename Arg0> | |
62 | BOOST_FORCEINLINE | |
63 | Expr make_terminal(T &t, Expr *, proto::term<Arg0> *) | |
64 | { | |
65 | Expr that = {t}; | |
66 | return that; | |
67 | } | |
68 | ||
69 | template<typename T, typename Expr, typename Arg0, std::size_t N> | |
70 | BOOST_FORCEINLINE | |
71 | Expr make_terminal(T (&t)[N], Expr *, proto::term<Arg0[N]> *) | |
72 | { | |
73 | Expr that; | |
74 | for(std::size_t i = 0; i < N; ++i) | |
75 | { | |
76 | that.child0[i] = t[i]; | |
77 | } | |
78 | return that; | |
79 | } | |
80 | ||
81 | template<typename T, typename Expr, typename Arg0, std::size_t N> | |
82 | BOOST_FORCEINLINE | |
83 | Expr make_terminal(T const(&t)[N], Expr *, proto::term<Arg0[N]> *) | |
84 | { | |
85 | Expr that; | |
86 | for(std::size_t i = 0; i < N; ++i) | |
87 | { | |
88 | that.child0[i] = t[i]; | |
89 | } | |
90 | return that; | |
91 | } | |
92 | ||
93 | // Work-around for: | |
94 | // https://connect.microsoft.com/VisualStudio/feedback/details/765449/codegen-stack-corruption-using-runtime-checks-when-aggregate-initializing-struct | |
95 | #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1700)) | |
96 | template<typename T, typename Expr, typename C, typename U> | |
97 | BOOST_FORCEINLINE | |
98 | Expr make_terminal(T &t, Expr *, proto::term<U C::*> *) | |
99 | { | |
100 | Expr that; | |
101 | that.child0 = t; | |
102 | return that; | |
103 | } | |
104 | #endif | |
105 | ||
106 | template<typename T, typename U> | |
107 | struct same_cv | |
108 | { | |
109 | typedef U type; | |
110 | }; | |
111 | ||
112 | template<typename T, typename U> | |
113 | struct same_cv<T const, U> | |
114 | { | |
115 | typedef U const type; | |
116 | }; | |
117 | } | |
118 | ||
119 | namespace result_of | |
120 | { | |
121 | /// \brief A helper metafunction for computing the | |
122 | /// return type of \c proto::expr\<\>::operator(). | |
123 | template<typename Sig, typename This, typename Domain> | |
124 | struct funop; | |
125 | ||
126 | #include <boost/proto/detail/funop.hpp> | |
127 | } | |
128 | ||
129 | namespace exprns_ | |
130 | { | |
131 | // This is where the basic_expr specializations are | |
132 | // actually defined: | |
133 | #include <boost/proto/detail/basic_expr.hpp> | |
134 | ||
135 | // This is where the expr specialization are | |
136 | // actually defined: | |
137 | #include <boost/proto/detail/expr.hpp> | |
138 | } | |
139 | ||
140 | /// \brief Lets you inherit the interface of an expression | |
141 | /// while hiding from Proto the fact that the type is a Proto | |
142 | /// expression. | |
143 | template<typename Expr> | |
144 | struct unexpr | |
145 | : Expr | |
146 | { | |
147 | BOOST_PROTO_UNEXPR() | |
148 | ||
149 | BOOST_FORCEINLINE | |
150 | explicit unexpr(Expr const &e) | |
151 | : Expr(e) | |
152 | {} | |
153 | ||
154 | using Expr::operator =; | |
155 | }; | |
156 | ||
157 | }} | |
158 | ||
159 | #if defined(_MSC_VER) | |
160 | # pragma warning(pop) | |
161 | #endif | |
162 | ||
163 | #endif // BOOST_PROTO_EXPR_HPP_EAN_04_01_2005 |