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