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