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