Chris@16
|
1 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 /// \file deduce_domain.hpp
|
Chris@16
|
3 /// Contains definition of deduce_domain\<\> class templates
|
Chris@16
|
4 /// for finding the domain that is common among the specified
|
Chris@16
|
5 /// domains
|
Chris@16
|
6 //
|
Chris@16
|
7 // Copyright 2010 Daniel Wallin, Eric Niebler. Distributed under the Boost
|
Chris@16
|
8 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
9 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
10 //
|
Chris@16
|
11 // Many thanks to Daniel Wallin who first implemented this code. Thanks
|
Chris@16
|
12 // also to Jeremiah Willcock, John Bytheway and Krishna Achuthan who
|
Chris@16
|
13 // offered alternate solutions to this tricky programming problem.
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_PROTO_DEDUCE_DOMAIN_HPP_EAN_05_22_2010
|
Chris@16
|
16 #define BOOST_PROTO_DEDUCE_DOMAIN_HPP_EAN_05_22_2010
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/config.hpp>
|
Chris@16
|
19 #include <boost/preprocessor/cat.hpp>
|
Chris@16
|
20 #include <boost/preprocessor/facilities/intercept.hpp>
|
Chris@16
|
21 #include <boost/preprocessor/iteration/local.hpp>
|
Chris@16
|
22 #include <boost/preprocessor/iteration/iterate.hpp>
|
Chris@16
|
23 #include <boost/preprocessor/repetition/enum_params.hpp>
|
Chris@16
|
24 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
Chris@16
|
25 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
Chris@16
|
26 #include <boost/preprocessor/arithmetic/inc.hpp>
|
Chris@16
|
27 #include <boost/mpl/assert.hpp>
|
Chris@16
|
28 #include <boost/type_traits/is_same.hpp>
|
Chris@16
|
29 #include <boost/proto/proto_fwd.hpp>
|
Chris@16
|
30
|
Chris@16
|
31 #ifndef BOOST_PROTO_ASSERT_VALID_DOMAIN
|
Chris@16
|
32 # define BOOST_PROTO_ASSERT_VALID_DOMAIN(DOM) BOOST_MPL_ASSERT_NOT((boost::is_same<DOM, boost::proto::detail::not_a_domain>))
|
Chris@16
|
33 #endif
|
Chris@16
|
34
|
Chris@16
|
35 namespace boost
|
Chris@16
|
36 {
|
Chris@16
|
37 namespace proto
|
Chris@16
|
38 {
|
Chris@16
|
39 namespace detail
|
Chris@16
|
40 {
|
Chris@16
|
41 template<typename Domain>
|
Chris@16
|
42 struct domain_
|
Chris@16
|
43 : domain_<typename Domain::proto_super_domain>
|
Chris@16
|
44 {
|
Chris@16
|
45 typedef Domain type;
|
Chris@16
|
46 typedef domain_<typename Domain::proto_super_domain> base;
|
Chris@16
|
47 #ifdef BOOST_NO_CXX11_DECLTYPE
|
Chris@16
|
48 using base::deduce98;
|
Chris@16
|
49 static int const index = base::index + 1;
|
Chris@16
|
50 static typename sized_type<index>::type deduce98(domain_<Domain>*);
|
Chris@16
|
51 #else
|
Chris@16
|
52 using base::deduce0x;
|
Chris@16
|
53 static Domain deduce0x(domain_<Domain>*);
|
Chris@16
|
54 #endif
|
Chris@16
|
55 };
|
Chris@16
|
56
|
Chris@16
|
57 template<>
|
Chris@16
|
58 struct domain_<not_a_domain>
|
Chris@16
|
59 {
|
Chris@16
|
60 typedef not_a_domain type;
|
Chris@16
|
61 #ifdef BOOST_NO_CXX11_DECLTYPE
|
Chris@16
|
62 static int const index = 1;
|
Chris@16
|
63 static sized_type<1>::type deduce98(void*);
|
Chris@16
|
64 #else
|
Chris@16
|
65 static not_a_domain deduce0x(void*);
|
Chris@16
|
66 #endif
|
Chris@16
|
67 };
|
Chris@16
|
68
|
Chris@16
|
69 template<>
|
Chris@16
|
70 struct domain_<default_domain>
|
Chris@16
|
71 : domain_<not_a_domain>
|
Chris@16
|
72 {};
|
Chris@16
|
73
|
Chris@16
|
74 template<>
|
Chris@16
|
75 struct domain_<basic_default_domain>
|
Chris@16
|
76 : domain_<not_a_domain>
|
Chris@16
|
77 {};
|
Chris@16
|
78
|
Chris@16
|
79 sized_type<1>::type default_test(void*, void*);
|
Chris@16
|
80 sized_type<2>::type default_test(domain_<default_domain>*, void*);
|
Chris@16
|
81 sized_type<2>::type default_test(domain_<basic_default_domain>*, void*);
|
Chris@16
|
82 sized_type<3>::type default_test(void*, domain_<default_domain>*);
|
Chris@16
|
83 sized_type<3>::type default_test(void*, domain_<basic_default_domain>*);
|
Chris@16
|
84 sized_type<4>::type default_test(domain_<default_domain>*, domain_<default_domain>*);
|
Chris@16
|
85 sized_type<4>::type default_test(domain_<basic_default_domain>*, domain_<default_domain>*);
|
Chris@16
|
86 sized_type<4>::type default_test(domain_<default_domain>*, domain_<basic_default_domain>*);
|
Chris@16
|
87 sized_type<4>::type default_test(domain_<basic_default_domain>*, domain_<basic_default_domain>*);
|
Chris@16
|
88
|
Chris@16
|
89 #ifdef BOOST_NO_CXX11_DECLTYPE
|
Chris@16
|
90 template<int N, typename Domain>
|
Chris@16
|
91 struct nth_domain
|
Chris@16
|
92 : nth_domain<N - 1, typename Domain::base>
|
Chris@16
|
93 {};
|
Chris@16
|
94
|
Chris@16
|
95 template<typename Domain>
|
Chris@16
|
96 struct nth_domain<0, Domain>
|
Chris@16
|
97 : Domain
|
Chris@16
|
98 {};
|
Chris@16
|
99 #endif
|
Chris@16
|
100
|
Chris@16
|
101 template<typename D0>
|
Chris@16
|
102 struct common_domain1
|
Chris@16
|
103 {
|
Chris@16
|
104 typedef D0 type;
|
Chris@16
|
105 };
|
Chris@16
|
106
|
Chris@16
|
107 template<typename E0>
|
Chris@16
|
108 struct deduce_domain1
|
Chris@16
|
109 : domain_of<E0>
|
Chris@16
|
110 {};
|
Chris@16
|
111
|
Chris@16
|
112 template<
|
Chris@16
|
113 typename D0
|
Chris@16
|
114 , typename D1
|
Chris@16
|
115 , int DefaultCase = sizeof(proto::detail::default_test((domain_<D0>*)0, (domain_<D1>*)0))
|
Chris@16
|
116 >
|
Chris@16
|
117 struct common_domain2
|
Chris@16
|
118 {
|
Chris@16
|
119 #ifdef BOOST_NO_CXX11_DECLTYPE
|
Chris@16
|
120 static int const index = domain_<D0>::index - sizeof(domain_<D0>::deduce98((domain_<D1>*)0));
|
Chris@16
|
121 typedef typename nth_domain<index, domain_<D0> >::type type;
|
Chris@16
|
122 #else
|
Chris@16
|
123 typedef decltype(domain_<D0>::deduce0x((domain_<D1>*)0)) type;
|
Chris@16
|
124 #endif
|
Chris@16
|
125 };
|
Chris@16
|
126
|
Chris@16
|
127 template<typename D0, typename D1>
|
Chris@16
|
128 struct common_domain2<D0, D1, 2>
|
Chris@16
|
129 {
|
Chris@16
|
130 typedef D1 type;
|
Chris@16
|
131 };
|
Chris@16
|
132
|
Chris@16
|
133 template<typename D0, typename D1>
|
Chris@16
|
134 struct common_domain2<D0, D1, 3>
|
Chris@16
|
135 {
|
Chris@16
|
136 typedef D0 type;
|
Chris@16
|
137 };
|
Chris@16
|
138
|
Chris@16
|
139 template<typename D0>
|
Chris@16
|
140 struct common_domain2<D0, default_domain, 4>
|
Chris@16
|
141 {
|
Chris@16
|
142 typedef D0 type;
|
Chris@16
|
143 };
|
Chris@16
|
144
|
Chris@16
|
145 template<typename D0>
|
Chris@16
|
146 struct common_domain2<D0, basic_default_domain, 4>
|
Chris@16
|
147 {
|
Chris@16
|
148 typedef D0 type;
|
Chris@16
|
149 };
|
Chris@16
|
150
|
Chris@16
|
151 template<typename D1>
|
Chris@16
|
152 struct common_domain2<default_domain, D1, 4>
|
Chris@16
|
153 {
|
Chris@16
|
154 typedef D1 type;
|
Chris@16
|
155 };
|
Chris@16
|
156
|
Chris@16
|
157 template<typename D1>
|
Chris@16
|
158 struct common_domain2<basic_default_domain, D1, 4>
|
Chris@16
|
159 {
|
Chris@16
|
160 typedef D1 type;
|
Chris@16
|
161 };
|
Chris@16
|
162
|
Chris@16
|
163 template<>
|
Chris@16
|
164 struct common_domain2<default_domain, default_domain, 4>
|
Chris@16
|
165 {
|
Chris@16
|
166 typedef default_domain type;
|
Chris@16
|
167 };
|
Chris@16
|
168
|
Chris@16
|
169 template<>
|
Chris@16
|
170 struct common_domain2<basic_default_domain, default_domain, 4>
|
Chris@16
|
171 {
|
Chris@16
|
172 typedef default_domain type;
|
Chris@16
|
173 };
|
Chris@16
|
174
|
Chris@16
|
175 template<>
|
Chris@16
|
176 struct common_domain2<default_domain, basic_default_domain, 4>
|
Chris@16
|
177 {
|
Chris@16
|
178 typedef default_domain type;
|
Chris@16
|
179 };
|
Chris@16
|
180
|
Chris@16
|
181 template<>
|
Chris@16
|
182 struct common_domain2<basic_default_domain, basic_default_domain, 4>
|
Chris@16
|
183 {
|
Chris@16
|
184 typedef basic_default_domain type;
|
Chris@16
|
185 };
|
Chris@16
|
186
|
Chris@16
|
187 template<typename E0, typename E1>
|
Chris@16
|
188 struct deduce_domain2
|
Chris@16
|
189 : common_domain2<
|
Chris@16
|
190 typename domain_of<E0>::type
|
Chris@16
|
191 , typename domain_of<E1>::type
|
Chris@16
|
192 >
|
Chris@16
|
193 {};
|
Chris@16
|
194
|
Chris@16
|
195 #include <boost/proto/detail/deduce_domain_n.hpp>
|
Chris@16
|
196 }
|
Chris@16
|
197 }
|
Chris@16
|
198 }
|
Chris@16
|
199
|
Chris@16
|
200 #endif // BOOST_PROTO_DEDUCE_DOMAIN_HPP_EAN_05_22_2010
|