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