Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===------------------------ functional ----------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_FUNCTIONAL |
| 12 | #define _LIBCPP_FUNCTIONAL |
| 13 | |
| 14 | /* |
| 15 | functional synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | template <class Arg, class Result> |
| 21 | struct unary_function |
| 22 | { |
| 23 | typedef Arg argument_type; |
| 24 | typedef Result result_type; |
| 25 | }; |
| 26 | |
| 27 | template <class Arg1, class Arg2, class Result> |
| 28 | struct binary_function |
| 29 | { |
| 30 | typedef Arg1 first_argument_type; |
| 31 | typedef Arg2 second_argument_type; |
| 32 | typedef Result result_type; |
| 33 | }; |
| 34 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 35 | template <class T> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 36 | class reference_wrapper |
| 37 | : public unary_function<T1, R> // if wrapping a unary functor |
| 38 | : public binary_function<T1, T2, R> // if wraping a binary functor |
| 39 | { |
| 40 | public: |
| 41 | // types |
| 42 | typedef T type; |
| 43 | typedef see below result_type; // Not always defined |
| 44 | |
| 45 | // construct/copy/destroy |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 46 | reference_wrapper(T&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 47 | reference_wrapper(T&&) = delete; // do not bind to temps |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 48 | reference_wrapper(const reference_wrapper<T>& x) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 49 | |
| 50 | // assignment |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 51 | reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 52 | |
| 53 | // access |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 54 | operator T& () const noexcept; |
| 55 | T& get() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 56 | |
| 57 | // invoke |
| 58 | template <class... ArgTypes> |
Howard Hinnant | 23e470c | 2013-09-21 17:58:58 +0000 | [diff] [blame] | 59 | typename result_of<T&(ArgTypes&&...)>::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 60 | operator() (ArgTypes&&...) const; |
| 61 | }; |
| 62 | |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 63 | template <class T> reference_wrapper<T> ref(T& t) noexcept; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 64 | template <class T> void ref(const T&& t) = delete; |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 65 | template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 66 | |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 67 | template <class T> reference_wrapper<const T> cref(const T& t) noexcept; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 68 | template <class T> void cref(const T&& t) = delete; |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 69 | template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 70 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 71 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 72 | struct plus : binary_function<T, T, T> |
| 73 | { |
| 74 | T operator()(const T& x, const T& y) const; |
| 75 | }; |
| 76 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 77 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 78 | struct minus : binary_function<T, T, T> |
| 79 | { |
| 80 | T operator()(const T& x, const T& y) const; |
| 81 | }; |
| 82 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 83 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 84 | struct multiplies : binary_function<T, T, T> |
| 85 | { |
| 86 | T operator()(const T& x, const T& y) const; |
| 87 | }; |
| 88 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 89 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 90 | struct divides : binary_function<T, T, T> |
| 91 | { |
| 92 | T operator()(const T& x, const T& y) const; |
| 93 | }; |
| 94 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 95 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 96 | struct modulus : binary_function<T, T, T> |
| 97 | { |
| 98 | T operator()(const T& x, const T& y) const; |
| 99 | }; |
| 100 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 101 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 102 | struct negate : unary_function<T, T> |
| 103 | { |
| 104 | T operator()(const T& x) const; |
| 105 | }; |
| 106 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 107 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 108 | struct equal_to : binary_function<T, T, bool> |
| 109 | { |
| 110 | bool operator()(const T& x, const T& y) const; |
| 111 | }; |
| 112 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 113 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 114 | struct not_equal_to : binary_function<T, T, bool> |
| 115 | { |
| 116 | bool operator()(const T& x, const T& y) const; |
| 117 | }; |
| 118 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 119 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 120 | struct greater : binary_function<T, T, bool> |
| 121 | { |
| 122 | bool operator()(const T& x, const T& y) const; |
| 123 | }; |
| 124 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 125 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 126 | struct less : binary_function<T, T, bool> |
| 127 | { |
| 128 | bool operator()(const T& x, const T& y) const; |
| 129 | }; |
| 130 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 131 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 132 | struct greater_equal : binary_function<T, T, bool> |
| 133 | { |
| 134 | bool operator()(const T& x, const T& y) const; |
| 135 | }; |
| 136 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 137 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 138 | struct less_equal : binary_function<T, T, bool> |
| 139 | { |
| 140 | bool operator()(const T& x, const T& y) const; |
| 141 | }; |
| 142 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 143 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 144 | struct logical_and : binary_function<T, T, bool> |
| 145 | { |
| 146 | bool operator()(const T& x, const T& y) const; |
| 147 | }; |
| 148 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 149 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 150 | struct logical_or : binary_function<T, T, bool> |
| 151 | { |
| 152 | bool operator()(const T& x, const T& y) const; |
| 153 | }; |
| 154 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 155 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 156 | struct logical_not : unary_function<T, bool> |
| 157 | { |
| 158 | bool operator()(const T& x) const; |
| 159 | }; |
| 160 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 161 | template <class T> // <class T=void> in C++14 |
| 162 | struct bit_and : unary_function<T, bool> |
| 163 | { |
| 164 | bool operator()(const T& x, const T& y) const; |
| 165 | }; |
| 166 | |
| 167 | template <class T> // <class T=void> in C++14 |
| 168 | struct bit_or : unary_function<T, bool> |
| 169 | { |
| 170 | bool operator()(const T& x, const T& y) const; |
| 171 | }; |
| 172 | |
| 173 | template <class T> // <class T=void> in C++14 |
| 174 | struct bit_xor : unary_function<T, bool> |
| 175 | { |
| 176 | bool operator()(const T& x, const T& y) const; |
| 177 | }; |
| 178 | |
| 179 | template <class T=void> // C++14 |
| 180 | struct bit_xor : unary_function<T, bool> |
| 181 | { |
| 182 | bool operator()(const T& x) const; |
| 183 | }; |
| 184 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 185 | template <class Predicate> |
| 186 | class unary_negate |
| 187 | : public unary_function<typename Predicate::argument_type, bool> |
| 188 | { |
| 189 | public: |
| 190 | explicit unary_negate(const Predicate& pred); |
| 191 | bool operator()(const typename Predicate::argument_type& x) const; |
| 192 | }; |
| 193 | |
| 194 | template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred); |
| 195 | |
| 196 | template <class Predicate> |
| 197 | class binary_negate |
| 198 | : public binary_function<typename Predicate::first_argument_type, |
| 199 | typename Predicate::second_argument_type, |
| 200 | bool> |
| 201 | { |
| 202 | public: |
| 203 | explicit binary_negate(const Predicate& pred); |
| 204 | bool operator()(const typename Predicate::first_argument_type& x, |
| 205 | const typename Predicate::second_argument_type& y) const; |
| 206 | }; |
| 207 | |
| 208 | template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred); |
| 209 | |
| 210 | template<class T> struct is_bind_expression; |
| 211 | template<class T> struct is_placeholder; |
| 212 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 213 | template<class Fn, class... BoundArgs> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 214 | unspecified bind(Fn&&, BoundArgs&&...); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 215 | template<class R, class Fn, class... BoundArgs> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 216 | unspecified bind(Fn&&, BoundArgs&&...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 217 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 218 | namespace placeholders { |
| 219 | // M is the implementation-defined number of placeholders |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 220 | extern unspecified _1; |
| 221 | extern unspecified _2; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 222 | . |
| 223 | . |
| 224 | . |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 225 | extern unspecified _Mp; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | template <class Operation> |
| 229 | class binder1st |
| 230 | : public unary_function<typename Operation::second_argument_type, |
| 231 | typename Operation::result_type> |
| 232 | { |
| 233 | protected: |
| 234 | Operation op; |
| 235 | typename Operation::first_argument_type value; |
| 236 | public: |
| 237 | binder1st(const Operation& x, const typename Operation::first_argument_type y); |
| 238 | typename Operation::result_type operator()( typename Operation::second_argument_type& x) const; |
| 239 | typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const; |
| 240 | }; |
| 241 | |
| 242 | template <class Operation, class T> |
| 243 | binder1st<Operation> bind1st(const Operation& op, const T& x); |
| 244 | |
| 245 | template <class Operation> |
| 246 | class binder2nd |
| 247 | : public unary_function<typename Operation::first_argument_type, |
| 248 | typename Operation::result_type> |
| 249 | { |
| 250 | protected: |
| 251 | Operation op; |
| 252 | typename Operation::second_argument_type value; |
| 253 | public: |
| 254 | binder2nd(const Operation& x, const typename Operation::second_argument_type y); |
| 255 | typename Operation::result_type operator()( typename Operation::first_argument_type& x) const; |
| 256 | typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const; |
| 257 | }; |
| 258 | |
| 259 | template <class Operation, class T> |
| 260 | binder2nd<Operation> bind2nd(const Operation& op, const T& x); |
| 261 | |
| 262 | template <class Arg, class Result> |
| 263 | class pointer_to_unary_function : public unary_function<Arg, Result> |
| 264 | { |
| 265 | public: |
| 266 | explicit pointer_to_unary_function(Result (*f)(Arg)); |
| 267 | Result operator()(Arg x) const; |
| 268 | }; |
| 269 | |
| 270 | template <class Arg, class Result> |
| 271 | pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); |
| 272 | |
| 273 | template <class Arg1, class Arg2, class Result> |
| 274 | class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> |
| 275 | { |
| 276 | public: |
| 277 | explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); |
| 278 | Result operator()(Arg1 x, Arg2 y) const; |
| 279 | }; |
| 280 | |
| 281 | template <class Arg1, class Arg2, class Result> |
| 282 | pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); |
| 283 | |
| 284 | template<class S, class T> |
| 285 | class mem_fun_t : public unary_function<T*, S> |
| 286 | { |
| 287 | public: |
| 288 | explicit mem_fun_t(S (T::*p)()); |
| 289 | S operator()(T* p) const; |
| 290 | }; |
| 291 | |
| 292 | template<class S, class T, class A> |
| 293 | class mem_fun1_t : public binary_function<T*, A, S> |
| 294 | { |
| 295 | public: |
| 296 | explicit mem_fun1_t(S (T::*p)(A)); |
| 297 | S operator()(T* p, A x) const; |
| 298 | }; |
| 299 | |
| 300 | template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); |
| 301 | template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); |
| 302 | |
| 303 | template<class S, class T> |
| 304 | class mem_fun_ref_t : public unary_function<T, S> |
| 305 | { |
| 306 | public: |
| 307 | explicit mem_fun_ref_t(S (T::*p)()); |
| 308 | S operator()(T& p) const; |
| 309 | }; |
| 310 | |
| 311 | template<class S, class T, class A> |
| 312 | class mem_fun1_ref_t : public binary_function<T, A, S> |
| 313 | { |
| 314 | public: |
| 315 | explicit mem_fun1_ref_t(S (T::*p)(A)); |
| 316 | S operator()(T& p, A x) const; |
| 317 | }; |
| 318 | |
| 319 | template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); |
| 320 | template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); |
| 321 | |
| 322 | template <class S, class T> |
| 323 | class const_mem_fun_t : public unary_function<const T*, S> |
| 324 | { |
| 325 | public: |
| 326 | explicit const_mem_fun_t(S (T::*p)() const); |
| 327 | S operator()(const T* p) const; |
| 328 | }; |
| 329 | |
| 330 | template <class S, class T, class A> |
| 331 | class const_mem_fun1_t : public binary_function<const T*, A, S> |
| 332 | { |
| 333 | public: |
| 334 | explicit const_mem_fun1_t(S (T::*p)(A) const); |
| 335 | S operator()(const T* p, A x) const; |
| 336 | }; |
| 337 | |
| 338 | template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); |
| 339 | template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); |
| 340 | |
| 341 | template <class S, class T> |
| 342 | class const_mem_fun_ref_t : public unary_function<T, S> |
| 343 | { |
| 344 | public: |
| 345 | explicit const_mem_fun_ref_t(S (T::*p)() const); |
| 346 | S operator()(const T& p) const; |
| 347 | }; |
| 348 | |
| 349 | template <class S, class T, class A> |
| 350 | class const_mem_fun1_ref_t : public binary_function<T, A, S> |
| 351 | { |
| 352 | public: |
| 353 | explicit const_mem_fun1_ref_t(S (T::*p)(A) const); |
| 354 | S operator()(const T& p, A x) const; |
| 355 | }; |
| 356 | |
| 357 | template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); |
| 358 | template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); |
| 359 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 360 | template<class R, class T> unspecified mem_fn(R T::*); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 361 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 362 | class bad_function_call |
| 363 | : public exception |
| 364 | { |
| 365 | }; |
| 366 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 367 | template<class> class function; // undefined |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 368 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 369 | template<class R, class... ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 370 | class function<R(ArgTypes...)> |
| 371 | : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and |
| 372 | // ArgTypes contains T1 |
| 373 | : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and |
| 374 | // ArgTypes contains T1 and T2 |
| 375 | { |
| 376 | public: |
| 377 | typedef R result_type; |
| 378 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 379 | // construct/copy/destroy: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 380 | function() noexcept; |
| 381 | function(nullptr_t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 382 | function(const function&); |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 383 | function(function&&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 384 | template<class F> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 385 | function(F); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 386 | template<Allocator Alloc> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 387 | function(allocator_arg_t, const Alloc&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 388 | template<Allocator Alloc> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 389 | function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 390 | template<Allocator Alloc> |
| 391 | function(allocator_arg_t, const Alloc&, const function&); |
| 392 | template<Allocator Alloc> |
| 393 | function(allocator_arg_t, const Alloc&, function&&); |
| 394 | template<class F, Allocator Alloc> |
| 395 | function(allocator_arg_t, const Alloc&, F); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 396 | |
| 397 | function& operator=(const function&); |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 398 | function& operator=(function&&) noexcept; |
Howard Hinnant | ad1a5cc | 2011-05-29 13:53:56 +0000 | [diff] [blame] | 399 | function& operator=(nullptr_t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 400 | template<class F> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 401 | function& operator=(F&&); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 402 | template<class F> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 403 | function& operator=(reference_wrapper<F>) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 404 | |
| 405 | ~function(); |
| 406 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 407 | // function modifiers: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 408 | void swap(function&) noexcept; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 409 | template<class F, class Alloc> |
| 410 | void assign(F&&, const Alloc&); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 411 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 412 | // function capacity: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 413 | explicit operator bool() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 414 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 415 | // function invocation: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 416 | R operator()(ArgTypes...) const; |
| 417 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 418 | // function target access: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 419 | const std::type_info& target_type() const noexcept; |
| 420 | template <typename T> T* target() noexcept; |
| 421 | template <typename T> const T* target() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 422 | }; |
| 423 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 424 | // Null pointer comparisons: |
| 425 | template <class R, class ... ArgTypes> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 426 | bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 427 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 428 | template <class R, class ... ArgTypes> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 429 | bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 430 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 431 | template <class R, class ... ArgTypes> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 432 | bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 433 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 434 | template <class R, class ... ArgTypes> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 435 | bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 436 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 437 | // specialized algorithms: |
| 438 | template <class R, class ... ArgTypes> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 439 | void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 440 | |
| 441 | template <class T> struct hash; |
| 442 | |
| 443 | template <> struct hash<bool>; |
| 444 | template <> struct hash<char>; |
| 445 | template <> struct hash<signed char>; |
| 446 | template <> struct hash<unsigned char>; |
| 447 | template <> struct hash<char16_t>; |
| 448 | template <> struct hash<char32_t>; |
| 449 | template <> struct hash<wchar_t>; |
| 450 | template <> struct hash<short>; |
| 451 | template <> struct hash<unsigned short>; |
| 452 | template <> struct hash<int>; |
| 453 | template <> struct hash<unsigned int>; |
| 454 | template <> struct hash<long>; |
| 455 | template <> struct hash<long long>; |
| 456 | template <> struct hash<unsigned long>; |
| 457 | template <> struct hash<unsigned long long>; |
| 458 | |
| 459 | template <> struct hash<float>; |
| 460 | template <> struct hash<double>; |
| 461 | template <> struct hash<long double>; |
| 462 | |
| 463 | template<class T> struct hash<T*>; |
| 464 | |
| 465 | } // std |
| 466 | |
| 467 | POLICY: For non-variadic implementations, the number of arguments is limited |
| 468 | to 3. It is hoped that the need for non-variadic implementations |
| 469 | will be minimal. |
| 470 | |
| 471 | */ |
| 472 | |
| 473 | #include <__config> |
| 474 | #include <type_traits> |
| 475 | #include <typeinfo> |
| 476 | #include <exception> |
| 477 | #include <memory> |
| 478 | #include <tuple> |
| 479 | |
| 480 | #include <__functional_base> |
| 481 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 482 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 483 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 484 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 485 | |
| 486 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 487 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 488 | #if _LIBCPP_STD_VER > 11 |
| 489 | template <class _Tp = void> |
| 490 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 491 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 492 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 493 | struct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 494 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 495 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 496 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 497 | {return __x + __y;} |
| 498 | }; |
| 499 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 500 | #if _LIBCPP_STD_VER > 11 |
| 501 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 502 | struct _LIBCPP_TYPE_VIS_ONLY plus<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 503 | { |
| 504 | template <class _T1, class _T2> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 505 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 506 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 507 | { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 508 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 509 | }; |
| 510 | #endif |
| 511 | |
| 512 | |
| 513 | #if _LIBCPP_STD_VER > 11 |
| 514 | template <class _Tp = void> |
| 515 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 516 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 517 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 518 | struct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 519 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 520 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 521 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 522 | {return __x - __y;} |
| 523 | }; |
| 524 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 525 | #if _LIBCPP_STD_VER > 11 |
| 526 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 527 | struct _LIBCPP_TYPE_VIS_ONLY minus<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 528 | { |
| 529 | template <class _T1, class _T2> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 530 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 531 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 532 | { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 533 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 534 | }; |
| 535 | #endif |
| 536 | |
| 537 | |
| 538 | #if _LIBCPP_STD_VER > 11 |
| 539 | template <class _Tp = void> |
| 540 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 541 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 542 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 543 | struct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 544 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 545 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 546 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 547 | {return __x * __y;} |
| 548 | }; |
| 549 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 550 | #if _LIBCPP_STD_VER > 11 |
| 551 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 552 | struct _LIBCPP_TYPE_VIS_ONLY multiplies<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 553 | { |
| 554 | template <class _T1, class _T2> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 555 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 556 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 557 | { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 558 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 559 | }; |
| 560 | #endif |
| 561 | |
| 562 | |
| 563 | #if _LIBCPP_STD_VER > 11 |
| 564 | template <class _Tp = void> |
| 565 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 566 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 567 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 568 | struct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 569 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 570 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 571 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 572 | {return __x / __y;} |
| 573 | }; |
| 574 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 575 | #if _LIBCPP_STD_VER > 11 |
| 576 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 577 | struct _LIBCPP_TYPE_VIS_ONLY divides<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 578 | { |
| 579 | template <class _T1, class _T2> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 580 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 581 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 582 | { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 583 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 584 | }; |
| 585 | #endif |
| 586 | |
| 587 | |
| 588 | #if _LIBCPP_STD_VER > 11 |
| 589 | template <class _Tp = void> |
| 590 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 591 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 592 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 593 | struct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 594 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 595 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 596 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 597 | {return __x % __y;} |
| 598 | }; |
| 599 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 600 | #if _LIBCPP_STD_VER > 11 |
| 601 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 602 | struct _LIBCPP_TYPE_VIS_ONLY modulus<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 603 | { |
| 604 | template <class _T1, class _T2> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 605 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 606 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 607 | { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 608 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 609 | }; |
| 610 | #endif |
| 611 | |
| 612 | |
| 613 | #if _LIBCPP_STD_VER > 11 |
| 614 | template <class _Tp = void> |
| 615 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 616 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 617 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 618 | struct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 619 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 620 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 621 | _Tp operator()(const _Tp& __x) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 622 | {return -__x;} |
| 623 | }; |
| 624 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 625 | #if _LIBCPP_STD_VER > 11 |
| 626 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 627 | struct _LIBCPP_TYPE_VIS_ONLY negate<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 628 | { |
| 629 | template <class _Tp> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 630 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 631 | auto operator()(_Tp&& __x) const |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 632 | { return -_VSTD::forward<_Tp>(__x); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 633 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 634 | }; |
| 635 | #endif |
| 636 | |
| 637 | |
| 638 | #if _LIBCPP_STD_VER > 11 |
| 639 | template <class _Tp = void> |
| 640 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 641 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 642 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 643 | struct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 644 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 645 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 646 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 647 | {return __x == __y;} |
| 648 | }; |
| 649 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 650 | #if _LIBCPP_STD_VER > 11 |
| 651 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 652 | struct _LIBCPP_TYPE_VIS_ONLY equal_to<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 653 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 654 | template <class _T1, class _T2> |
| 655 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 656 | auto operator()(_T1&& __t, _T2&& __u) const |
| 657 | { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 658 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 659 | }; |
| 660 | #endif |
| 661 | |
| 662 | |
| 663 | #if _LIBCPP_STD_VER > 11 |
| 664 | template <class _Tp = void> |
| 665 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 666 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 667 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 668 | struct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 669 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 670 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 671 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 672 | {return __x != __y;} |
| 673 | }; |
| 674 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 675 | #if _LIBCPP_STD_VER > 11 |
| 676 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 677 | struct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 678 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 679 | template <class _T1, class _T2> |
| 680 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 681 | auto operator()(_T1&& __t, _T2&& __u) const |
| 682 | { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 683 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 684 | }; |
| 685 | #endif |
| 686 | |
| 687 | |
| 688 | #if _LIBCPP_STD_VER > 11 |
| 689 | template <class _Tp = void> |
| 690 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 691 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 692 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 693 | struct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 694 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 695 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 696 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 697 | {return __x > __y;} |
| 698 | }; |
| 699 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 700 | #if _LIBCPP_STD_VER > 11 |
| 701 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 702 | struct _LIBCPP_TYPE_VIS_ONLY greater<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 703 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 704 | template <class _T1, class _T2> |
| 705 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 706 | auto operator()(_T1&& __t, _T2&& __u) const |
| 707 | { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 708 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 709 | }; |
| 710 | #endif |
| 711 | |
| 712 | |
Howard Hinnant | 3fadda3 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 713 | // less in <__functional_base> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 714 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 715 | #if _LIBCPP_STD_VER > 11 |
| 716 | template <class _Tp = void> |
| 717 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 718 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 719 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 720 | struct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 721 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 722 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 723 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 724 | {return __x >= __y;} |
| 725 | }; |
| 726 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 727 | #if _LIBCPP_STD_VER > 11 |
| 728 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 729 | struct _LIBCPP_TYPE_VIS_ONLY greater_equal<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 730 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 731 | template <class _T1, class _T2> |
| 732 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 733 | auto operator()(_T1&& __t, _T2&& __u) const |
| 734 | { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 735 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 736 | }; |
| 737 | #endif |
| 738 | |
| 739 | |
| 740 | #if _LIBCPP_STD_VER > 11 |
| 741 | template <class _Tp = void> |
| 742 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 743 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 744 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 745 | struct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 746 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 747 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 748 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 749 | {return __x <= __y;} |
| 750 | }; |
| 751 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 752 | #if _LIBCPP_STD_VER > 11 |
| 753 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 754 | struct _LIBCPP_TYPE_VIS_ONLY less_equal<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 755 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 756 | template <class _T1, class _T2> |
| 757 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 758 | auto operator()(_T1&& __t, _T2&& __u) const |
| 759 | { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 760 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 761 | }; |
| 762 | #endif |
| 763 | |
| 764 | |
| 765 | #if _LIBCPP_STD_VER > 11 |
| 766 | template <class _Tp = void> |
| 767 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 768 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 769 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 770 | struct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 771 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 772 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 773 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 774 | {return __x && __y;} |
| 775 | }; |
| 776 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 777 | #if _LIBCPP_STD_VER > 11 |
| 778 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 779 | struct _LIBCPP_TYPE_VIS_ONLY logical_and<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 780 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 781 | template <class _T1, class _T2> |
| 782 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 783 | auto operator()(_T1&& __t, _T2&& __u) const |
| 784 | { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 785 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 786 | }; |
| 787 | #endif |
| 788 | |
| 789 | |
| 790 | #if _LIBCPP_STD_VER > 11 |
| 791 | template <class _Tp = void> |
| 792 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 793 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 794 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 795 | struct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 796 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 797 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 798 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 799 | {return __x || __y;} |
| 800 | }; |
| 801 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 802 | #if _LIBCPP_STD_VER > 11 |
| 803 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 804 | struct _LIBCPP_TYPE_VIS_ONLY logical_or<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 805 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 806 | template <class _T1, class _T2> |
| 807 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 808 | auto operator()(_T1&& __t, _T2&& __u) const |
| 809 | { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 810 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 811 | }; |
| 812 | #endif |
| 813 | |
| 814 | |
| 815 | #if _LIBCPP_STD_VER > 11 |
| 816 | template <class _Tp = void> |
| 817 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 818 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 819 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 820 | struct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 821 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 822 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 823 | bool operator()(const _Tp& __x) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 824 | {return !__x;} |
| 825 | }; |
| 826 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 827 | #if _LIBCPP_STD_VER > 11 |
| 828 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 829 | struct _LIBCPP_TYPE_VIS_ONLY logical_not<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 830 | { |
| 831 | template <class _Tp> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 832 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 833 | auto operator()(_Tp&& __x) const |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 834 | { return !_VSTD::forward<_Tp>(__x); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 835 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 836 | }; |
| 837 | #endif |
| 838 | |
| 839 | |
| 840 | #if _LIBCPP_STD_VER > 11 |
| 841 | template <class _Tp = void> |
| 842 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 843 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 844 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 845 | struct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 846 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 847 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 848 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 849 | {return __x & __y;} |
| 850 | }; |
| 851 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 852 | #if _LIBCPP_STD_VER > 11 |
| 853 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 854 | struct _LIBCPP_TYPE_VIS_ONLY bit_and<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 855 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 856 | template <class _T1, class _T2> |
| 857 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 858 | auto operator()(_T1&& __t, _T2&& __u) const |
| 859 | { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 860 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 861 | }; |
| 862 | #endif |
| 863 | |
| 864 | |
| 865 | #if _LIBCPP_STD_VER > 11 |
| 866 | template <class _Tp = void> |
| 867 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 868 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 869 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 870 | struct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 871 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 872 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 873 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 874 | {return __x | __y;} |
| 875 | }; |
| 876 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 877 | #if _LIBCPP_STD_VER > 11 |
| 878 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 879 | struct _LIBCPP_TYPE_VIS_ONLY bit_or<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 880 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 881 | template <class _T1, class _T2> |
| 882 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 883 | auto operator()(_T1&& __t, _T2&& __u) const |
| 884 | { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 885 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 886 | }; |
| 887 | #endif |
| 888 | |
| 889 | |
| 890 | #if _LIBCPP_STD_VER > 11 |
| 891 | template <class _Tp = void> |
| 892 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 893 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 894 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 895 | struct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 896 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 897 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 898 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 899 | {return __x ^ __y;} |
| 900 | }; |
| 901 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 902 | #if _LIBCPP_STD_VER > 11 |
| 903 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 904 | struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 905 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 906 | template <class _T1, class _T2> |
| 907 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 908 | auto operator()(_T1&& __t, _T2&& __u) const |
| 909 | { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 910 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 911 | }; |
| 912 | #endif |
| 913 | |
| 914 | |
| 915 | #if _LIBCPP_STD_VER > 11 |
| 916 | template <class _Tp = void> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 917 | struct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 918 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 919 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 920 | _Tp operator()(const _Tp& __x) const |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 921 | {return ~__x;} |
| 922 | }; |
| 923 | |
| 924 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 925 | struct _LIBCPP_TYPE_VIS_ONLY bit_not<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 926 | { |
| 927 | template <class _Tp> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 928 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 929 | auto operator()(_Tp&& __x) const |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 930 | { return ~_VSTD::forward<_Tp>(__x); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 931 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 932 | }; |
| 933 | #endif |
| 934 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 935 | template <class _Predicate> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 936 | class _LIBCPP_TYPE_VIS_ONLY unary_negate |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 937 | : public unary_function<typename _Predicate::argument_type, bool> |
| 938 | { |
| 939 | _Predicate __pred_; |
| 940 | public: |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 941 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 942 | explicit unary_negate(const _Predicate& __pred) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 943 | : __pred_(__pred) {} |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 944 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 945 | bool operator()(const typename _Predicate::argument_type& __x) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 946 | {return !__pred_(__x);} |
| 947 | }; |
| 948 | |
| 949 | template <class _Predicate> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 950 | inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 951 | unary_negate<_Predicate> |
| 952 | not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} |
| 953 | |
| 954 | template <class _Predicate> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 955 | class _LIBCPP_TYPE_VIS_ONLY binary_negate |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 956 | : public binary_function<typename _Predicate::first_argument_type, |
| 957 | typename _Predicate::second_argument_type, |
| 958 | bool> |
| 959 | { |
| 960 | _Predicate __pred_; |
| 961 | public: |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 962 | _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 963 | binary_negate(const _Predicate& __pred) : __pred_(__pred) {} |
| 964 | |
| 965 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 966 | bool operator()(const typename _Predicate::first_argument_type& __x, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 967 | const typename _Predicate::second_argument_type& __y) const |
| 968 | {return !__pred_(__x, __y);} |
| 969 | }; |
| 970 | |
| 971 | template <class _Predicate> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 972 | inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 973 | binary_negate<_Predicate> |
| 974 | not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} |
| 975 | |
| 976 | template <class __Operation> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 977 | class _LIBCPP_TYPE_VIS_ONLY binder1st |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 978 | : public unary_function<typename __Operation::second_argument_type, |
| 979 | typename __Operation::result_type> |
| 980 | { |
| 981 | protected: |
| 982 | __Operation op; |
| 983 | typename __Operation::first_argument_type value; |
| 984 | public: |
| 985 | _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x, |
| 986 | const typename __Operation::first_argument_type __y) |
| 987 | : op(__x), value(__y) {} |
| 988 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 989 | (typename __Operation::second_argument_type& __x) const |
| 990 | {return op(value, __x);} |
| 991 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 992 | (const typename __Operation::second_argument_type& __x) const |
| 993 | {return op(value, __x);} |
| 994 | }; |
| 995 | |
| 996 | template <class __Operation, class _Tp> |
| 997 | inline _LIBCPP_INLINE_VISIBILITY |
| 998 | binder1st<__Operation> |
| 999 | bind1st(const __Operation& __op, const _Tp& __x) |
| 1000 | {return binder1st<__Operation>(__op, __x);} |
| 1001 | |
| 1002 | template <class __Operation> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1003 | class _LIBCPP_TYPE_VIS_ONLY binder2nd |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1004 | : public unary_function<typename __Operation::first_argument_type, |
| 1005 | typename __Operation::result_type> |
| 1006 | { |
| 1007 | protected: |
| 1008 | __Operation op; |
| 1009 | typename __Operation::second_argument_type value; |
| 1010 | public: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1011 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1012 | binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) |
| 1013 | : op(__x), value(__y) {} |
| 1014 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 1015 | ( typename __Operation::first_argument_type& __x) const |
| 1016 | {return op(__x, value);} |
| 1017 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 1018 | (const typename __Operation::first_argument_type& __x) const |
| 1019 | {return op(__x, value);} |
| 1020 | }; |
| 1021 | |
| 1022 | template <class __Operation, class _Tp> |
| 1023 | inline _LIBCPP_INLINE_VISIBILITY |
| 1024 | binder2nd<__Operation> |
| 1025 | bind2nd(const __Operation& __op, const _Tp& __x) |
| 1026 | {return binder2nd<__Operation>(__op, __x);} |
| 1027 | |
| 1028 | template <class _Arg, class _Result> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1029 | class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1030 | : public unary_function<_Arg, _Result> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1031 | { |
| 1032 | _Result (*__f_)(_Arg); |
| 1033 | public: |
| 1034 | _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) |
| 1035 | : __f_(__f) {} |
| 1036 | _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const |
| 1037 | {return __f_(__x);} |
| 1038 | }; |
| 1039 | |
| 1040 | template <class _Arg, class _Result> |
| 1041 | inline _LIBCPP_INLINE_VISIBILITY |
| 1042 | pointer_to_unary_function<_Arg,_Result> |
| 1043 | ptr_fun(_Result (*__f)(_Arg)) |
| 1044 | {return pointer_to_unary_function<_Arg,_Result>(__f);} |
| 1045 | |
| 1046 | template <class _Arg1, class _Arg2, class _Result> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1047 | class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1048 | : public binary_function<_Arg1, _Arg2, _Result> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1049 | { |
| 1050 | _Result (*__f_)(_Arg1, _Arg2); |
| 1051 | public: |
| 1052 | _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) |
| 1053 | : __f_(__f) {} |
| 1054 | _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const |
| 1055 | {return __f_(__x, __y);} |
| 1056 | }; |
| 1057 | |
| 1058 | template <class _Arg1, class _Arg2, class _Result> |
| 1059 | inline _LIBCPP_INLINE_VISIBILITY |
| 1060 | pointer_to_binary_function<_Arg1,_Arg2,_Result> |
| 1061 | ptr_fun(_Result (*__f)(_Arg1,_Arg2)) |
| 1062 | {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} |
| 1063 | |
| 1064 | template<class _Sp, class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1065 | class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1066 | { |
| 1067 | _Sp (_Tp::*__p_)(); |
| 1068 | public: |
| 1069 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) |
| 1070 | : __p_(__p) {} |
| 1071 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const |
| 1072 | {return (__p->*__p_)();} |
| 1073 | }; |
| 1074 | |
| 1075 | template<class _Sp, class _Tp, class _Ap> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1076 | class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1077 | { |
| 1078 | _Sp (_Tp::*__p_)(_Ap); |
| 1079 | public: |
| 1080 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) |
| 1081 | : __p_(__p) {} |
| 1082 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const |
| 1083 | {return (__p->*__p_)(__x);} |
| 1084 | }; |
| 1085 | |
| 1086 | template<class _Sp, class _Tp> |
| 1087 | inline _LIBCPP_INLINE_VISIBILITY |
| 1088 | mem_fun_t<_Sp,_Tp> |
| 1089 | mem_fun(_Sp (_Tp::*__f)()) |
| 1090 | {return mem_fun_t<_Sp,_Tp>(__f);} |
| 1091 | |
| 1092 | template<class _Sp, class _Tp, class _Ap> |
| 1093 | inline _LIBCPP_INLINE_VISIBILITY |
| 1094 | mem_fun1_t<_Sp,_Tp,_Ap> |
| 1095 | mem_fun(_Sp (_Tp::*__f)(_Ap)) |
| 1096 | {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} |
| 1097 | |
| 1098 | template<class _Sp, class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1099 | class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1100 | { |
| 1101 | _Sp (_Tp::*__p_)(); |
| 1102 | public: |
| 1103 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) |
| 1104 | : __p_(__p) {} |
| 1105 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const |
| 1106 | {return (__p.*__p_)();} |
| 1107 | }; |
| 1108 | |
| 1109 | template<class _Sp, class _Tp, class _Ap> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1110 | class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1111 | { |
| 1112 | _Sp (_Tp::*__p_)(_Ap); |
| 1113 | public: |
| 1114 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) |
| 1115 | : __p_(__p) {} |
| 1116 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const |
| 1117 | {return (__p.*__p_)(__x);} |
| 1118 | }; |
| 1119 | |
| 1120 | template<class _Sp, class _Tp> |
| 1121 | inline _LIBCPP_INLINE_VISIBILITY |
| 1122 | mem_fun_ref_t<_Sp,_Tp> |
| 1123 | mem_fun_ref(_Sp (_Tp::*__f)()) |
| 1124 | {return mem_fun_ref_t<_Sp,_Tp>(__f);} |
| 1125 | |
| 1126 | template<class _Sp, class _Tp, class _Ap> |
| 1127 | inline _LIBCPP_INLINE_VISIBILITY |
| 1128 | mem_fun1_ref_t<_Sp,_Tp,_Ap> |
| 1129 | mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) |
| 1130 | {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} |
| 1131 | |
| 1132 | template <class _Sp, class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1133 | class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1134 | { |
| 1135 | _Sp (_Tp::*__p_)() const; |
| 1136 | public: |
| 1137 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) |
| 1138 | : __p_(__p) {} |
| 1139 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const |
| 1140 | {return (__p->*__p_)();} |
| 1141 | }; |
| 1142 | |
| 1143 | template <class _Sp, class _Tp, class _Ap> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1144 | class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1145 | { |
| 1146 | _Sp (_Tp::*__p_)(_Ap) const; |
| 1147 | public: |
| 1148 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) |
| 1149 | : __p_(__p) {} |
| 1150 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const |
| 1151 | {return (__p->*__p_)(__x);} |
| 1152 | }; |
| 1153 | |
| 1154 | template <class _Sp, class _Tp> |
| 1155 | inline _LIBCPP_INLINE_VISIBILITY |
| 1156 | const_mem_fun_t<_Sp,_Tp> |
| 1157 | mem_fun(_Sp (_Tp::*__f)() const) |
| 1158 | {return const_mem_fun_t<_Sp,_Tp>(__f);} |
| 1159 | |
| 1160 | template <class _Sp, class _Tp, class _Ap> |
| 1161 | inline _LIBCPP_INLINE_VISIBILITY |
| 1162 | const_mem_fun1_t<_Sp,_Tp,_Ap> |
| 1163 | mem_fun(_Sp (_Tp::*__f)(_Ap) const) |
| 1164 | {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} |
| 1165 | |
| 1166 | template <class _Sp, class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1167 | class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1168 | { |
| 1169 | _Sp (_Tp::*__p_)() const; |
| 1170 | public: |
| 1171 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) |
| 1172 | : __p_(__p) {} |
| 1173 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const |
| 1174 | {return (__p.*__p_)();} |
| 1175 | }; |
| 1176 | |
| 1177 | template <class _Sp, class _Tp, class _Ap> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1178 | class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1179 | : public binary_function<_Tp, _Ap, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1180 | { |
| 1181 | _Sp (_Tp::*__p_)(_Ap) const; |
| 1182 | public: |
| 1183 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) |
| 1184 | : __p_(__p) {} |
| 1185 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const |
| 1186 | {return (__p.*__p_)(__x);} |
| 1187 | }; |
| 1188 | |
| 1189 | template <class _Sp, class _Tp> |
| 1190 | inline _LIBCPP_INLINE_VISIBILITY |
| 1191 | const_mem_fun_ref_t<_Sp,_Tp> |
| 1192 | mem_fun_ref(_Sp (_Tp::*__f)() const) |
| 1193 | {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} |
| 1194 | |
| 1195 | template <class _Sp, class _Tp, class _Ap> |
| 1196 | inline _LIBCPP_INLINE_VISIBILITY |
| 1197 | const_mem_fun1_ref_t<_Sp,_Tp,_Ap> |
| 1198 | mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) |
| 1199 | {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} |
| 1200 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1201 | #ifdef _LIBCPP_HAS_NO_VARIADICS |
| 1202 | |
| 1203 | #include <__functional_03> |
| 1204 | |
| 1205 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 1206 | |
| 1207 | template <class _Tp> |
| 1208 | class __mem_fn |
| 1209 | : public __weak_result_type<_Tp> |
| 1210 | { |
| 1211 | public: |
| 1212 | // types |
| 1213 | typedef _Tp type; |
| 1214 | private: |
| 1215 | type __f_; |
| 1216 | |
| 1217 | public: |
| 1218 | _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {} |
| 1219 | |
| 1220 | // invoke |
| 1221 | template <class... _ArgTypes> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1222 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1223 | typename __invoke_return<type, _ArgTypes...>::type |
Peter Collingbourne | a4c0d87 | 2014-01-22 22:56:52 +0000 | [diff] [blame] | 1224 | operator() (_ArgTypes&&... __args) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1225 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1226 | return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1227 | } |
| 1228 | }; |
| 1229 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1230 | template<class _Rp, class _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1231 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1232 | __mem_fn<_Rp _Tp::*> |
| 1233 | mem_fn(_Rp _Tp::* __pm) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1234 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1235 | return __mem_fn<_Rp _Tp::*>(__pm); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1238 | // bad_function_call |
| 1239 | |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1240 | class _LIBCPP_EXCEPTION_ABI bad_function_call |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1241 | : public exception |
| 1242 | { |
| 1243 | }; |
| 1244 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1245 | template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1246 | |
| 1247 | namespace __function |
| 1248 | { |
| 1249 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1250 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1251 | struct __maybe_derive_from_unary_function |
| 1252 | { |
| 1253 | }; |
| 1254 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1255 | template<class _Rp, class _A1> |
| 1256 | struct __maybe_derive_from_unary_function<_Rp(_A1)> |
| 1257 | : public unary_function<_A1, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1258 | { |
| 1259 | }; |
| 1260 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1261 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1262 | struct __maybe_derive_from_binary_function |
| 1263 | { |
| 1264 | }; |
| 1265 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1266 | template<class _Rp, class _A1, class _A2> |
| 1267 | struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> |
| 1268 | : public binary_function<_A1, _A2, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1269 | { |
| 1270 | }; |
| 1271 | |
| 1272 | template<class _Fp> class __base; |
| 1273 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1274 | template<class _Rp, class ..._ArgTypes> |
| 1275 | class __base<_Rp(_ArgTypes...)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1276 | { |
| 1277 | __base(const __base&); |
| 1278 | __base& operator=(const __base&); |
| 1279 | public: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1280 | _LIBCPP_INLINE_VISIBILITY __base() {} |
| 1281 | _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1282 | virtual __base* __clone() const = 0; |
| 1283 | virtual void __clone(__base*) const = 0; |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1284 | virtual void destroy() _NOEXCEPT = 0; |
| 1285 | virtual void destroy_deallocate() _NOEXCEPT = 0; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1286 | virtual _Rp operator()(_ArgTypes&& ...) = 0; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1287 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1288 | virtual const void* target(const type_info&) const _NOEXCEPT = 0; |
| 1289 | virtual const std::type_info& target_type() const _NOEXCEPT = 0; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1290 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1291 | }; |
| 1292 | |
| 1293 | template<class _FD, class _Alloc, class _FB> class __func; |
| 1294 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1295 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 1296 | class __func<_Fp, _Alloc, _Rp(_ArgTypes...)> |
| 1297 | : public __base<_Rp(_ArgTypes...)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1298 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1299 | __compressed_pair<_Fp, _Alloc> __f_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1300 | public: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1301 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4a13b2d | 2012-02-28 19:47:38 +0000 | [diff] [blame] | 1302 | explicit __func(_Fp&& __f) |
| 1303 | : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), |
| 1304 | _VSTD::forward_as_tuple()) {} |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1305 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4a13b2d | 2012-02-28 19:47:38 +0000 | [diff] [blame] | 1306 | explicit __func(const _Fp& __f, const _Alloc& __a) |
| 1307 | : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), |
| 1308 | _VSTD::forward_as_tuple(__a)) {} |
| 1309 | |
| 1310 | _LIBCPP_INLINE_VISIBILITY |
| 1311 | explicit __func(const _Fp& __f, _Alloc&& __a) |
| 1312 | : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), |
| 1313 | _VSTD::forward_as_tuple(_VSTD::move(__a))) {} |
| 1314 | |
| 1315 | _LIBCPP_INLINE_VISIBILITY |
| 1316 | explicit __func(_Fp&& __f, _Alloc&& __a) |
| 1317 | : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), |
| 1318 | _VSTD::forward_as_tuple(_VSTD::move(__a))) {} |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1319 | virtual __base<_Rp(_ArgTypes...)>* __clone() const; |
| 1320 | virtual void __clone(__base<_Rp(_ArgTypes...)>*) const; |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1321 | virtual void destroy() _NOEXCEPT; |
| 1322 | virtual void destroy_deallocate() _NOEXCEPT; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1323 | virtual _Rp operator()(_ArgTypes&& ... __arg); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1324 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1325 | virtual const void* target(const type_info&) const _NOEXCEPT; |
| 1326 | virtual const std::type_info& target_type() const _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1327 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1328 | }; |
| 1329 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1330 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 1331 | __base<_Rp(_ArgTypes...)>* |
| 1332 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1333 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1334 | typedef typename _Alloc::template rebind<__func>::other _Ap; |
| 1335 | _Ap __a(__f_.second()); |
| 1336 | typedef __allocator_destructor<_Ap> _Dp; |
| 1337 | unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1338 | ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); |
| 1339 | return __hold.release(); |
| 1340 | } |
| 1341 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1342 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1343 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1344 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1345 | { |
| 1346 | ::new (__p) __func(__f_.first(), __f_.second()); |
| 1347 | } |
| 1348 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1349 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1350 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1351 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1352 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1353 | __f_.~__compressed_pair<_Fp, _Alloc>(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1356 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1357 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1358 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1359 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1360 | typedef typename _Alloc::template rebind<__func>::other _Ap; |
| 1361 | _Ap __a(__f_.second()); |
| 1362 | __f_.~__compressed_pair<_Fp, _Alloc>(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1363 | __a.deallocate(this, 1); |
| 1364 | } |
| 1365 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1366 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 1367 | _Rp |
| 1368 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1369 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1370 | return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1373 | #ifndef _LIBCPP_NO_RTTI |
| 1374 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1375 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1376 | const void* |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1377 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1378 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1379 | if (__ti == typeid(_Fp)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1380 | return &__f_.first(); |
| 1381 | return (const void*)0; |
| 1382 | } |
| 1383 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1384 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1385 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1386 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1387 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1388 | return typeid(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1391 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1392 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1393 | } // __function |
| 1394 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1395 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1396 | class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1397 | : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>, |
| 1398 | public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1399 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1400 | typedef __function::__base<_Rp(_ArgTypes...)> __base; |
Howard Hinnant | 78f0de2 | 2013-01-21 17:26:55 +0000 | [diff] [blame] | 1401 | typename aligned_storage<3*sizeof(void*)>::type __buf_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1402 | __base* __f_; |
| 1403 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1404 | template <class _Fp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1405 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1406 | static bool __not_null(const _Fp&) {return true;} |
| 1407 | template <class _R2, class ..._Ap> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1408 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1409 | static bool __not_null(_R2 (*__p)(_Ap...)) {return __p;} |
| 1410 | template <class _R2, class _Cp, class ..._Ap> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1411 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1412 | static bool __not_null(_R2 (_Cp::*__p)(_Ap...)) {return __p;} |
| 1413 | template <class _R2, class _Cp, class ..._Ap> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1414 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1415 | static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const) {return __p;} |
| 1416 | template <class _R2, class _Cp, class ..._Ap> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1417 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1418 | static bool __not_null(_R2 (_Cp::*__p)(_Ap...) volatile) {return __p;} |
| 1419 | template <class _R2, class _Cp, class ..._Ap> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1420 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1421 | static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const volatile) {return __p;} |
| 1422 | template <class _R2, class ..._Ap> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1423 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1424 | static bool __not_null(const function<_Rp(_Ap...)>& __p) {return __p;} |
Howard Hinnant | 083ba5f | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 1425 | |
Howard Hinnant | e41f475 | 2012-07-20 18:56:07 +0000 | [diff] [blame] | 1426 | template <class _Fp, bool = !is_same<_Fp, function>::value && |
| 1427 | __invokable<_Fp&, _ArgTypes...>::value> |
Howard Hinnant | 083ba5f | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 1428 | struct __callable; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1429 | template <class _Fp> |
| 1430 | struct __callable<_Fp, true> |
Howard Hinnant | 083ba5f | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 1431 | { |
| 1432 | static const bool value = |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1433 | is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type, |
| 1434 | _Rp>::value; |
Howard Hinnant | 083ba5f | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 1435 | }; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1436 | template <class _Fp> |
| 1437 | struct __callable<_Fp, false> |
Howard Hinnant | 083ba5f | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 1438 | { |
| 1439 | static const bool value = false; |
| 1440 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1441 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1442 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1443 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1444 | // construct/copy/destroy: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1445 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1446 | function() _NOEXCEPT : __f_(0) {} |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1447 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1448 | function(nullptr_t) _NOEXCEPT : __f_(0) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1449 | function(const function&); |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1450 | function(function&&) _NOEXCEPT; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1451 | template<class _Fp> |
Howard Hinnant | 099dec1 | 2013-07-01 00:01:51 +0000 | [diff] [blame] | 1452 | function(_Fp, typename enable_if |
| 1453 | < |
| 1454 | __callable<_Fp>::value && |
| 1455 | !is_same<_Fp, function>::value |
| 1456 | >::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1457 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1458 | template<class _Alloc> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1459 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1460 | function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {} |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1461 | template<class _Alloc> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1462 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1463 | function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {} |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1464 | template<class _Alloc> |
| 1465 | function(allocator_arg_t, const _Alloc&, const function&); |
| 1466 | template<class _Alloc> |
| 1467 | function(allocator_arg_t, const _Alloc&, function&&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1468 | template<class _Fp, class _Alloc> |
| 1469 | function(allocator_arg_t, const _Alloc& __a, _Fp __f, |
| 1470 | typename enable_if<__callable<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1471 | |
| 1472 | function& operator=(const function&); |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1473 | function& operator=(function&&) _NOEXCEPT; |
| 1474 | function& operator=(nullptr_t) _NOEXCEPT; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1475 | template<class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1476 | typename enable_if |
| 1477 | < |
Howard Hinnant | 099dec1 | 2013-07-01 00:01:51 +0000 | [diff] [blame] | 1478 | __callable<typename decay<_Fp>::type>::value && |
| 1479 | !is_same<typename remove_reference<_Fp>::type, function>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1480 | function& |
| 1481 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1482 | operator=(_Fp&&); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1483 | |
| 1484 | ~function(); |
| 1485 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1486 | // function modifiers: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1487 | void swap(function&) _NOEXCEPT; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1488 | template<class _Fp, class _Alloc> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1489 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1490 | void assign(_Fp&& __f, const _Alloc& __a) |
| 1491 | {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1492 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1493 | // function capacity: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1494 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7786188 | 2012-02-21 21:46:43 +0000 | [diff] [blame] | 1495 | _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1496 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1497 | // deleted overloads close possible hole in the type system |
| 1498 | template<class _R2, class... _ArgTypes2> |
Howard Hinnant | a0f1dc9 | 2010-09-11 15:33:21 +0000 | [diff] [blame] | 1499 | bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1500 | template<class _R2, class... _ArgTypes2> |
Howard Hinnant | a0f1dc9 | 2010-09-11 15:33:21 +0000 | [diff] [blame] | 1501 | bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1502 | public: |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1503 | // function invocation: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1504 | _Rp operator()(_ArgTypes...) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1505 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1506 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1507 | // function target access: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1508 | const std::type_info& target_type() const _NOEXCEPT; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1509 | template <typename _Tp> _Tp* target() _NOEXCEPT; |
| 1510 | template <typename _Tp> const _Tp* target() const _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1511 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1512 | }; |
| 1513 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1514 | template<class _Rp, class ..._ArgTypes> |
| 1515 | function<_Rp(_ArgTypes...)>::function(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1516 | { |
| 1517 | if (__f.__f_ == 0) |
| 1518 | __f_ = 0; |
| 1519 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1520 | { |
| 1521 | __f_ = (__base*)&__buf_; |
| 1522 | __f.__f_->__clone(__f_); |
| 1523 | } |
| 1524 | else |
| 1525 | __f_ = __f.__f_->__clone(); |
| 1526 | } |
| 1527 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1528 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1529 | template <class _Alloc> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1530 | function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1531 | const function& __f) |
| 1532 | { |
| 1533 | if (__f.__f_ == 0) |
| 1534 | __f_ = 0; |
| 1535 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1536 | { |
| 1537 | __f_ = (__base*)&__buf_; |
| 1538 | __f.__f_->__clone(__f_); |
| 1539 | } |
| 1540 | else |
| 1541 | __f_ = __f.__f_->__clone(); |
| 1542 | } |
| 1543 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1544 | template<class _Rp, class ..._ArgTypes> |
| 1545 | function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1546 | { |
| 1547 | if (__f.__f_ == 0) |
| 1548 | __f_ = 0; |
| 1549 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1550 | { |
| 1551 | __f_ = (__base*)&__buf_; |
| 1552 | __f.__f_->__clone(__f_); |
| 1553 | } |
| 1554 | else |
| 1555 | { |
| 1556 | __f_ = __f.__f_; |
| 1557 | __f.__f_ = 0; |
| 1558 | } |
| 1559 | } |
| 1560 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1561 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1562 | template <class _Alloc> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1563 | function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1564 | function&& __f) |
| 1565 | { |
| 1566 | if (__f.__f_ == 0) |
| 1567 | __f_ = 0; |
| 1568 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1569 | { |
| 1570 | __f_ = (__base*)&__buf_; |
| 1571 | __f.__f_->__clone(__f_); |
| 1572 | } |
| 1573 | else |
| 1574 | { |
| 1575 | __f_ = __f.__f_; |
| 1576 | __f.__f_ = 0; |
| 1577 | } |
| 1578 | } |
| 1579 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1580 | template<class _Rp, class ..._ArgTypes> |
| 1581 | template <class _Fp> |
| 1582 | function<_Rp(_ArgTypes...)>::function(_Fp __f, |
Howard Hinnant | 099dec1 | 2013-07-01 00:01:51 +0000 | [diff] [blame] | 1583 | typename enable_if |
| 1584 | < |
| 1585 | __callable<_Fp>::value && |
| 1586 | !is_same<_Fp, function>::value |
| 1587 | >::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1588 | : __f_(0) |
| 1589 | { |
| 1590 | if (__not_null(__f)) |
| 1591 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1592 | typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF; |
| 1593 | if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1594 | { |
| 1595 | __f_ = (__base*)&__buf_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1596 | ::new (__f_) _FF(_VSTD::move(__f)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1597 | } |
| 1598 | else |
| 1599 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1600 | typedef allocator<_FF> _Ap; |
| 1601 | _Ap __a; |
| 1602 | typedef __allocator_destructor<_Ap> _Dp; |
| 1603 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
| 1604 | ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1605 | __f_ = __hold.release(); |
| 1606 | } |
| 1607 | } |
| 1608 | } |
| 1609 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1610 | template<class _Rp, class ..._ArgTypes> |
| 1611 | template <class _Fp, class _Alloc> |
| 1612 | function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, |
| 1613 | typename enable_if<__callable<_Fp>::value>::type*) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1614 | : __f_(0) |
| 1615 | { |
| 1616 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 1617 | if (__not_null(__f)) |
| 1618 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1619 | typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF; |
| 1620 | if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1621 | { |
| 1622 | __f_ = (__base*)&__buf_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1623 | ::new (__f_) _FF(_VSTD::move(__f)); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1624 | } |
| 1625 | else |
| 1626 | { |
| 1627 | typedef typename __alloc_traits::template |
| 1628 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 1629 | rebind_alloc<_FF> |
| 1630 | #else |
| 1631 | rebind_alloc<_FF>::other |
| 1632 | #endif |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1633 | _Ap; |
| 1634 | _Ap __a(__a0); |
| 1635 | typedef __allocator_destructor<_Ap> _Dp; |
| 1636 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1637 | ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a)); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1638 | __f_ = __hold.release(); |
| 1639 | } |
| 1640 | } |
| 1641 | } |
| 1642 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1643 | template<class _Rp, class ..._ArgTypes> |
| 1644 | function<_Rp(_ArgTypes...)>& |
| 1645 | function<_Rp(_ArgTypes...)>::operator=(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1646 | { |
| 1647 | function(__f).swap(*this); |
| 1648 | return *this; |
| 1649 | } |
| 1650 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1651 | template<class _Rp, class ..._ArgTypes> |
| 1652 | function<_Rp(_ArgTypes...)>& |
| 1653 | function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1654 | { |
| 1655 | if (__f_ == (__base*)&__buf_) |
| 1656 | __f_->destroy(); |
| 1657 | else if (__f_) |
| 1658 | __f_->destroy_deallocate(); |
| 1659 | __f_ = 0; |
| 1660 | if (__f.__f_ == 0) |
| 1661 | __f_ = 0; |
| 1662 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1663 | { |
| 1664 | __f_ = (__base*)&__buf_; |
| 1665 | __f.__f_->__clone(__f_); |
| 1666 | } |
| 1667 | else |
| 1668 | { |
| 1669 | __f_ = __f.__f_; |
| 1670 | __f.__f_ = 0; |
| 1671 | } |
Argyrios Kyrtzidis | 1dc6f7a | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 1672 | return *this; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1675 | template<class _Rp, class ..._ArgTypes> |
| 1676 | function<_Rp(_ArgTypes...)>& |
| 1677 | function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1678 | { |
| 1679 | if (__f_ == (__base*)&__buf_) |
| 1680 | __f_->destroy(); |
| 1681 | else if (__f_) |
| 1682 | __f_->destroy_deallocate(); |
| 1683 | __f_ = 0; |
Argyrios Kyrtzidis | 1dc6f7a | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 1684 | return *this; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1685 | } |
| 1686 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1687 | template<class _Rp, class ..._ArgTypes> |
| 1688 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1689 | typename enable_if |
| 1690 | < |
Howard Hinnant | 099dec1 | 2013-07-01 00:01:51 +0000 | [diff] [blame] | 1691 | function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value && |
| 1692 | !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1693 | function<_Rp(_ArgTypes...)>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1694 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1695 | function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1696 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1697 | function(_VSTD::forward<_Fp>(__f)).swap(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1698 | return *this; |
| 1699 | } |
| 1700 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1701 | template<class _Rp, class ..._ArgTypes> |
| 1702 | function<_Rp(_ArgTypes...)>::~function() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1703 | { |
| 1704 | if (__f_ == (__base*)&__buf_) |
| 1705 | __f_->destroy(); |
| 1706 | else if (__f_) |
| 1707 | __f_->destroy_deallocate(); |
| 1708 | } |
| 1709 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1710 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1711 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1712 | function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1713 | { |
| 1714 | if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) |
| 1715 | { |
| 1716 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 1717 | __base* __t = (__base*)&__tempbuf; |
| 1718 | __f_->__clone(__t); |
| 1719 | __f_->destroy(); |
| 1720 | __f_ = 0; |
| 1721 | __f.__f_->__clone((__base*)&__buf_); |
| 1722 | __f.__f_->destroy(); |
| 1723 | __f.__f_ = 0; |
| 1724 | __f_ = (__base*)&__buf_; |
| 1725 | __t->__clone((__base*)&__f.__buf_); |
| 1726 | __t->destroy(); |
| 1727 | __f.__f_ = (__base*)&__f.__buf_; |
| 1728 | } |
| 1729 | else if (__f_ == (__base*)&__buf_) |
| 1730 | { |
| 1731 | __f_->__clone((__base*)&__f.__buf_); |
| 1732 | __f_->destroy(); |
| 1733 | __f_ = __f.__f_; |
| 1734 | __f.__f_ = (__base*)&__f.__buf_; |
| 1735 | } |
| 1736 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1737 | { |
| 1738 | __f.__f_->__clone((__base*)&__buf_); |
| 1739 | __f.__f_->destroy(); |
| 1740 | __f.__f_ = __f_; |
| 1741 | __f_ = (__base*)&__buf_; |
| 1742 | } |
| 1743 | else |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1744 | _VSTD::swap(__f_, __f.__f_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1745 | } |
| 1746 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1747 | template<class _Rp, class ..._ArgTypes> |
| 1748 | _Rp |
| 1749 | function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1750 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1751 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1752 | if (__f_ == 0) |
| 1753 | throw bad_function_call(); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1754 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1755 | return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1756 | } |
| 1757 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1758 | #ifndef _LIBCPP_NO_RTTI |
| 1759 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1760 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1761 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1762 | function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1763 | { |
| 1764 | if (__f_ == 0) |
| 1765 | return typeid(void); |
| 1766 | return __f_->target_type(); |
| 1767 | } |
| 1768 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1769 | template<class _Rp, class ..._ArgTypes> |
| 1770 | template <typename _Tp> |
| 1771 | _Tp* |
| 1772 | function<_Rp(_ArgTypes...)>::target() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1773 | { |
| 1774 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1775 | return (_Tp*)0; |
| 1776 | return (_Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1779 | template<class _Rp, class ..._ArgTypes> |
| 1780 | template <typename _Tp> |
| 1781 | const _Tp* |
| 1782 | function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1783 | { |
| 1784 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1785 | return (const _Tp*)0; |
| 1786 | return (const _Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1789 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1790 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1791 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1792 | inline _LIBCPP_INLINE_VISIBILITY |
| 1793 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1794 | operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1795 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1796 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1797 | inline _LIBCPP_INLINE_VISIBILITY |
| 1798 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1799 | operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1800 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1801 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1802 | inline _LIBCPP_INLINE_VISIBILITY |
| 1803 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1804 | operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1805 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1806 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1807 | inline _LIBCPP_INLINE_VISIBILITY |
| 1808 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1809 | operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1810 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1811 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1812 | inline _LIBCPP_INLINE_VISIBILITY |
| 1813 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1814 | swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1815 | {return __x.swap(__y);} |
| 1816 | |
| 1817 | template<class _Tp> struct __is_bind_expression : public false_type {}; |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1818 | template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1819 | : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; |
| 1820 | |
| 1821 | template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1822 | template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1823 | : public __is_placeholder<typename remove_cv<_Tp>::type> {}; |
| 1824 | |
| 1825 | namespace placeholders |
| 1826 | { |
| 1827 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1828 | template <int _Np> struct __ph {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1829 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1830 | _LIBCPP_FUNC_VIS extern __ph<1> _1; |
| 1831 | _LIBCPP_FUNC_VIS extern __ph<2> _2; |
| 1832 | _LIBCPP_FUNC_VIS extern __ph<3> _3; |
| 1833 | _LIBCPP_FUNC_VIS extern __ph<4> _4; |
| 1834 | _LIBCPP_FUNC_VIS extern __ph<5> _5; |
| 1835 | _LIBCPP_FUNC_VIS extern __ph<6> _6; |
| 1836 | _LIBCPP_FUNC_VIS extern __ph<7> _7; |
| 1837 | _LIBCPP_FUNC_VIS extern __ph<8> _8; |
| 1838 | _LIBCPP_FUNC_VIS extern __ph<9> _9; |
| 1839 | _LIBCPP_FUNC_VIS extern __ph<10> _10; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1840 | |
| 1841 | } // placeholders |
| 1842 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1843 | template<int _Np> |
| 1844 | struct __is_placeholder<placeholders::__ph<_Np> > |
| 1845 | : public integral_constant<int, _Np> {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1846 | |
| 1847 | template <class _Tp, class _Uj> |
| 1848 | inline _LIBCPP_INLINE_VISIBILITY |
| 1849 | _Tp& |
| 1850 | __mu(reference_wrapper<_Tp> __t, _Uj&) |
| 1851 | { |
| 1852 | return __t.get(); |
| 1853 | } |
| 1854 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1855 | template <class _Ti, class ..._Uj, size_t ..._Indx> |
| 1856 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1857 | typename __invoke_of<_Ti&, _Uj...>::type |
| 1858 | __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1859 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1860 | return __ti(_VSTD::forward<_Uj>(get<_Indx>(__uj))...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | template <class _Ti, class ..._Uj> |
| 1864 | inline _LIBCPP_INLINE_VISIBILITY |
| 1865 | typename enable_if |
| 1866 | < |
| 1867 | is_bind_expression<_Ti>::value, |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1868 | typename __invoke_of<_Ti&, _Uj...>::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1869 | >::type |
| 1870 | __mu(_Ti& __ti, tuple<_Uj...>& __uj) |
| 1871 | { |
| 1872 | typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; |
| 1873 | return __mu_expand(__ti, __uj, __indices()); |
| 1874 | } |
| 1875 | |
| 1876 | template <bool IsPh, class _Ti, class _Uj> |
| 1877 | struct __mu_return2 {}; |
| 1878 | |
| 1879 | template <class _Ti, class _Uj> |
| 1880 | struct __mu_return2<true, _Ti, _Uj> |
| 1881 | { |
| 1882 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; |
| 1883 | }; |
| 1884 | |
| 1885 | template <class _Ti, class _Uj> |
| 1886 | inline _LIBCPP_INLINE_VISIBILITY |
| 1887 | typename enable_if |
| 1888 | < |
| 1889 | 0 < is_placeholder<_Ti>::value, |
| 1890 | typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type |
| 1891 | >::type |
| 1892 | __mu(_Ti&, _Uj& __uj) |
| 1893 | { |
| 1894 | const size_t _Indx = is_placeholder<_Ti>::value - 1; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1895 | return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | template <class _Ti, class _Uj> |
| 1899 | inline _LIBCPP_INLINE_VISIBILITY |
| 1900 | typename enable_if |
| 1901 | < |
| 1902 | !is_bind_expression<_Ti>::value && |
| 1903 | is_placeholder<_Ti>::value == 0 && |
| 1904 | !__is_reference_wrapper<_Ti>::value, |
| 1905 | _Ti& |
| 1906 | >::type |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1907 | __mu(_Ti& __ti, _Uj&) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1908 | { |
| 1909 | return __ti; |
| 1910 | } |
| 1911 | |
Howard Hinnant | ef54251 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 1912 | template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh, |
| 1913 | class _TupleUj> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1914 | struct ____mu_return; |
| 1915 | |
Howard Hinnant | c05e986 | 2013-06-30 19:48:15 +0000 | [diff] [blame] | 1916 | template <bool _Invokable, class _Ti, class ..._Uj> |
| 1917 | struct ____mu_return_invokable // false |
| 1918 | { |
| 1919 | typedef __nat type; |
| 1920 | }; |
| 1921 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1922 | template <class _Ti, class ..._Uj> |
Howard Hinnant | c05e986 | 2013-06-30 19:48:15 +0000 | [diff] [blame] | 1923 | struct ____mu_return_invokable<true, _Ti, _Uj...> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1924 | { |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1925 | typedef typename __invoke_of<_Ti&, _Uj...>::type type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1926 | }; |
| 1927 | |
Howard Hinnant | c05e986 | 2013-06-30 19:48:15 +0000 | [diff] [blame] | 1928 | template <class _Ti, class ..._Uj> |
| 1929 | struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> > |
| 1930 | : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> |
| 1931 | { |
| 1932 | }; |
| 1933 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1934 | template <class _Ti, class _TupleUj> |
Howard Hinnant | ef54251 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 1935 | struct ____mu_return<_Ti, false, false, true, _TupleUj> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1936 | { |
| 1937 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, |
| 1938 | _TupleUj>::type&& type; |
| 1939 | }; |
| 1940 | |
| 1941 | template <class _Ti, class _TupleUj> |
Howard Hinnant | ef54251 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 1942 | struct ____mu_return<_Ti, true, false, false, _TupleUj> |
| 1943 | { |
| 1944 | typedef typename _Ti::type& type; |
| 1945 | }; |
| 1946 | |
| 1947 | template <class _Ti, class _TupleUj> |
| 1948 | struct ____mu_return<_Ti, false, false, false, _TupleUj> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1949 | { |
| 1950 | typedef _Ti& type; |
| 1951 | }; |
| 1952 | |
| 1953 | template <class _Ti, class _TupleUj> |
| 1954 | struct __mu_return |
| 1955 | : public ____mu_return<_Ti, |
Howard Hinnant | ef54251 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 1956 | __is_reference_wrapper<_Ti>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1957 | is_bind_expression<_Ti>::value, |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 1958 | 0 < is_placeholder<_Ti>::value && |
| 1959 | is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1960 | _TupleUj> |
| 1961 | { |
| 1962 | }; |
| 1963 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1964 | template <class _Fp, class _BoundArgs, class _TupleUj> |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 1965 | struct _is_valid_bind_return |
| 1966 | { |
| 1967 | static const bool value = false; |
| 1968 | }; |
| 1969 | |
| 1970 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
| 1971 | struct _is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> |
| 1972 | { |
| 1973 | static const bool value = __invokable<_Fp, |
| 1974 | typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; |
| 1975 | }; |
| 1976 | |
| 1977 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
| 1978 | struct _is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> |
| 1979 | { |
| 1980 | static const bool value = __invokable<_Fp, |
| 1981 | typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value; |
| 1982 | }; |
| 1983 | |
| 1984 | template <class _Fp, class _BoundArgs, class _TupleUj, |
| 1985 | bool = _is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1986 | struct __bind_return; |
| 1987 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1988 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 1989 | struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1990 | { |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1991 | typedef typename __invoke_of |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1992 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1993 | _Fp&, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1994 | typename __mu_return |
| 1995 | < |
| 1996 | _BoundArgs, |
| 1997 | _TupleUj |
| 1998 | >::type... |
| 1999 | >::type type; |
| 2000 | }; |
| 2001 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2002 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2003 | struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2004 | { |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2005 | typedef typename __invoke_of |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2006 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2007 | _Fp&, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2008 | typename __mu_return |
| 2009 | < |
| 2010 | const _BoundArgs, |
| 2011 | _TupleUj |
| 2012 | >::type... |
| 2013 | >::type type; |
| 2014 | }; |
| 2015 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2016 | template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2017 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2018 | typename __bind_return<_Fp, _BoundArgs, _Args>::type |
| 2019 | __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2020 | _Args&& __args) |
| 2021 | { |
| 2022 | return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...); |
| 2023 | } |
| 2024 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2025 | template<class _Fp, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2026 | class __bind |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2027 | : public __weak_result_type<typename decay<_Fp>::type> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2028 | { |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2029 | protected: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2030 | typedef typename decay<_Fp>::type _Fd; |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2031 | typedef tuple<typename decay<_BoundArgs>::type...> _Td; |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2032 | private: |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2033 | _Fd __f_; |
| 2034 | _Td __bound_args_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2035 | |
| 2036 | typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; |
| 2037 | public: |
Howard Hinnant | 90d7785 | 2011-07-02 18:22:36 +0000 | [diff] [blame] | 2038 | #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS |
| 2039 | |
| 2040 | _LIBCPP_INLINE_VISIBILITY |
| 2041 | __bind(const __bind& __b) |
| 2042 | : __f_(__b.__f_), |
| 2043 | __bound_args_(__b.__bound_args_) {} |
| 2044 | |
| 2045 | _LIBCPP_INLINE_VISIBILITY |
| 2046 | __bind& operator=(const __bind& __b) |
| 2047 | { |
| 2048 | __f_ = __b.__f_; |
| 2049 | __bound_args_ = __b.__bound_args_; |
| 2050 | return *this; |
| 2051 | } |
| 2052 | |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2053 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2054 | __bind(__bind&& __b) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2055 | : __f_(_VSTD::move(__b.__f_)), |
| 2056 | __bound_args_(_VSTD::move(__b.__bound_args_)) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2057 | |
Howard Hinnant | 90d7785 | 2011-07-02 18:22:36 +0000 | [diff] [blame] | 2058 | _LIBCPP_INLINE_VISIBILITY |
| 2059 | __bind& operator=(__bind&& __b) |
| 2060 | { |
| 2061 | __f_ = _VSTD::move(__b.__f_); |
| 2062 | __bound_args_ = _VSTD::move(__b.__bound_args_); |
| 2063 | return *this; |
| 2064 | } |
| 2065 | |
| 2066 | #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS |
| 2067 | |
Howard Hinnant | d2da6d2 | 2012-05-04 17:21:02 +0000 | [diff] [blame] | 2068 | template <class _Gp, class ..._BA, |
| 2069 | class = typename enable_if |
| 2070 | < |
Howard Hinnant | 099dec1 | 2013-07-01 00:01:51 +0000 | [diff] [blame] | 2071 | is_constructible<_Fd, _Gp>::value && |
| 2072 | !is_same<typename remove_reference<_Gp>::type, |
| 2073 | __bind>::value |
Howard Hinnant | d2da6d2 | 2012-05-04 17:21:02 +0000 | [diff] [blame] | 2074 | >::type> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2075 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2076 | explicit __bind(_Gp&& __f, _BA&& ...__bound_args) |
| 2077 | : __f_(_VSTD::forward<_Gp>(__f)), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2078 | __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2079 | |
| 2080 | template <class ..._Args> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2081 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2082 | typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2083 | operator()(_Args&& ...__args) |
| 2084 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2085 | return __apply_functor(__f_, __bound_args_, __indices(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2086 | tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | template <class ..._Args> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2090 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2091 | typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2092 | operator()(_Args&& ...__args) const |
| 2093 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2094 | return __apply_functor(__f_, __bound_args_, __indices(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2095 | tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2096 | } |
| 2097 | }; |
| 2098 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2099 | template<class _Fp, class ..._BoundArgs> |
| 2100 | struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2101 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2102 | template<class _Rp, class _Fp, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2103 | class __bind_r |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2104 | : public __bind<_Fp, _BoundArgs...> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2105 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2106 | typedef __bind<_Fp, _BoundArgs...> base; |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2107 | typedef typename base::_Fd _Fd; |
| 2108 | typedef typename base::_Td _Td; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2109 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2110 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2111 | |
Howard Hinnant | 90d7785 | 2011-07-02 18:22:36 +0000 | [diff] [blame] | 2112 | #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS |
| 2113 | |
| 2114 | _LIBCPP_INLINE_VISIBILITY |
| 2115 | __bind_r(const __bind_r& __b) |
| 2116 | : base(_VSTD::forward<const base&>(__b)) {} |
| 2117 | |
| 2118 | _LIBCPP_INLINE_VISIBILITY |
| 2119 | __bind_r& operator=(const __bind_r& __b) |
| 2120 | { |
| 2121 | base::operator=(_VSTD::forward<const base&>(__b)); |
| 2122 | return *this; |
| 2123 | } |
| 2124 | |
Howard Hinnant | 496934a | 2011-05-16 16:19:01 +0000 | [diff] [blame] | 2125 | _LIBCPP_INLINE_VISIBILITY |
| 2126 | __bind_r(__bind_r&& __b) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2127 | : base(_VSTD::forward<base>(__b)) {} |
Howard Hinnant | 496934a | 2011-05-16 16:19:01 +0000 | [diff] [blame] | 2128 | |
Howard Hinnant | 90d7785 | 2011-07-02 18:22:36 +0000 | [diff] [blame] | 2129 | _LIBCPP_INLINE_VISIBILITY |
| 2130 | __bind_r& operator=(__bind_r&& __b) |
| 2131 | { |
| 2132 | base::operator=(_VSTD::forward<base>(__b)); |
| 2133 | return *this; |
| 2134 | } |
| 2135 | |
| 2136 | #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS |
| 2137 | |
Howard Hinnant | 099dec1 | 2013-07-01 00:01:51 +0000 | [diff] [blame] | 2138 | template <class _Gp, class ..._BA, |
| 2139 | class = typename enable_if |
| 2140 | < |
| 2141 | is_constructible<_Fd, _Gp>::value && |
| 2142 | !is_same<typename remove_reference<_Gp>::type, |
| 2143 | __bind_r>::value |
| 2144 | >::type> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2145 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2146 | explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) |
| 2147 | : base(_VSTD::forward<_Gp>(__f), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2148 | _VSTD::forward<_BA>(__bound_args)...) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2149 | |
| 2150 | template <class ..._Args> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2151 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2152 | typename enable_if |
| 2153 | < |
| 2154 | is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type, |
| 2155 | result_type>::value, |
| 2156 | result_type |
| 2157 | >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2158 | operator()(_Args&& ...__args) |
| 2159 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2160 | return base::operator()(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | template <class ..._Args> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2164 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2165 | typename enable_if |
| 2166 | < |
| 2167 | is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type, |
| 2168 | result_type>::value, |
| 2169 | result_type |
| 2170 | >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2171 | operator()(_Args&& ...__args) const |
| 2172 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2173 | return base::operator()(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2174 | } |
| 2175 | }; |
| 2176 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2177 | template<class _Rp, class _Fp, class ..._BoundArgs> |
| 2178 | struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2179 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2180 | template<class _Fp, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2181 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2182 | __bind<_Fp, _BoundArgs...> |
| 2183 | bind(_Fp&& __f, _BoundArgs&&... __bound_args) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2184 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2185 | typedef __bind<_Fp, _BoundArgs...> type; |
| 2186 | return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2187 | } |
| 2188 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2189 | template<class _Rp, class _Fp, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2190 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2191 | __bind_r<_Rp, _Fp, _BoundArgs...> |
| 2192 | bind(_Fp&& __f, _BoundArgs&&... __bound_args) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2193 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2194 | typedef __bind_r<_Rp, _Fp, _BoundArgs...> type; |
| 2195 | return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 2199 | |
| 2200 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2201 | struct _LIBCPP_TYPE_VIS_ONLY hash<bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2202 | : public unary_function<bool, size_t> |
| 2203 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2204 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2205 | size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2206 | }; |
| 2207 | |
| 2208 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2209 | struct _LIBCPP_TYPE_VIS_ONLY hash<char> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2210 | : public unary_function<char, size_t> |
| 2211 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2212 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2213 | size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2214 | }; |
| 2215 | |
| 2216 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2217 | struct _LIBCPP_TYPE_VIS_ONLY hash<signed char> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2218 | : public unary_function<signed char, size_t> |
| 2219 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2220 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2221 | size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2222 | }; |
| 2223 | |
| 2224 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2225 | struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2226 | : public unary_function<unsigned char, size_t> |
| 2227 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2228 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2229 | size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2230 | }; |
| 2231 | |
| 2232 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
| 2233 | |
| 2234 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2235 | struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2236 | : public unary_function<char16_t, size_t> |
| 2237 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2238 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2239 | size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2240 | }; |
| 2241 | |
| 2242 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2243 | struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2244 | : public unary_function<char32_t, size_t> |
| 2245 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2246 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2247 | size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2248 | }; |
| 2249 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2250 | #endif // _LIBCPP_HAS_NO_UNICODE_CHARS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2251 | |
| 2252 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2253 | struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2254 | : public unary_function<wchar_t, size_t> |
| 2255 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2256 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2257 | size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2258 | }; |
| 2259 | |
| 2260 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2261 | struct _LIBCPP_TYPE_VIS_ONLY hash<short> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2262 | : public unary_function<short, size_t> |
| 2263 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2264 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2265 | size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2266 | }; |
| 2267 | |
| 2268 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2269 | struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2270 | : public unary_function<unsigned short, size_t> |
| 2271 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2272 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2273 | size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2274 | }; |
| 2275 | |
| 2276 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2277 | struct _LIBCPP_TYPE_VIS_ONLY hash<int> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2278 | : public unary_function<int, size_t> |
| 2279 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2280 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2281 | size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2282 | }; |
| 2283 | |
| 2284 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2285 | struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2286 | : public unary_function<unsigned int, size_t> |
| 2287 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2288 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2289 | size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2290 | }; |
| 2291 | |
| 2292 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2293 | struct _LIBCPP_TYPE_VIS_ONLY hash<long> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2294 | : public unary_function<long, size_t> |
| 2295 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2296 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2297 | size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2298 | }; |
| 2299 | |
| 2300 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2301 | struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2302 | : public unary_function<unsigned long, size_t> |
| 2303 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2304 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2305 | size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2306 | }; |
| 2307 | |
| 2308 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2309 | struct _LIBCPP_TYPE_VIS_ONLY hash<long long> |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2310 | : public __scalar_hash<long long> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2311 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2312 | }; |
| 2313 | |
| 2314 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2315 | struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long> |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2316 | : public __scalar_hash<unsigned long long> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2317 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2318 | }; |
| 2319 | |
| 2320 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2321 | struct _LIBCPP_TYPE_VIS_ONLY hash<float> |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2322 | : public __scalar_hash<float> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2323 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2324 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2325 | size_t operator()(float __v) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2326 | { |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2327 | // -0.0 and 0.0 should return same hash |
Howard Hinnant | 2891675 | 2011-12-02 23:45:22 +0000 | [diff] [blame] | 2328 | if (__v == 0) |
| 2329 | return 0; |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2330 | return __scalar_hash<float>::operator()(__v); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2331 | } |
| 2332 | }; |
| 2333 | |
| 2334 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2335 | struct _LIBCPP_TYPE_VIS_ONLY hash<double> |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2336 | : public __scalar_hash<double> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2337 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2338 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2339 | size_t operator()(double __v) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2340 | { |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2341 | // -0.0 and 0.0 should return same hash |
| 2342 | if (__v == 0) |
| 2343 | return 0; |
| 2344 | return __scalar_hash<double>::operator()(__v); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2345 | } |
| 2346 | }; |
| 2347 | |
| 2348 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2349 | struct _LIBCPP_TYPE_VIS_ONLY hash<long double> |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2350 | : public __scalar_hash<long double> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2351 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2352 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2353 | size_t operator()(long double __v) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2354 | { |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2355 | // -0.0 and 0.0 should return same hash |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2356 | if (__v == 0) |
| 2357 | return 0; |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2358 | #if defined(__i386__) |
| 2359 | // Zero out padding bits |
| 2360 | union |
Howard Hinnant | 2891675 | 2011-12-02 23:45:22 +0000 | [diff] [blame] | 2361 | { |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2362 | long double __t; |
| 2363 | struct |
Howard Hinnant | 2891675 | 2011-12-02 23:45:22 +0000 | [diff] [blame] | 2364 | { |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2365 | size_t __a; |
| 2366 | size_t __b; |
| 2367 | size_t __c; |
Howard Hinnant | 2891675 | 2011-12-02 23:45:22 +0000 | [diff] [blame] | 2368 | size_t __d; |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2369 | }; |
Howard Hinnant | 2891675 | 2011-12-02 23:45:22 +0000 | [diff] [blame] | 2370 | } __u; |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2371 | __u.__a = 0; |
| 2372 | __u.__b = 0; |
| 2373 | __u.__c = 0; |
| 2374 | __u.__d = 0; |
| 2375 | __u.__t = __v; |
| 2376 | return __u.__a ^ __u.__b ^ __u.__c ^ __u.__d; |
| 2377 | #elif defined(__x86_64__) |
| 2378 | // Zero out padding bits |
| 2379 | union |
| 2380 | { |
| 2381 | long double __t; |
| 2382 | struct |
| 2383 | { |
| 2384 | size_t __a; |
| 2385 | size_t __b; |
| 2386 | }; |
| 2387 | } __u; |
| 2388 | __u.__a = 0; |
| 2389 | __u.__b = 0; |
| 2390 | __u.__t = __v; |
| 2391 | return __u.__a ^ __u.__b; |
| 2392 | #else |
| 2393 | return __scalar_hash<long double>::operator()(__v); |
| 2394 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2395 | } |
| 2396 | }; |
| 2397 | |
Marshall Clow | 9e613ca | 2013-09-03 17:55:32 +0000 | [diff] [blame] | 2398 | #if _LIBCPP_STD_VER > 11 |
| 2399 | template <class _Tp> |
| 2400 | struct _LIBCPP_TYPE_VIS_ONLY hash |
| 2401 | : public unary_function<_Tp, size_t> |
| 2402 | { |
| 2403 | static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types"); |
| 2404 | |
| 2405 | _LIBCPP_INLINE_VISIBILITY |
| 2406 | size_t operator()(_Tp __v) const _NOEXCEPT |
| 2407 | { |
| 2408 | typedef typename underlying_type<_Tp>::type type; |
| 2409 | return hash<type>{}(static_cast<type>(__v)); |
| 2410 | } |
| 2411 | }; |
| 2412 | #endif |
| 2413 | |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2414 | // struct hash<T*> in <memory> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2415 | |
| 2416 | _LIBCPP_END_NAMESPACE_STD |
| 2417 | |
| 2418 | #endif // _LIBCPP_FUNCTIONAL |