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