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