]>
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 | |
92f5a8d4 | 95 | #if BOOST_WORKAROUND(BOOST_MSVC, < 1800) |
7c673cae FG |
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 | ||
20effc67 TL |
135 | #if defined(__GNUC__) && __GNUC__ >= 9 || defined(__clang__) && __clang_major__ >= 10 |
136 | #pragma GCC diagnostic push | |
137 | // The warning cannot be fixed for aggregates | |
138 | // Sadly, GCC currently emits the warning at the use location: | |
139 | // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94492 | |
140 | #pragma GCC diagnostic ignored "-Wdeprecated-copy" | |
141 | #endif | |
142 | ||
7c673cae FG |
143 | // This is where the expr specialization are |
144 | // actually defined: | |
145 | #include <boost/proto/detail/expr.hpp> | |
20effc67 TL |
146 | |
147 | #if defined(__GNUC__) && __GNUC__ >= 9 || defined(__clang__) && __clang_major__ >= 10 | |
148 | #pragma GCC diagnostic pop | |
149 | #endif | |
7c673cae FG |
150 | } |
151 | ||
152 | /// \brief Lets you inherit the interface of an expression | |
153 | /// while hiding from Proto the fact that the type is a Proto | |
154 | /// expression. | |
155 | template<typename Expr> | |
156 | struct unexpr | |
157 | : Expr | |
158 | { | |
159 | BOOST_PROTO_UNEXPR() | |
160 | ||
161 | BOOST_FORCEINLINE | |
162 | explicit unexpr(Expr const &e) | |
163 | : Expr(e) | |
164 | {} | |
165 | ||
166 | using Expr::operator =; | |
167 | }; | |
168 | ||
169 | }} | |
170 | ||
171 | #if defined(_MSC_VER) | |
172 | # pragma warning(pop) | |
173 | #endif | |
174 | ||
175 | #endif // BOOST_PROTO_EXPR_HPP_EAN_04_01_2005 |