annotate DEPENDENCIES/generic/include/boost/lambda/detail/lambda_functors.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Boost Lambda Library - lambda_functors.hpp -------------------------------
Chris@16 2
Chris@16 3 // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
Chris@16 4 //
Chris@16 5 // Distributed under the Boost Software License, Version 1.0. (See
Chris@16 6 // accompanying file LICENSE_1_0.txt or copy at
Chris@16 7 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8 //
Chris@16 9 // For more information, see http://www.boost.org
Chris@16 10
Chris@16 11 // ------------------------------------------------
Chris@16 12
Chris@16 13 #ifndef BOOST_LAMBDA_LAMBDA_FUNCTORS_HPP
Chris@16 14 #define BOOST_LAMBDA_LAMBDA_FUNCTORS_HPP
Chris@16 15
Chris@16 16 #include <boost/config.hpp>
Chris@16 17 #include <boost/detail/workaround.hpp>
Chris@16 18 #include <boost/utility/result_of.hpp>
Chris@16 19
Chris@16 20 #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
Chris@16 21
Chris@16 22 #include <boost/mpl/or.hpp>
Chris@16 23 #include <boost/utility/enable_if.hpp>
Chris@16 24 #include <boost/type_traits/is_array.hpp>
Chris@16 25
Chris@16 26 #define BOOST_LAMBDA_DISABLE_IF_ARRAY1(A1, R1)\
Chris@16 27 typename lazy_disable_if<is_array<A1>, typename R1 >::type
Chris@16 28 #define BOOST_LAMBDA_DISABLE_IF_ARRAY2(A1, A2, R1, R2) \
Chris@16 29 typename lazy_disable_if<mpl::or_<is_array<A1>, is_array<A2> >, typename R1, R2 >::type
Chris@16 30 #define BOOST_LAMBDA_DISABLE_IF_ARRAY3(A1, A2, A3, R1, R2, R3) \
Chris@16 31 typename lazy_disable_if<mpl::or_<is_array<A1>, is_array<A2>, is_array<A3> >, typename R1, R2, R3 >::type
Chris@16 32
Chris@16 33 #else
Chris@16 34
Chris@16 35 #define BOOST_LAMBDA_DISABLE_IF_ARRAY1(A1, R1) typename R1::type
Chris@16 36 #define BOOST_LAMBDA_DISABLE_IF_ARRAY2(A1, A2, R1, R2) typename R1, R2::type
Chris@16 37 #define BOOST_LAMBDA_DISABLE_IF_ARRAY3(A1, A2, A3, R1, R2, R3) typename R1, R2, R3::type
Chris@16 38
Chris@16 39 #endif
Chris@16 40
Chris@16 41 namespace boost {
Chris@16 42 namespace lambda {
Chris@16 43
Chris@16 44 // -- lambda_functor --------------------------------------------
Chris@16 45 // --------------------------------------------------------------
Chris@16 46
Chris@16 47 //inline const null_type const_null_type() { return null_type(); }
Chris@16 48
Chris@16 49 namespace detail {
Chris@16 50 namespace {
Chris@16 51
Chris@16 52 static const null_type constant_null_type = null_type();
Chris@16 53
Chris@16 54 } // unnamed
Chris@16 55 } // detail
Chris@16 56
Chris@16 57 class unused {};
Chris@16 58
Chris@16 59 #define cnull_type() detail::constant_null_type
Chris@16 60
Chris@16 61 // -- free variables types --------------------------------------------------
Chris@16 62
Chris@16 63 // helper to work around the case where the nullary return type deduction
Chris@16 64 // is always performed, even though the functor is not nullary
Chris@16 65 namespace detail {
Chris@16 66 template<int N, class Tuple> struct get_element_or_null_type {
Chris@16 67 typedef typename
Chris@16 68 detail::tuple_element_as_reference<N, Tuple>::type type;
Chris@16 69 };
Chris@16 70 template<int N> struct get_element_or_null_type<N, null_type> {
Chris@16 71 typedef null_type type;
Chris@16 72 };
Chris@16 73 }
Chris@16 74
Chris@16 75 template <int I> struct placeholder;
Chris@16 76
Chris@16 77 template<> struct placeholder<FIRST> {
Chris@16 78
Chris@16 79 template<class SigArgs> struct sig {
Chris@16 80 typedef typename detail::get_element_or_null_type<0, SigArgs>::type type;
Chris@16 81 };
Chris@16 82
Chris@16 83 template<class RET, CALL_TEMPLATE_ARGS>
Chris@16 84 RET call(CALL_FORMAL_ARGS) const {
Chris@16 85 BOOST_STATIC_ASSERT(boost::is_reference<RET>::value);
Chris@16 86 CALL_USE_ARGS; // does nothing, prevents warnings for unused args
Chris@16 87 return a;
Chris@16 88 }
Chris@16 89 };
Chris@16 90
Chris@16 91 template<> struct placeholder<SECOND> {
Chris@16 92
Chris@16 93 template<class SigArgs> struct sig {
Chris@16 94 typedef typename detail::get_element_or_null_type<1, SigArgs>::type type;
Chris@16 95 };
Chris@16 96
Chris@16 97 template<class RET, CALL_TEMPLATE_ARGS>
Chris@16 98 RET call(CALL_FORMAL_ARGS) const { CALL_USE_ARGS; return b; }
Chris@16 99 };
Chris@16 100
Chris@16 101 template<> struct placeholder<THIRD> {
Chris@16 102
Chris@16 103 template<class SigArgs> struct sig {
Chris@16 104 typedef typename detail::get_element_or_null_type<2, SigArgs>::type type;
Chris@16 105 };
Chris@16 106
Chris@16 107 template<class RET, CALL_TEMPLATE_ARGS>
Chris@16 108 RET call(CALL_FORMAL_ARGS) const { CALL_USE_ARGS; return c; }
Chris@16 109 };
Chris@16 110
Chris@16 111 template<> struct placeholder<EXCEPTION> {
Chris@16 112
Chris@16 113 template<class SigArgs> struct sig {
Chris@16 114 typedef typename detail::get_element_or_null_type<3, SigArgs>::type type;
Chris@16 115 };
Chris@16 116
Chris@16 117 template<class RET, CALL_TEMPLATE_ARGS>
Chris@16 118 RET call(CALL_FORMAL_ARGS) const { CALL_USE_ARGS; return env; }
Chris@16 119 };
Chris@16 120
Chris@16 121 typedef const lambda_functor<placeholder<FIRST> > placeholder1_type;
Chris@16 122 typedef const lambda_functor<placeholder<SECOND> > placeholder2_type;
Chris@16 123 typedef const lambda_functor<placeholder<THIRD> > placeholder3_type;
Chris@16 124
Chris@16 125
Chris@16 126 ///////////////////////////////////////////////////////////////////////////////
Chris@16 127
Chris@16 128
Chris@16 129 // free variables are lambda_functors. This is to allow uniform handling with
Chris@16 130 // other lambda_functors.
Chris@16 131 // -------------------------------------------------------------------
Chris@16 132
Chris@16 133 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
Chris@16 134 #pragma warning(push)
Chris@16 135 #pragma warning(disable:4512) //assignment operator could not be generated
Chris@16 136 #endif
Chris@16 137
Chris@16 138 // -- lambda_functor NONE ------------------------------------------------
Chris@16 139 template <class T>
Chris@16 140 class lambda_functor : public T
Chris@16 141 {
Chris@16 142
Chris@16 143 BOOST_STATIC_CONSTANT(int, arity_bits = get_arity<T>::value);
Chris@16 144
Chris@16 145 public:
Chris@16 146 typedef T inherited;
Chris@16 147
Chris@16 148 lambda_functor() {}
Chris@16 149 lambda_functor(const lambda_functor& l) : inherited(l) {}
Chris@16 150
Chris@16 151 lambda_functor(const T& t) : inherited(t) {}
Chris@16 152
Chris@16 153 template <class SigArgs> struct sig {
Chris@16 154 typedef typename inherited::template
Chris@16 155 sig<typename SigArgs::tail_type>::type type;
Chris@16 156 };
Chris@16 157
Chris@16 158 // Note that this return type deduction template is instantiated, even
Chris@16 159 // if the nullary
Chris@16 160 // operator() is not called at all. One must make sure that it does not fail.
Chris@16 161 typedef typename
Chris@16 162 inherited::template sig<null_type>::type
Chris@16 163 nullary_return_type;
Chris@16 164
Chris@16 165 // Support for boost::result_of.
Chris@16 166 template <class Sig> struct result;
Chris@16 167 template <class F>
Chris@16 168 struct result<F()> {
Chris@16 169 typedef nullary_return_type type;
Chris@16 170 };
Chris@16 171 template <class F, class A>
Chris@16 172 struct result<F(A)> {
Chris@16 173 typedef typename sig<tuple<F, A> >::type type;
Chris@16 174 };
Chris@16 175 template <class F, class A, class B>
Chris@16 176 struct result<F(A, B)> {
Chris@16 177 typedef typename sig<tuple<F, A, B> >::type type;
Chris@16 178 };
Chris@16 179 template <class F, class A, class B, class C>
Chris@16 180 struct result<F(A, B, C)> {
Chris@16 181 typedef typename sig<tuple<F, A, B, C> >::type type;
Chris@16 182 };
Chris@16 183
Chris@16 184 nullary_return_type operator()() const {
Chris@16 185 return inherited::template
Chris@16 186 call<nullary_return_type>
Chris@16 187 (cnull_type(), cnull_type(), cnull_type(), cnull_type());
Chris@16 188 }
Chris@16 189
Chris@16 190 template<class A>
Chris@16 191 typename inherited::template sig<tuple<A&> >::type
Chris@16 192 operator()(A& a) const {
Chris@16 193 return inherited::template call<
Chris@16 194 typename inherited::template sig<tuple<A&> >::type
Chris@16 195 >(a, cnull_type(), cnull_type(), cnull_type());
Chris@16 196 }
Chris@16 197
Chris@16 198 template<class A>
Chris@16 199 BOOST_LAMBDA_DISABLE_IF_ARRAY1(A, inherited::template sig<tuple<A const&> >)
Chris@16 200 operator()(A const& a) const {
Chris@16 201 return inherited::template call<
Chris@16 202 typename inherited::template sig<tuple<A const&> >::type
Chris@16 203 >(a, cnull_type(), cnull_type(), cnull_type());
Chris@16 204 }
Chris@16 205
Chris@16 206 template<class A, class B>
Chris@16 207 typename inherited::template sig<tuple<A&, B&> >::type
Chris@16 208 operator()(A& a, B& b) const {
Chris@16 209 return inherited::template call<
Chris@16 210 typename inherited::template sig<tuple<A&, B&> >::type
Chris@16 211 >(a, b, cnull_type(), cnull_type());
Chris@16 212 }
Chris@16 213
Chris@16 214 template<class A, class B>
Chris@16 215 BOOST_LAMBDA_DISABLE_IF_ARRAY2(A, B, inherited::template sig<tuple<A const&, B&> >)
Chris@16 216 operator()(A const& a, B& b) const {
Chris@16 217 return inherited::template call<
Chris@16 218 typename inherited::template sig<tuple<A const&, B&> >::type
Chris@16 219 >(a, b, cnull_type(), cnull_type());
Chris@16 220 }
Chris@16 221
Chris@16 222 template<class A, class B>
Chris@16 223 BOOST_LAMBDA_DISABLE_IF_ARRAY2(A, B, inherited::template sig<tuple<A&, B const&> >)
Chris@16 224 operator()(A& a, B const& b) const {
Chris@16 225 return inherited::template call<
Chris@16 226 typename inherited::template sig<tuple<A&, B const&> >::type
Chris@16 227 >(a, b, cnull_type(), cnull_type());
Chris@16 228 }
Chris@16 229
Chris@16 230 template<class A, class B>
Chris@16 231 BOOST_LAMBDA_DISABLE_IF_ARRAY2(A, B, inherited::template sig<tuple<A const&, B const&> >)
Chris@16 232 operator()(A const& a, B const& b) const {
Chris@16 233 return inherited::template call<
Chris@16 234 typename inherited::template sig<tuple<A const&, B const&> >::type
Chris@16 235 >(a, b, cnull_type(), cnull_type());
Chris@16 236 }
Chris@16 237
Chris@16 238 template<class A, class B, class C>
Chris@16 239 typename inherited::template sig<tuple<A&, B&, C&> >::type
Chris@16 240 operator()(A& a, B& b, C& c) const
Chris@16 241 {
Chris@16 242 return inherited::template call<
Chris@16 243 typename inherited::template sig<tuple<A&, B&, C&> >::type
Chris@16 244 >(a, b, c, cnull_type());
Chris@16 245 }
Chris@16 246
Chris@16 247 template<class A, class B, class C>
Chris@16 248 BOOST_LAMBDA_DISABLE_IF_ARRAY3(A, B, C, inherited::template sig<tuple<A const&, B const&, C const&> >)
Chris@16 249 operator()(A const& a, B const& b, C const& c) const
Chris@16 250 {
Chris@16 251 return inherited::template call<
Chris@16 252 typename inherited::template sig<tuple<A const&, B const&, C const&> >::type
Chris@16 253 >(a, b, c, cnull_type());
Chris@16 254 }
Chris@16 255
Chris@16 256 // for internal calls with env
Chris@16 257 template<CALL_TEMPLATE_ARGS>
Chris@16 258 typename inherited::template sig<tuple<CALL_REFERENCE_TYPES> >::type
Chris@16 259 internal_call(CALL_FORMAL_ARGS) const {
Chris@16 260 return inherited::template
Chris@16 261 call<typename inherited::template
Chris@16 262 sig<tuple<CALL_REFERENCE_TYPES> >::type>(CALL_ACTUAL_ARGS);
Chris@16 263 }
Chris@16 264
Chris@16 265 template<class A>
Chris@16 266 const lambda_functor<lambda_functor_base<
Chris@16 267 other_action<assignment_action>,
Chris@16 268 boost::tuple<lambda_functor,
Chris@16 269 typename const_copy_argument <const A>::type> > >
Chris@16 270 operator=(const A& a) const {
Chris@16 271 return lambda_functor_base<
Chris@16 272 other_action<assignment_action>,
Chris@16 273 boost::tuple<lambda_functor,
Chris@16 274 typename const_copy_argument <const A>::type> >
Chris@16 275 ( boost::tuple<lambda_functor,
Chris@16 276 typename const_copy_argument <const A>::type>(*this, a) );
Chris@16 277 }
Chris@16 278
Chris@16 279 template<class A>
Chris@16 280 const lambda_functor<lambda_functor_base<
Chris@16 281 other_action<subscript_action>,
Chris@16 282 boost::tuple<lambda_functor,
Chris@16 283 typename const_copy_argument <const A>::type> > >
Chris@16 284 operator[](const A& a) const {
Chris@16 285 return lambda_functor_base<
Chris@16 286 other_action<subscript_action>,
Chris@16 287 boost::tuple<lambda_functor,
Chris@16 288 typename const_copy_argument <const A>::type> >
Chris@16 289 ( boost::tuple<lambda_functor,
Chris@16 290 typename const_copy_argument <const A>::type>(*this, a ) );
Chris@16 291 }
Chris@16 292 };
Chris@16 293
Chris@16 294 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
Chris@16 295 #pragma warning(pop)
Chris@16 296 #endif
Chris@16 297
Chris@16 298 } // namespace lambda
Chris@16 299 } // namespace boost
Chris@16 300
Chris@16 301 namespace boost {
Chris@16 302
Chris@16 303 #if !defined(BOOST_RESULT_OF_USE_DECLTYPE) || defined(BOOST_NO_DECLTYPE)
Chris@16 304
Chris@16 305 template<class T>
Chris@16 306 struct result_of<boost::lambda::lambda_functor<T>()>
Chris@16 307 {
Chris@16 308 typedef typename boost::lambda::lambda_functor<T>::nullary_return_type type;
Chris@16 309 };
Chris@16 310
Chris@16 311 template<class T>
Chris@16 312 struct result_of<const boost::lambda::lambda_functor<T>()>
Chris@16 313 {
Chris@16 314 typedef typename boost::lambda::lambda_functor<T>::nullary_return_type type;
Chris@16 315 };
Chris@16 316
Chris@16 317 #endif
Chris@16 318
Chris@16 319 template<class T>
Chris@16 320 struct tr1_result_of<boost::lambda::lambda_functor<T>()>
Chris@16 321 {
Chris@16 322 typedef typename boost::lambda::lambda_functor<T>::nullary_return_type type;
Chris@16 323 };
Chris@16 324
Chris@16 325 template<class T>
Chris@16 326 struct tr1_result_of<const boost::lambda::lambda_functor<T>()>
Chris@16 327 {
Chris@16 328 typedef typename boost::lambda::lambda_functor<T>::nullary_return_type type;
Chris@16 329 };
Chris@16 330
Chris@16 331 }
Chris@16 332
Chris@16 333 // is_placeholder
Chris@16 334
Chris@16 335 #include <boost/is_placeholder.hpp>
Chris@16 336
Chris@16 337 namespace boost
Chris@16 338 {
Chris@16 339
Chris@16 340 template<> struct is_placeholder< lambda::lambda_functor< lambda::placeholder<lambda::FIRST> > >
Chris@16 341 {
Chris@16 342 enum _vt { value = 1 };
Chris@16 343 };
Chris@16 344
Chris@16 345 template<> struct is_placeholder< lambda::lambda_functor< lambda::placeholder<lambda::SECOND> > >
Chris@16 346 {
Chris@16 347 enum _vt { value = 2 };
Chris@16 348 };
Chris@16 349
Chris@16 350 template<> struct is_placeholder< lambda::lambda_functor< lambda::placeholder<lambda::THIRD> > >
Chris@16 351 {
Chris@16 352 enum _vt { value = 3 };
Chris@16 353 };
Chris@16 354
Chris@16 355 } // namespace boost
Chris@16 356
Chris@16 357 #endif