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