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