Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
1 //-----------------------------------------------------------------------------
2 // boost variant/detail/visitation_impl.hpp header file
3 // See http://www.boost.org for updates, documentation, and revision history.
4 //-----------------------------------------------------------------------------
9 // Distributed under the Boost Software License, Version 1.0. (See
10 // accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
13 #ifndef BOOST_VARIANT_DETAIL_VISITATION_IMPL_HPP
14 #define BOOST_VARIANT_DETAIL_VISITATION_IMPL_HPP
16 #include "boost/config.hpp"
18 #include "boost/variant/detail/backup_holder.hpp"
19 #include "boost/variant/detail/cast_storage.hpp"
20 #include "boost/variant/detail/forced_return.hpp"
21 #include "boost/variant/detail/generic_result_type.hpp"
23 #include "boost/assert.hpp"
24 #include "boost/mpl/eval_if.hpp"
25 #include "boost/mpl/bool.hpp"
26 #include "boost/mpl/identity.hpp"
27 #include "boost/mpl/int.hpp"
28 #include "boost/mpl/next.hpp"
29 #include "boost/mpl/deref.hpp"
30 #include "boost/mpl/or.hpp"
31 #include "boost/preprocessor/cat.hpp"
32 #include "boost/preprocessor/inc.hpp"
33 #include "boost/preprocessor/repeat.hpp"
34 #include "boost/type_traits/is_same.hpp"
35 #include "boost/type_traits/has_nothrow_copy.hpp"
36 #include "boost/variant/detail/has_nothrow_move.hpp"
39 ///////////////////////////////////////////////////////////////////////////////
40 // BOOST_VARIANT_VISITATION_UNROLLING_LIMIT
42 // Unrolls variant's visitation mechanism to reduce template instantiation
43 // and potentially increase runtime performance. (TODO: Investigate further.)
45 #if !defined(BOOST_VARIANT_VISITATION_UNROLLING_LIMIT)
46 # define BOOST_VARIANT_VISITATION_UNROLLING_LIMIT \
47 BOOST_VARIANT_LIMIT_TYPES
51 namespace detail { namespace variant {
53 ///////////////////////////////////////////////////////////////////////////////
54 // (detail) class apply_visitor_unrolled
56 // Tag type indicates when visitation_impl is unrolled.
58 struct apply_visitor_unrolled {};
60 ///////////////////////////////////////////////////////////////////////////////
61 // (detail) class template visitation_impl_step
63 // "Never ending" iterator range facilitates visitation_impl unrolling.
66 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
68 template <typename Iter, typename LastIter>
69 struct visitation_impl_step
71 typedef typename mpl::deref<Iter>::type type;
73 typedef typename mpl::next<Iter>::type next_iter;
74 typedef visitation_impl_step<
79 template <typename LastIter>
80 struct visitation_impl_step< LastIter,LastIter >
82 typedef apply_visitor_unrolled type;
83 typedef visitation_impl_step next;
86 #else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
88 template <typename Iter, typename LastIter>
89 struct visitation_impl_step
91 typedef typename mpl::eval_if<
92 is_same<Iter, LastIter>
93 , mpl::identity<apply_visitor_unrolled>
97 typedef typename mpl::eval_if<
98 is_same<type, apply_visitor_unrolled> //is_same<Iter, LastIter>
99 , mpl::identity<LastIter>
103 typedef visitation_impl_step<
108 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
110 ///////////////////////////////////////////////////////////////////////////////
111 // (detail) function template visitation_impl_invoke
113 // Invokes the given visitor on the specified type in the given storage.
116 template <typename Visitor, typename VoidPtrCV, typename T>
118 BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename Visitor::result_type)
119 visitation_impl_invoke_impl(
120 int, Visitor& visitor, VoidPtrCV storage, T*
121 , mpl::true_// never_uses_backup
124 return visitor.internal_visit(
125 cast_storage<T>(storage), 1L
129 template <typename Visitor, typename VoidPtrCV, typename T>
131 BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename Visitor::result_type)
132 visitation_impl_invoke_impl(
133 int internal_which, Visitor& visitor, VoidPtrCV storage, T*
134 , mpl::false_// never_uses_backup
137 if (internal_which >= 0)
139 return visitor.internal_visit(
140 cast_storage<T>(storage), 1L
145 return visitor.internal_visit(
146 cast_storage< backup_holder<T> >(storage), 1L
151 template <typename Visitor, typename VoidPtrCV, typename T, typename NoBackupFlag>
153 BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename Visitor::result_type)
154 visitation_impl_invoke(
155 int internal_which, Visitor& visitor, VoidPtrCV storage, T* t
160 typedef typename mpl::or_<
162 , has_nothrow_move_constructor<T>
163 , has_nothrow_copy<T>
164 >::type never_uses_backup;
166 return visitation_impl_invoke_impl(
167 internal_which, visitor, storage, t
168 , never_uses_backup()
172 template <typename Visitor, typename VoidPtrCV, typename NBF>
174 BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename Visitor::result_type)
175 visitation_impl_invoke(int, Visitor&, VoidPtrCV, apply_visitor_unrolled*, NBF, long)
177 // should never be here at runtime:
179 typedef typename Visitor::result_type result_type;
180 return ::boost::detail::variant::forced_return< result_type >();
183 ///////////////////////////////////////////////////////////////////////////////
184 // (detail) function template visitation_impl
186 // Invokes the given visitor on the type in the given variant storage.
190 typename W, typename S
191 , typename Visitor, typename VPCV
195 BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename Visitor::result_type)
197 int, int, Visitor&, VPCV
198 , mpl::true_ // is_apply_visitor_unrolled
199 , NBF, W* = 0, S* = 0
202 // should never be here at runtime:
204 typedef typename Visitor::result_type result_type;
205 return ::boost::detail::variant::forced_return< result_type >();
209 typename Which, typename step0
210 , typename Visitor, typename VoidPtrCV
211 , typename NoBackupFlag
214 BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename Visitor::result_type)
216 const int internal_which, const int logical_which
217 , Visitor& visitor, VoidPtrCV storage
218 , mpl::false_ // is_apply_visitor_unrolled
219 , NoBackupFlag no_backup_flag
220 , Which* = 0, step0* = 0
223 // Typedef apply_visitor_unrolled steps and associated types...
224 # define BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_TYPEDEF(z, N, _) \
225 typedef typename BOOST_PP_CAT(step,N)::type BOOST_PP_CAT(T,N); \
226 typedef typename BOOST_PP_CAT(step,N)::next \
227 BOOST_PP_CAT(step, BOOST_PP_INC(N)); \
231 BOOST_VARIANT_VISITATION_UNROLLING_LIMIT
232 , BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_TYPEDEF
236 # undef BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_TYPEDEF
238 // ...switch on the target which-index value...
239 switch (logical_which)
242 // ...applying the appropriate case:
243 # define BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_CASE(z, N, _) \
244 case (Which::value + (N)): \
245 return visitation_impl_invoke( \
246 internal_which, visitor, storage \
247 , static_cast<BOOST_PP_CAT(T,N)*>(0) \
248 , no_backup_flag, 1L \
253 BOOST_VARIANT_VISITATION_UNROLLING_LIMIT
254 , BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_CASE
258 # undef BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_CASE
262 // If not handled in this iteration, continue unrolling:
264 Which::value + (BOOST_VARIANT_VISITATION_UNROLLING_LIMIT)
267 typedef BOOST_PP_CAT(step, BOOST_VARIANT_VISITATION_UNROLLING_LIMIT)
270 typedef typename next_step::type next_type;
271 typedef typename is_same< next_type,apply_visitor_unrolled >::type
272 is_apply_visitor_unrolled;
274 return visitation_impl(
275 internal_which, logical_which
277 , is_apply_visitor_unrolled()
279 , static_cast<next_which*>(0), static_cast<next_step*>(0)
283 }} // namespace detail::variant
286 #endif // BOOST_VARIANT_DETAIL_VISITATION_IMPL_HPP