annotate DEPENDENCIES/generic/include/boost/lambda/detail/operators.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Boost Lambda Library - operators.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 www.boost.org
Chris@16 10
Chris@16 11 // ---------------------------------------------------------------
Chris@16 12
Chris@16 13 #ifndef BOOST_LAMBDA_OPERATORS_HPP
Chris@16 14 #define BOOST_LAMBDA_OPERATORS_HPP
Chris@16 15
Chris@16 16 #include "boost/lambda/detail/is_instance_of.hpp"
Chris@16 17
Chris@16 18 namespace boost {
Chris@16 19 namespace lambda {
Chris@16 20
Chris@16 21 #if defined BOOST_LAMBDA_BE1
Chris@16 22 #error "Multiple defines of BOOST_LAMBDA_BE1"
Chris@16 23 #endif
Chris@16 24
Chris@16 25 // For all BOOSTA_LAMBDA_BE* macros:
Chris@16 26
Chris@16 27 // CONSTA must be either 'A' or 'const A'
Chris@16 28 // CONSTB must be either 'B' or 'const B'
Chris@16 29
Chris@16 30 // It is stupid to have the names A and B as macro arguments, but it avoids
Chris@16 31 // the need to pass in emtpy macro arguments, which gives warnings on some
Chris@16 32 // compilers
Chris@16 33
Chris@16 34 #define BOOST_LAMBDA_BE1(OPER_NAME, ACTION, CONSTA, CONSTB, CONVERSION) \
Chris@16 35 template<class Arg, class B> \
Chris@16 36 inline const \
Chris@16 37 lambda_functor< \
Chris@16 38 lambda_functor_base< \
Chris@16 39 ACTION, \
Chris@16 40 tuple<lambda_functor<Arg>, typename const_copy_argument <CONSTB>::type> \
Chris@16 41 > \
Chris@16 42 > \
Chris@16 43 OPER_NAME (const lambda_functor<Arg>& a, CONSTB& b) { \
Chris@16 44 return \
Chris@16 45 lambda_functor_base< \
Chris@16 46 ACTION, \
Chris@16 47 tuple<lambda_functor<Arg>, typename const_copy_argument <CONSTB>::type>\
Chris@16 48 > \
Chris@16 49 (tuple<lambda_functor<Arg>, typename const_copy_argument <CONSTB>::type>(a, b)); \
Chris@16 50 }
Chris@16 51
Chris@16 52
Chris@16 53 #if defined BOOST_LAMBDA_BE2
Chris@16 54 #error "Multiple defines of BOOST_LAMBDA_BE2"
Chris@16 55 #endif
Chris@16 56
Chris@16 57 #define BOOST_LAMBDA_BE2(OPER_NAME, ACTION, CONSTA, CONSTB, CONVERSION) \
Chris@16 58 template<class A, class Arg> \
Chris@16 59 inline const \
Chris@16 60 lambda_functor< \
Chris@16 61 lambda_functor_base< \
Chris@16 62 ACTION, \
Chris@16 63 tuple<typename CONVERSION <CONSTA>::type, lambda_functor<Arg> > \
Chris@16 64 > \
Chris@16 65 > \
Chris@16 66 OPER_NAME (CONSTA& a, const lambda_functor<Arg>& b) { \
Chris@16 67 return \
Chris@16 68 lambda_functor_base< \
Chris@16 69 ACTION, \
Chris@16 70 tuple<typename CONVERSION <CONSTA>::type, lambda_functor<Arg> > \
Chris@16 71 > \
Chris@16 72 (tuple<typename CONVERSION <CONSTA>::type, lambda_functor<Arg> >(a, b)); \
Chris@16 73 }
Chris@16 74
Chris@16 75
Chris@16 76 #if defined BOOST_LAMBDA_BE3
Chris@16 77 #error "Multiple defines of BOOST_LAMBDA_BE3"
Chris@16 78 #endif
Chris@16 79
Chris@16 80 #define BOOST_LAMBDA_BE3(OPER_NAME, ACTION, CONSTA, CONSTB, CONVERSION) \
Chris@16 81 template<class ArgA, class ArgB> \
Chris@16 82 inline const \
Chris@16 83 lambda_functor< \
Chris@16 84 lambda_functor_base< \
Chris@16 85 ACTION, \
Chris@16 86 tuple<lambda_functor<ArgA>, lambda_functor<ArgB> > \
Chris@16 87 > \
Chris@16 88 > \
Chris@16 89 OPER_NAME (const lambda_functor<ArgA>& a, const lambda_functor<ArgB>& b) { \
Chris@16 90 return \
Chris@16 91 lambda_functor_base< \
Chris@16 92 ACTION, \
Chris@16 93 tuple<lambda_functor<ArgA>, lambda_functor<ArgB> > \
Chris@16 94 > \
Chris@16 95 (tuple<lambda_functor<ArgA>, lambda_functor<ArgB> >(a, b)); \
Chris@16 96 }
Chris@16 97
Chris@16 98 #if defined BOOST_LAMBDA_BE
Chris@16 99 #error "Multiple defines of BOOST_LAMBDA_BE"
Chris@16 100 #endif
Chris@16 101
Chris@16 102 #define BOOST_LAMBDA_BE(OPER_NAME, ACTION, CONSTA, CONSTB, CONST_CONVERSION) \
Chris@16 103 BOOST_LAMBDA_BE1(OPER_NAME, ACTION, CONSTA, CONSTB, CONST_CONVERSION) \
Chris@16 104 BOOST_LAMBDA_BE2(OPER_NAME, ACTION, CONSTA, CONSTB, CONST_CONVERSION) \
Chris@16 105 BOOST_LAMBDA_BE3(OPER_NAME, ACTION, CONSTA, CONSTB, CONST_CONVERSION)
Chris@16 106
Chris@16 107 #define BOOST_LAMBDA_EMPTY()
Chris@16 108
Chris@16 109 BOOST_LAMBDA_BE(operator+, arithmetic_action<plus_action>, const A, const B, const_copy_argument)
Chris@16 110 BOOST_LAMBDA_BE(operator-, arithmetic_action<minus_action>, const A, const B, const_copy_argument)
Chris@16 111 BOOST_LAMBDA_BE(operator*, arithmetic_action<multiply_action>, const A, const B, const_copy_argument)
Chris@16 112 BOOST_LAMBDA_BE(operator/, arithmetic_action<divide_action>, const A, const B, const_copy_argument)
Chris@16 113 BOOST_LAMBDA_BE(operator%, arithmetic_action<remainder_action>, const A, const B, const_copy_argument)
Chris@16 114 BOOST_LAMBDA_BE(operator<<, bitwise_action<leftshift_action>, const A, const B, const_copy_argument)
Chris@16 115 BOOST_LAMBDA_BE(operator>>, bitwise_action<rightshift_action>, const A, const B, const_copy_argument)
Chris@16 116 BOOST_LAMBDA_BE(operator&, bitwise_action<and_action>, const A, const B, const_copy_argument)
Chris@16 117 BOOST_LAMBDA_BE(operator|, bitwise_action<or_action>, const A, const B, const_copy_argument)
Chris@16 118 BOOST_LAMBDA_BE(operator^, bitwise_action<xor_action>, const A, const B, const_copy_argument)
Chris@16 119 BOOST_LAMBDA_BE(operator&&, logical_action<and_action>, const A, const B, const_copy_argument)
Chris@16 120 BOOST_LAMBDA_BE(operator||, logical_action<or_action>, const A, const B, const_copy_argument)
Chris@16 121 BOOST_LAMBDA_BE(operator<, relational_action<less_action>, const A, const B, const_copy_argument)
Chris@16 122 BOOST_LAMBDA_BE(operator>, relational_action<greater_action>, const A, const B, const_copy_argument)
Chris@16 123 BOOST_LAMBDA_BE(operator<=, relational_action<lessorequal_action>, const A, const B, const_copy_argument)
Chris@16 124 BOOST_LAMBDA_BE(operator>=, relational_action<greaterorequal_action>, const A, const B, const_copy_argument)
Chris@16 125 BOOST_LAMBDA_BE(operator==, relational_action<equal_action>, const A, const B, const_copy_argument)
Chris@16 126 BOOST_LAMBDA_BE(operator!=, relational_action<notequal_action>, const A, const B, const_copy_argument)
Chris@16 127
Chris@16 128 BOOST_LAMBDA_BE(operator+=, arithmetic_assignment_action<plus_action>, A, const B, reference_argument)
Chris@16 129 BOOST_LAMBDA_BE(operator-=, arithmetic_assignment_action<minus_action>, A, const B, reference_argument)
Chris@16 130 BOOST_LAMBDA_BE(operator*=, arithmetic_assignment_action<multiply_action>, A, const B, reference_argument)
Chris@16 131 BOOST_LAMBDA_BE(operator/=, arithmetic_assignment_action<divide_action>, A, const B, reference_argument)
Chris@16 132 BOOST_LAMBDA_BE(operator%=, arithmetic_assignment_action<remainder_action>, A, const B, reference_argument)
Chris@16 133 BOOST_LAMBDA_BE(operator<<=, bitwise_assignment_action<leftshift_action>, A, const B, reference_argument)
Chris@16 134 BOOST_LAMBDA_BE(operator>>=, bitwise_assignment_action<rightshift_action>, A, const B, reference_argument)
Chris@16 135 BOOST_LAMBDA_BE(operator&=, bitwise_assignment_action<and_action>, A, const B, reference_argument)
Chris@16 136 BOOST_LAMBDA_BE(operator|=, bitwise_assignment_action<or_action>, A, const B, reference_argument)
Chris@16 137 BOOST_LAMBDA_BE(operator^=, bitwise_assignment_action<xor_action>, A, const B, reference_argument)
Chris@16 138
Chris@16 139
Chris@16 140 // A special trick for comma operator for correct preprocessing
Chris@16 141 #if defined BOOST_LAMBDA_COMMA_OPERATOR_NAME
Chris@16 142 #error "Multiple defines of BOOST_LAMBDA_COMMA_OPERATOR_NAME"
Chris@16 143 #endif
Chris@16 144
Chris@16 145 #define BOOST_LAMBDA_COMMA_OPERATOR_NAME operator,
Chris@16 146
Chris@16 147 BOOST_LAMBDA_BE1(BOOST_LAMBDA_COMMA_OPERATOR_NAME, other_action<comma_action>, const A, const B, const_copy_argument)
Chris@16 148 BOOST_LAMBDA_BE2(BOOST_LAMBDA_COMMA_OPERATOR_NAME, other_action<comma_action>, const A, const B, const_copy_argument)
Chris@16 149 BOOST_LAMBDA_BE3(BOOST_LAMBDA_COMMA_OPERATOR_NAME, other_action<comma_action>, const A, const B, const_copy_argument)
Chris@16 150
Chris@16 151
Chris@16 152
Chris@16 153 namespace detail {
Chris@16 154
Chris@16 155 // special cases for ostream& << Any and istream& >> Any ---------------
Chris@16 156 // the actual stream classes may vary and thus a specialisation for,
Chris@16 157 // say ostream& does not match (the general case above is chosen).
Chris@16 158 // Therefore we specialise for non-const reference:
Chris@16 159 // if the left argument is a stream, we store the stream as reference
Chris@16 160 // if it is something else, we store a const plain by default
Chris@16 161
Chris@16 162 // Note that the overloading is const vs. non-const first argument
Chris@16 163
Chris@16 164 #ifdef BOOST_NO_TEMPLATED_STREAMS
Chris@16 165 template<class T> struct convert_ostream_to_ref_others_to_c_plain_by_default {
Chris@16 166 typedef typename detail::IF<
Chris@16 167 boost::is_convertible<T*, std::ostream*>::value,
Chris@16 168 T&,
Chris@16 169 typename const_copy_argument <T>::type
Chris@16 170 >::RET type;
Chris@16 171 };
Chris@16 172
Chris@16 173 template<class T> struct convert_istream_to_ref_others_to_c_plain_by_default {
Chris@16 174 typedef typename detail::IF<
Chris@16 175 boost::is_convertible<T*, std::istream*>::value,
Chris@16 176 T&,
Chris@16 177 typename const_copy_argument <T>::type
Chris@16 178 >::RET type;
Chris@16 179 };
Chris@16 180 #else
Chris@16 181
Chris@16 182 template<class T> struct convert_ostream_to_ref_others_to_c_plain_by_default {
Chris@16 183 typedef typename detail::IF<
Chris@16 184 is_instance_of_2<
Chris@16 185 T, std::basic_ostream
Chris@16 186 >::value,
Chris@16 187 T&,
Chris@16 188 typename const_copy_argument <T>::type
Chris@16 189 >::RET type;
Chris@16 190 };
Chris@16 191
Chris@16 192 template<class T> struct convert_istream_to_ref_others_to_c_plain_by_default {
Chris@16 193 typedef typename detail::IF<
Chris@16 194 is_instance_of_2<
Chris@16 195 T, std::basic_istream
Chris@16 196 >::value,
Chris@16 197 T&,
Chris@16 198 typename const_copy_argument <T>::type
Chris@16 199 >::RET type;
Chris@16 200 };
Chris@16 201 #endif
Chris@16 202
Chris@16 203 } // detail
Chris@16 204
Chris@16 205 BOOST_LAMBDA_BE2(operator<<, bitwise_action< leftshift_action>, A, const B, detail::convert_ostream_to_ref_others_to_c_plain_by_default)
Chris@16 206 BOOST_LAMBDA_BE2(operator>>, bitwise_action< rightshift_action>, A, const B, detail::convert_istream_to_ref_others_to_c_plain_by_default)
Chris@16 207
Chris@16 208
Chris@16 209 // special case for io_manipulators.
Chris@16 210 // function references cannot be given as arguments to lambda operator
Chris@16 211 // expressions in general. With << and >> the use of manipulators is
Chris@16 212 // so common, that specializations are provided to make them work.
Chris@16 213
Chris@16 214 template<class Arg, class Ret, class ManipArg>
Chris@16 215 inline const
Chris@16 216 lambda_functor<
Chris@16 217 lambda_functor_base<
Chris@16 218 bitwise_action<leftshift_action>,
Chris@16 219 tuple<lambda_functor<Arg>, Ret(&)(ManipArg)>
Chris@16 220 >
Chris@16 221 >
Chris@16 222 operator<<(const lambda_functor<Arg>& a, Ret(&b)(ManipArg))
Chris@16 223 {
Chris@16 224 return
Chris@16 225 lambda_functor_base<
Chris@16 226 bitwise_action<leftshift_action>,
Chris@16 227 tuple<lambda_functor<Arg>, Ret(&)(ManipArg)>
Chris@16 228 >
Chris@16 229 ( tuple<lambda_functor<Arg>, Ret(&)(ManipArg)>(a, b) );
Chris@16 230 }
Chris@16 231
Chris@16 232 template<class Arg, class Ret, class ManipArg>
Chris@16 233 inline const
Chris@16 234 lambda_functor<
Chris@16 235 lambda_functor_base<
Chris@16 236 bitwise_action<rightshift_action>,
Chris@16 237 tuple<lambda_functor<Arg>, Ret(&)(ManipArg)>
Chris@16 238 >
Chris@16 239 >
Chris@16 240 operator>>(const lambda_functor<Arg>& a, Ret(&b)(ManipArg))
Chris@16 241 {
Chris@16 242 return
Chris@16 243 lambda_functor_base<
Chris@16 244 bitwise_action<rightshift_action>,
Chris@16 245 tuple<lambda_functor<Arg>, Ret(&)(ManipArg)>
Chris@16 246 >
Chris@16 247 ( tuple<lambda_functor<Arg>, Ret(&)(ManipArg)>(a, b) );
Chris@16 248 }
Chris@16 249
Chris@16 250
Chris@16 251 // (+ and -) take their arguments as const references.
Chris@16 252 // This has consquences with pointer artihmetic
Chris@16 253 // E.g int a[]; ... *a = 1 works but not *(a+1) = 1.
Chris@16 254 // the result of a+1 would be const
Chris@16 255 // To make the latter work too,
Chris@16 256 // non-const arrays are taken as non-const and stored as non-const as well.
Chris@16 257 #if defined BOOST_LAMBDA_PTR_ARITHMETIC_E1
Chris@16 258 #error "Multiple defines of BOOST_LAMBDA_PTR_ARITHMETIC_E1"
Chris@16 259 #endif
Chris@16 260
Chris@16 261 #define BOOST_LAMBDA_PTR_ARITHMETIC_E1(OPER_NAME, ACTION, CONSTB) \
Chris@16 262 template<class Arg, int N, class B> \
Chris@16 263 inline const \
Chris@16 264 lambda_functor< \
Chris@16 265 lambda_functor_base<ACTION, tuple<lambda_functor<Arg>, CONSTB(&)[N]> > \
Chris@16 266 > \
Chris@16 267 OPER_NAME (const lambda_functor<Arg>& a, CONSTB(&b)[N]) \
Chris@16 268 { \
Chris@16 269 return \
Chris@16 270 lambda_functor_base<ACTION, tuple<lambda_functor<Arg>, CONSTB(&)[N]> > \
Chris@16 271 (tuple<lambda_functor<Arg>, CONSTB(&)[N]>(a, b)); \
Chris@16 272 }
Chris@16 273
Chris@16 274
Chris@16 275 #if defined BOOST_LAMBDA_PTR_ARITHMETIC_E2
Chris@16 276 #error "Multiple defines of BOOST_LAMBDA_PTR_ARITHMETIC_E2"
Chris@16 277 #endif
Chris@16 278
Chris@16 279 #define BOOST_LAMBDA_PTR_ARITHMETIC_E2(OPER_NAME, ACTION, CONSTA) \
Chris@16 280 template<int N, class A, class Arg> \
Chris@16 281 inline const \
Chris@16 282 lambda_functor< \
Chris@16 283 lambda_functor_base<ACTION, tuple<CONSTA(&)[N], lambda_functor<Arg> > > \
Chris@16 284 > \
Chris@16 285 OPER_NAME (CONSTA(&a)[N], const lambda_functor<Arg>& b) \
Chris@16 286 { \
Chris@16 287 return \
Chris@16 288 lambda_functor_base<ACTION, tuple<CONSTA(&)[N], lambda_functor<Arg> > > \
Chris@16 289 (tuple<CONSTA(&)[N], lambda_functor<Arg> >(a, b)); \
Chris@16 290 }
Chris@16 291
Chris@16 292
Chris@16 293 BOOST_LAMBDA_PTR_ARITHMETIC_E1(operator+, arithmetic_action<plus_action>, B)
Chris@16 294 BOOST_LAMBDA_PTR_ARITHMETIC_E2(operator+, arithmetic_action<plus_action>, A)
Chris@16 295 BOOST_LAMBDA_PTR_ARITHMETIC_E1(operator+, arithmetic_action<plus_action>,const B)
Chris@16 296 BOOST_LAMBDA_PTR_ARITHMETIC_E2(operator+, arithmetic_action<plus_action>,const A)
Chris@16 297
Chris@16 298
Chris@16 299 //BOOST_LAMBDA_PTR_ARITHMETIC_E1(operator-, arithmetic_action<minus_action>)
Chris@16 300 // This is not needed, since the result of ptr-ptr is an rvalue anyway
Chris@16 301
Chris@16 302 BOOST_LAMBDA_PTR_ARITHMETIC_E2(operator-, arithmetic_action<minus_action>, A)
Chris@16 303 BOOST_LAMBDA_PTR_ARITHMETIC_E2(operator-, arithmetic_action<minus_action>, const A)
Chris@16 304
Chris@16 305
Chris@16 306 #undef BOOST_LAMBDA_BE1
Chris@16 307 #undef BOOST_LAMBDA_BE2
Chris@16 308 #undef BOOST_LAMBDA_BE3
Chris@16 309 #undef BOOST_LAMBDA_BE
Chris@16 310 #undef BOOST_LAMBDA_COMMA_OPERATOR_NAME
Chris@16 311
Chris@16 312 #undef BOOST_LAMBDA_PTR_ARITHMETIC_E1
Chris@16 313 #undef BOOST_LAMBDA_PTR_ARITHMETIC_E2
Chris@16 314
Chris@16 315
Chris@16 316 // ---------------------------------------------------------------------
Chris@16 317 // unary operators -----------------------------------------------------
Chris@16 318 // ---------------------------------------------------------------------
Chris@16 319
Chris@16 320 #if defined BOOST_LAMBDA_UE
Chris@16 321 #error "Multiple defines of BOOST_LAMBDA_UE"
Chris@16 322 #endif
Chris@16 323
Chris@16 324 #define BOOST_LAMBDA_UE(OPER_NAME, ACTION) \
Chris@16 325 template<class Arg> \
Chris@16 326 inline const \
Chris@16 327 lambda_functor<lambda_functor_base<ACTION, tuple<lambda_functor<Arg> > > > \
Chris@16 328 OPER_NAME (const lambda_functor<Arg>& a) \
Chris@16 329 { \
Chris@16 330 return \
Chris@16 331 lambda_functor_base<ACTION, tuple<lambda_functor<Arg> > > \
Chris@16 332 ( tuple<lambda_functor<Arg> >(a) ); \
Chris@16 333 }
Chris@16 334
Chris@16 335
Chris@16 336 BOOST_LAMBDA_UE(operator+, unary_arithmetic_action<plus_action>)
Chris@16 337 BOOST_LAMBDA_UE(operator-, unary_arithmetic_action<minus_action>)
Chris@16 338 BOOST_LAMBDA_UE(operator~, bitwise_action<not_action>)
Chris@16 339 BOOST_LAMBDA_UE(operator!, logical_action<not_action>)
Chris@16 340 BOOST_LAMBDA_UE(operator++, pre_increment_decrement_action<increment_action>)
Chris@16 341 BOOST_LAMBDA_UE(operator--, pre_increment_decrement_action<decrement_action>)
Chris@16 342 BOOST_LAMBDA_UE(operator*, other_action<contentsof_action>)
Chris@16 343 BOOST_LAMBDA_UE(operator&, other_action<addressof_action>)
Chris@16 344
Chris@16 345 #if defined BOOST_LAMBDA_POSTFIX_UE
Chris@16 346 #error "Multiple defines of BOOST_LAMBDA_POSTFIX_UE"
Chris@16 347 #endif
Chris@16 348
Chris@16 349 #define BOOST_LAMBDA_POSTFIX_UE(OPER_NAME, ACTION) \
Chris@16 350 template<class Arg> \
Chris@16 351 inline const \
Chris@16 352 lambda_functor<lambda_functor_base<ACTION, tuple<lambda_functor<Arg> > > > \
Chris@16 353 OPER_NAME (const lambda_functor<Arg>& a, int) \
Chris@16 354 { \
Chris@16 355 return \
Chris@16 356 lambda_functor_base<ACTION, tuple<lambda_functor<Arg> > > \
Chris@16 357 ( tuple<lambda_functor<Arg> >(a) ); \
Chris@16 358 }
Chris@16 359
Chris@16 360
Chris@16 361 BOOST_LAMBDA_POSTFIX_UE(operator++, post_increment_decrement_action<increment_action>)
Chris@16 362 BOOST_LAMBDA_POSTFIX_UE(operator--, post_increment_decrement_action<decrement_action>)
Chris@16 363
Chris@16 364 #undef BOOST_LAMBDA_UE
Chris@16 365 #undef BOOST_LAMBDA_POSTFIX_UE
Chris@16 366
Chris@16 367 } // namespace lambda
Chris@16 368 } // namespace boost
Chris@16 369
Chris@16 370 #endif