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