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