Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===------------------------ functional ----------------------------------===// |
| 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_FUNCTIONAL |
| 11 | #define _LIBCPP_FUNCTIONAL |
| 12 | |
| 13 | /* |
| 14 | functional synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | |
| 19 | template <class Arg, class Result> |
| 20 | struct unary_function |
| 21 | { |
| 22 | typedef Arg argument_type; |
| 23 | typedef Result result_type; |
| 24 | }; |
| 25 | |
| 26 | template <class Arg1, class Arg2, class Result> |
| 27 | struct binary_function |
| 28 | { |
| 29 | typedef Arg1 first_argument_type; |
| 30 | typedef Arg2 second_argument_type; |
| 31 | typedef Result result_type; |
| 32 | }; |
| 33 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 34 | template <class T> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 35 | class reference_wrapper |
| 36 | : public unary_function<T1, R> // if wrapping a unary functor |
| 37 | : public binary_function<T1, T2, R> // if wraping a binary functor |
| 38 | { |
| 39 | public: |
| 40 | // types |
| 41 | typedef T type; |
| 42 | typedef see below result_type; // Not always defined |
| 43 | |
| 44 | // construct/copy/destroy |
Arthur O'Dwyer | 8fa8794 | 2020-12-05 19:37:41 -0500 | [diff] [blame] | 45 | template<class U> |
| 46 | reference_wrapper(U&&); |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 47 | reference_wrapper(const reference_wrapper<T>& x) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 48 | |
| 49 | // assignment |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 50 | reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 51 | |
| 52 | // access |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 53 | operator T& () const noexcept; |
| 54 | T& get() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 55 | |
| 56 | // invoke |
| 57 | template <class... ArgTypes> |
Howard Hinnant | c9c775b | 2013-09-21 17:58:58 +0000 | [diff] [blame] | 58 | typename result_of<T&(ArgTypes&&...)>::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 59 | operator() (ArgTypes&&...) const; |
| 60 | }; |
| 61 | |
Arthur O'Dwyer | 8fa8794 | 2020-12-05 19:37:41 -0500 | [diff] [blame] | 62 | template <class T> |
| 63 | reference_wrapper(T&) -> reference_wrapper<T>; |
| 64 | |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 65 | template <class T> reference_wrapper<T> ref(T& t) noexcept; |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 66 | template <class T> void ref(const T&& t) = delete; |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 67 | template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 68 | |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 69 | template <class T> reference_wrapper<const T> cref(const T& t) noexcept; |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 70 | template <class T> void cref(const T&& t) = delete; |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 71 | 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] | 72 | |
Louis Dionne | db1892a | 2018-12-03 14:03:27 +0000 | [diff] [blame] | 73 | template <class T> struct unwrap_reference; // since C++20 |
| 74 | template <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { }; // since C++20 |
| 75 | template <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20 |
| 76 | template <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20 |
| 77 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 78 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 79 | struct plus : binary_function<T, T, T> |
| 80 | { |
| 81 | T operator()(const T& x, const T& y) const; |
| 82 | }; |
| 83 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 84 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 85 | struct minus : binary_function<T, T, T> |
| 86 | { |
| 87 | T operator()(const T& x, const T& y) const; |
| 88 | }; |
| 89 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 90 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 91 | struct multiplies : binary_function<T, T, T> |
| 92 | { |
| 93 | T operator()(const T& x, const T& y) const; |
| 94 | }; |
| 95 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 96 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 97 | struct divides : binary_function<T, T, T> |
| 98 | { |
| 99 | T operator()(const T& x, const T& y) const; |
| 100 | }; |
| 101 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 102 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 103 | struct modulus : binary_function<T, T, T> |
| 104 | { |
| 105 | T operator()(const T& x, const T& y) const; |
| 106 | }; |
| 107 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 108 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 109 | struct negate : unary_function<T, T> |
| 110 | { |
| 111 | T operator()(const T& x) const; |
| 112 | }; |
| 113 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 114 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 115 | struct equal_to : binary_function<T, T, bool> |
| 116 | { |
| 117 | bool operator()(const T& x, const T& y) const; |
| 118 | }; |
| 119 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 120 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 121 | struct not_equal_to : binary_function<T, T, bool> |
| 122 | { |
| 123 | bool operator()(const T& x, const T& y) const; |
| 124 | }; |
| 125 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 126 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 127 | struct greater : binary_function<T, T, bool> |
| 128 | { |
| 129 | bool operator()(const T& x, const T& y) const; |
| 130 | }; |
| 131 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 132 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 133 | struct less : binary_function<T, T, bool> |
| 134 | { |
| 135 | bool operator()(const T& x, const T& y) const; |
| 136 | }; |
| 137 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 138 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 139 | struct greater_equal : binary_function<T, T, bool> |
| 140 | { |
| 141 | bool operator()(const T& x, const T& y) const; |
| 142 | }; |
| 143 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 144 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 145 | struct less_equal : binary_function<T, T, bool> |
| 146 | { |
| 147 | bool operator()(const T& x, const T& y) const; |
| 148 | }; |
| 149 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 150 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 151 | struct logical_and : binary_function<T, T, bool> |
| 152 | { |
| 153 | bool operator()(const T& x, const T& y) const; |
| 154 | }; |
| 155 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 156 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 157 | struct logical_or : binary_function<T, T, bool> |
| 158 | { |
| 159 | bool operator()(const T& x, const T& y) const; |
| 160 | }; |
| 161 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 162 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 163 | struct logical_not : unary_function<T, bool> |
| 164 | { |
| 165 | bool operator()(const T& x) const; |
| 166 | }; |
| 167 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 168 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | 0e77445 | 2021-03-07 20:22:03 -0500 | [diff] [blame] | 169 | struct bit_and : binary_function<T, T, T> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 170 | { |
Arthur O'Dwyer | 0e77445 | 2021-03-07 20:22:03 -0500 | [diff] [blame] | 171 | T operator()(const T& x, const T& y) const; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | 0e77445 | 2021-03-07 20:22:03 -0500 | [diff] [blame] | 175 | struct bit_or : binary_function<T, T, T> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 176 | { |
Arthur O'Dwyer | 0e77445 | 2021-03-07 20:22:03 -0500 | [diff] [blame] | 177 | T operator()(const T& x, const T& y) const; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | 0e77445 | 2021-03-07 20:22:03 -0500 | [diff] [blame] | 181 | struct bit_xor : binary_function<T, T, T> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 182 | { |
Arthur O'Dwyer | 0e77445 | 2021-03-07 20:22:03 -0500 | [diff] [blame] | 183 | T operator()(const T& x, const T& y) const; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | template <class T=void> // C++14 |
Arthur O'Dwyer | 0e77445 | 2021-03-07 20:22:03 -0500 | [diff] [blame] | 187 | struct bit_not : unary_function<T, T> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 188 | { |
Arthur O'Dwyer | 0e77445 | 2021-03-07 20:22:03 -0500 | [diff] [blame] | 189 | T operator()(const T& x) const; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 190 | }; |
| 191 | |
Christopher Di Bella | e68ec58 | 2021-03-18 17:21:35 +0000 | [diff] [blame] | 192 | struct identity; // C++20 |
| 193 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 194 | template <class Predicate> |
Arthur O'Dwyer | a6b5107 | 2021-05-24 18:36:17 -0400 | [diff] [blame] | 195 | class unary_negate // deprecated in C++17, removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 196 | : public unary_function<typename Predicate::argument_type, bool> |
| 197 | { |
| 198 | public: |
| 199 | explicit unary_negate(const Predicate& pred); |
| 200 | bool operator()(const typename Predicate::argument_type& x) const; |
| 201 | }; |
| 202 | |
Arthur O'Dwyer | a6b5107 | 2021-05-24 18:36:17 -0400 | [diff] [blame] | 203 | template <class Predicate> // deprecated in C++17, removed in C++20 |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 204 | unary_negate<Predicate> not1(const Predicate& pred); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 205 | |
| 206 | template <class Predicate> |
Arthur O'Dwyer | a6b5107 | 2021-05-24 18:36:17 -0400 | [diff] [blame] | 207 | class binary_negate // deprecated in C++17, removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 208 | : public binary_function<typename Predicate::first_argument_type, |
| 209 | typename Predicate::second_argument_type, |
| 210 | bool> |
| 211 | { |
| 212 | public: |
| 213 | explicit binary_negate(const Predicate& pred); |
| 214 | bool operator()(const typename Predicate::first_argument_type& x, |
| 215 | const typename Predicate::second_argument_type& y) const; |
| 216 | }; |
| 217 | |
Arthur O'Dwyer | a6b5107 | 2021-05-24 18:36:17 -0400 | [diff] [blame] | 218 | template <class Predicate> // deprecated in C++17, removed in C++20 |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 219 | binary_negate<Predicate> not2(const Predicate& pred); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 220 | |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 221 | template <class F> |
| 222 | constexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20 |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 223 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 224 | template<class T> struct is_bind_expression; |
| 225 | template<class T> struct is_placeholder; |
| 226 | |
Marshall Clow | 2d2d7f1 | 2016-09-22 00:23:15 +0000 | [diff] [blame] | 227 | // See C++14 20.9.9, Function object binders |
Marshall Clow | f1bf62f | 2018-01-02 17:17:01 +0000 | [diff] [blame] | 228 | template <class T> inline constexpr bool is_bind_expression_v |
Marshall Clow | 2d2d7f1 | 2016-09-22 00:23:15 +0000 | [diff] [blame] | 229 | = is_bind_expression<T>::value; // C++17 |
Marshall Clow | f1bf62f | 2018-01-02 17:17:01 +0000 | [diff] [blame] | 230 | template <class T> inline constexpr int is_placeholder_v |
Marshall Clow | 2d2d7f1 | 2016-09-22 00:23:15 +0000 | [diff] [blame] | 231 | = is_placeholder<T>::value; // C++17 |
| 232 | |
| 233 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 234 | template<class Fn, class... BoundArgs> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 235 | constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20 |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 236 | template<class R, class Fn, class... BoundArgs> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 237 | constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 238 | |
Louis Dionne | af34f12 | 2019-04-03 17:54:37 +0000 | [diff] [blame] | 239 | template<class F, class... Args> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 240 | constexpr // constexpr in C++20 |
Louis Dionne | af34f12 | 2019-04-03 17:54:37 +0000 | [diff] [blame] | 241 | invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17 |
| 242 | noexcept(is_nothrow_invocable_v<F, Args...>); |
| 243 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 244 | namespace placeholders { |
| 245 | // M is the implementation-defined number of placeholders |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 246 | extern unspecified _1; |
| 247 | extern unspecified _2; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 248 | . |
| 249 | . |
| 250 | . |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 251 | extern unspecified _Mp; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | template <class Operation> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 255 | class binder1st // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 256 | : public unary_function<typename Operation::second_argument_type, |
| 257 | typename Operation::result_type> |
| 258 | { |
| 259 | protected: |
| 260 | Operation op; |
| 261 | typename Operation::first_argument_type value; |
| 262 | public: |
| 263 | binder1st(const Operation& x, const typename Operation::first_argument_type y); |
| 264 | typename Operation::result_type operator()( typename Operation::second_argument_type& x) const; |
| 265 | typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const; |
| 266 | }; |
| 267 | |
| 268 | template <class Operation, class T> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 269 | 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] | 270 | |
| 271 | template <class Operation> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 272 | class binder2nd // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 273 | : public unary_function<typename Operation::first_argument_type, |
| 274 | typename Operation::result_type> |
| 275 | { |
| 276 | protected: |
| 277 | Operation op; |
| 278 | typename Operation::second_argument_type value; |
| 279 | public: |
| 280 | binder2nd(const Operation& x, const typename Operation::second_argument_type y); |
| 281 | typename Operation::result_type operator()( typename Operation::first_argument_type& x) const; |
| 282 | typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const; |
| 283 | }; |
| 284 | |
| 285 | template <class Operation, class T> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 286 | 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] | 287 | |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 288 | 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] | 289 | class pointer_to_unary_function : public unary_function<Arg, Result> |
| 290 | { |
| 291 | public: |
| 292 | explicit pointer_to_unary_function(Result (*f)(Arg)); |
| 293 | Result operator()(Arg x) const; |
| 294 | }; |
| 295 | |
| 296 | template <class Arg, class Result> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 297 | 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] | 298 | |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 299 | 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] | 300 | class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> |
| 301 | { |
| 302 | public: |
| 303 | explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); |
| 304 | Result operator()(Arg1 x, Arg2 y) const; |
| 305 | }; |
| 306 | |
| 307 | template <class Arg1, class Arg2, class Result> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 308 | 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] | 309 | |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 310 | 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] | 311 | class mem_fun_t : public unary_function<T*, S> |
| 312 | { |
| 313 | public: |
| 314 | explicit mem_fun_t(S (T::*p)()); |
| 315 | S operator()(T* p) const; |
| 316 | }; |
| 317 | |
| 318 | template<class S, class T, class A> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 319 | 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] | 320 | { |
| 321 | public: |
| 322 | explicit mem_fun1_t(S (T::*p)(A)); |
| 323 | S operator()(T* p, A x) const; |
| 324 | }; |
| 325 | |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 326 | template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17 |
| 327 | 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] | 328 | |
| 329 | template<class S, class T> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 330 | 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] | 331 | { |
| 332 | public: |
| 333 | explicit mem_fun_ref_t(S (T::*p)()); |
| 334 | S operator()(T& p) const; |
| 335 | }; |
| 336 | |
| 337 | template<class S, class T, class A> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 338 | 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] | 339 | { |
| 340 | public: |
| 341 | explicit mem_fun1_ref_t(S (T::*p)(A)); |
| 342 | S operator()(T& p, A x) const; |
| 343 | }; |
| 344 | |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 345 | 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 |
| 346 | 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] | 347 | |
| 348 | template <class S, class T> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 349 | 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] | 350 | { |
| 351 | public: |
| 352 | explicit const_mem_fun_t(S (T::*p)() const); |
| 353 | S operator()(const T* p) const; |
| 354 | }; |
| 355 | |
| 356 | template <class S, class T, class A> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 357 | 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] | 358 | { |
| 359 | public: |
| 360 | explicit const_mem_fun1_t(S (T::*p)(A) const); |
| 361 | S operator()(const T* p, A x) const; |
| 362 | }; |
| 363 | |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 364 | 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 |
| 365 | 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] | 366 | |
| 367 | template <class S, class T> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 368 | 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] | 369 | { |
| 370 | public: |
| 371 | explicit const_mem_fun_ref_t(S (T::*p)() const); |
| 372 | S operator()(const T& p) const; |
| 373 | }; |
| 374 | |
| 375 | template <class S, class T, class A> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 376 | 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] | 377 | { |
| 378 | public: |
| 379 | explicit const_mem_fun1_ref_t(S (T::*p)(A) const); |
| 380 | S operator()(const T& p, A x) const; |
| 381 | }; |
| 382 | |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 383 | 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 |
| 384 | 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] | 385 | |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 386 | template<class R, class T> |
| 387 | constexpr unspecified mem_fn(R T::*); // constexpr in C++20 |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 388 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 389 | class bad_function_call |
| 390 | : public exception |
| 391 | { |
| 392 | }; |
| 393 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 394 | template<class> class function; // undefined |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 395 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 396 | template<class R, class... ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 397 | class function<R(ArgTypes...)> |
| 398 | : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and |
| 399 | // ArgTypes contains T1 |
| 400 | : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and |
| 401 | // ArgTypes contains T1 and T2 |
| 402 | { |
| 403 | public: |
| 404 | typedef R result_type; |
| 405 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 406 | // construct/copy/destroy: |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 407 | function() noexcept; |
| 408 | function(nullptr_t) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 409 | function(const function&); |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 410 | function(function&&) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 411 | template<class F> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 412 | function(F); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 413 | template<Allocator Alloc> |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 414 | function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 415 | template<Allocator Alloc> |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 416 | 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] | 417 | template<Allocator Alloc> |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 418 | function(allocator_arg_t, const Alloc&, const function&); // removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 419 | template<Allocator Alloc> |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 420 | function(allocator_arg_t, const Alloc&, function&&); // removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 421 | template<class F, Allocator Alloc> |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 422 | function(allocator_arg_t, const Alloc&, F); // removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 423 | |
| 424 | function& operator=(const function&); |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 425 | function& operator=(function&&) noexcept; |
Howard Hinnant | 7b85be0 | 2011-05-29 13:53:56 +0000 | [diff] [blame] | 426 | function& operator=(nullptr_t) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 427 | template<class F> |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 428 | function& operator=(F&&); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 429 | template<class F> |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 430 | function& operator=(reference_wrapper<F>) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 431 | |
| 432 | ~function(); |
| 433 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 434 | // function modifiers: |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 435 | void swap(function&) noexcept; |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 436 | template<class F, class Alloc> |
Marshall Clow | fc8fd83 | 2016-01-25 17:29:55 +0000 | [diff] [blame] | 437 | void assign(F&&, const Alloc&); // Removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 438 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 439 | // function capacity: |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 440 | explicit operator bool() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 441 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 442 | // function invocation: |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 443 | R operator()(ArgTypes...) const; |
| 444 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 445 | // function target access: |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 446 | const std::type_info& target_type() const noexcept; |
| 447 | template <typename T> T* target() noexcept; |
| 448 | template <typename T> const T* target() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 449 | }; |
| 450 | |
Louis Dionne | 4af4971 | 2019-07-18 19:50:56 +0000 | [diff] [blame] | 451 | // Deduction guides |
| 452 | template<class R, class ...Args> |
| 453 | function(R(*)(Args...)) -> function<R(Args...)>; // since C++17 |
| 454 | |
| 455 | template<class F> |
| 456 | function(F) -> function<see-below>; // since C++17 |
| 457 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 458 | // Null pointer comparisons: |
| 459 | template <class R, class ... ArgTypes> |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 460 | bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 461 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 462 | template <class R, class ... ArgTypes> |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 463 | bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 464 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 465 | template <class R, class ... ArgTypes> |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 466 | bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 467 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 468 | template <class R, class ... ArgTypes> |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 469 | bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 470 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 471 | // specialized algorithms: |
| 472 | template <class R, class ... ArgTypes> |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 473 | void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 474 | |
| 475 | template <class T> struct hash; |
| 476 | |
| 477 | template <> struct hash<bool>; |
| 478 | template <> struct hash<char>; |
| 479 | template <> struct hash<signed char>; |
| 480 | template <> struct hash<unsigned char>; |
Yuriy Chernyshov | fbb87fa | 2020-12-08 13:39:56 -0500 | [diff] [blame] | 481 | template <> struct hash<char8_t>; // since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 482 | template <> struct hash<char16_t>; |
| 483 | template <> struct hash<char32_t>; |
| 484 | template <> struct hash<wchar_t>; |
| 485 | template <> struct hash<short>; |
| 486 | template <> struct hash<unsigned short>; |
| 487 | template <> struct hash<int>; |
| 488 | template <> struct hash<unsigned int>; |
| 489 | template <> struct hash<long>; |
| 490 | template <> struct hash<long long>; |
| 491 | template <> struct hash<unsigned long>; |
| 492 | template <> struct hash<unsigned long long>; |
| 493 | |
| 494 | template <> struct hash<float>; |
| 495 | template <> struct hash<double>; |
| 496 | template <> struct hash<long double>; |
| 497 | |
| 498 | template<class T> struct hash<T*>; |
Marshall Clow | cc25222 | 2017-03-23 06:20:18 +0000 | [diff] [blame] | 499 | template <> struct hash<nullptr_t>; // C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 500 | |
| 501 | } // std |
| 502 | |
| 503 | POLICY: For non-variadic implementations, the number of arguments is limited |
| 504 | to 3. It is hoped that the need for non-variadic implementations |
| 505 | will be minimal. |
| 506 | |
| 507 | */ |
| 508 | |
| 509 | #include <__config> |
Arthur O'Dwyer | 597cac4 | 2021-05-12 23:04:03 -0400 | [diff] [blame] | 510 | #include <__debug> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 511 | #include <__functional_base> |
zoecarver | 9ce102c | 2021-04-22 17:33:04 -0700 | [diff] [blame] | 512 | #include <concepts> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 513 | #include <exception> |
| 514 | #include <memory> |
| 515 | #include <tuple> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 516 | #include <type_traits> |
| 517 | #include <typeinfo> |
Eric Fiselier | 698a97b | 2017-01-21 00:02:12 +0000 | [diff] [blame] | 518 | #include <utility> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 519 | #include <version> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 520 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 521 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 522 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 523 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 524 | |
| 525 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 526 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 527 | #if _LIBCPP_STD_VER > 11 |
| 528 | template <class _Tp = void> |
| 529 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 530 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 531 | #endif |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 532 | struct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 533 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 534 | typedef _Tp __result_type; // used by valarray |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 535 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 536 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 537 | {return __x + __y;} |
| 538 | }; |
| 539 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 540 | #if _LIBCPP_STD_VER > 11 |
| 541 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 542 | struct _LIBCPP_TEMPLATE_VIS plus<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 543 | { |
| 544 | template <class _T1, class _T2> |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 545 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 546 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 547 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) |
| 548 | -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) |
| 549 | { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 550 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 551 | }; |
| 552 | #endif |
| 553 | |
| 554 | |
| 555 | #if _LIBCPP_STD_VER > 11 |
| 556 | template <class _Tp = void> |
| 557 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 558 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 559 | #endif |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 560 | struct _LIBCPP_TEMPLATE_VIS minus : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 561 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 562 | typedef _Tp __result_type; // used by valarray |
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 minus<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 multiplies : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 589 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 590 | typedef _Tp __result_type; // used by valarray |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 591 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 592 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 593 | {return __x * __y;} |
| 594 | }; |
| 595 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 596 | #if _LIBCPP_STD_VER > 11 |
| 597 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 598 | struct _LIBCPP_TEMPLATE_VIS multiplies<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 599 | { |
| 600 | template <class _T1, class _T2> |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 601 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 602 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 603 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))) |
| 604 | -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)) |
| 605 | { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 606 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 607 | }; |
| 608 | #endif |
| 609 | |
| 610 | |
| 611 | #if _LIBCPP_STD_VER > 11 |
| 612 | template <class _Tp = void> |
| 613 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 614 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 615 | #endif |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 616 | struct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 617 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 618 | typedef _Tp __result_type; // used by valarray |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 619 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 620 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 621 | {return __x / __y;} |
| 622 | }; |
| 623 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 624 | #if _LIBCPP_STD_VER > 11 |
| 625 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 626 | struct _LIBCPP_TEMPLATE_VIS divides<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 627 | { |
| 628 | template <class _T1, class _T2> |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 629 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 630 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 631 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))) |
| 632 | -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)) |
| 633 | { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 634 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 635 | }; |
| 636 | #endif |
| 637 | |
| 638 | |
| 639 | #if _LIBCPP_STD_VER > 11 |
| 640 | template <class _Tp = void> |
| 641 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 642 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 643 | #endif |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 644 | struct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 645 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 646 | typedef _Tp __result_type; // used by valarray |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 647 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 648 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 649 | {return __x % __y;} |
| 650 | }; |
| 651 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 652 | #if _LIBCPP_STD_VER > 11 |
| 653 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 654 | struct _LIBCPP_TEMPLATE_VIS modulus<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 655 | { |
| 656 | template <class _T1, class _T2> |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 657 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 658 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 659 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))) |
| 660 | -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)) |
| 661 | { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 662 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 663 | }; |
| 664 | #endif |
| 665 | |
| 666 | |
| 667 | #if _LIBCPP_STD_VER > 11 |
| 668 | template <class _Tp = void> |
| 669 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 670 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 671 | #endif |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 672 | struct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 673 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 674 | typedef _Tp __result_type; // used by valarray |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 675 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 676 | _Tp operator()(const _Tp& __x) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 677 | {return -__x;} |
| 678 | }; |
| 679 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 680 | #if _LIBCPP_STD_VER > 11 |
| 681 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 682 | struct _LIBCPP_TEMPLATE_VIS negate<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 683 | { |
| 684 | template <class _Tp> |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 685 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 686 | auto operator()(_Tp&& __x) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 687 | _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x))) |
| 688 | -> decltype (- _VSTD::forward<_Tp>(__x)) |
| 689 | { return - _VSTD::forward<_Tp>(__x); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 690 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 691 | }; |
| 692 | #endif |
| 693 | |
| 694 | |
| 695 | #if _LIBCPP_STD_VER > 11 |
| 696 | template <class _Tp = void> |
| 697 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 698 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 699 | #endif |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 700 | struct _LIBCPP_TEMPLATE_VIS equal_to : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 701 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 702 | typedef bool __result_type; // used by valarray |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 703 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 704 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 705 | {return __x == __y;} |
| 706 | }; |
| 707 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 708 | #if _LIBCPP_STD_VER > 11 |
| 709 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 710 | struct _LIBCPP_TEMPLATE_VIS equal_to<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 711 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 712 | template <class _T1, class _T2> |
| 713 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 714 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 715 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))) |
| 716 | -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)) |
| 717 | { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 718 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 719 | }; |
| 720 | #endif |
| 721 | |
| 722 | |
| 723 | #if _LIBCPP_STD_VER > 11 |
| 724 | template <class _Tp = void> |
| 725 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 726 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 727 | #endif |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 728 | struct _LIBCPP_TEMPLATE_VIS not_equal_to : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 729 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 730 | typedef bool __result_type; // used by valarray |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 731 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 732 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 733 | {return __x != __y;} |
| 734 | }; |
| 735 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 736 | #if _LIBCPP_STD_VER > 11 |
| 737 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 738 | struct _LIBCPP_TEMPLATE_VIS not_equal_to<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 739 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 740 | template <class _T1, class _T2> |
| 741 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 742 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 743 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))) |
| 744 | -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)) |
| 745 | { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 746 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 747 | }; |
| 748 | #endif |
| 749 | |
| 750 | |
| 751 | #if _LIBCPP_STD_VER > 11 |
| 752 | template <class _Tp = void> |
| 753 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 754 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 755 | #endif |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 756 | struct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 757 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 758 | typedef bool __result_type; // used by valarray |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 759 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 760 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 761 | {return __x > __y;} |
| 762 | }; |
| 763 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 764 | #if _LIBCPP_STD_VER > 11 |
| 765 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 766 | struct _LIBCPP_TEMPLATE_VIS greater<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 767 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 768 | template <class _T1, class _T2> |
| 769 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 770 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 771 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))) |
| 772 | -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)) |
| 773 | { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 774 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 775 | }; |
| 776 | #endif |
| 777 | |
| 778 | |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 779 | // less in <__functional_base> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 780 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 781 | #if _LIBCPP_STD_VER > 11 |
| 782 | template <class _Tp = void> |
| 783 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 784 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 785 | #endif |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 786 | struct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 787 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 788 | typedef bool __result_type; // used by valarray |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 789 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 790 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 791 | {return __x >= __y;} |
| 792 | }; |
| 793 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 794 | #if _LIBCPP_STD_VER > 11 |
| 795 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 796 | struct _LIBCPP_TEMPLATE_VIS greater_equal<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 797 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 798 | template <class _T1, class _T2> |
| 799 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 800 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 801 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))) |
| 802 | -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)) |
| 803 | { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 804 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 805 | }; |
| 806 | #endif |
| 807 | |
| 808 | |
| 809 | #if _LIBCPP_STD_VER > 11 |
| 810 | template <class _Tp = void> |
| 811 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 812 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 813 | #endif |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 814 | struct _LIBCPP_TEMPLATE_VIS less_equal : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 815 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 816 | typedef bool __result_type; // used by valarray |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 817 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 818 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 819 | {return __x <= __y;} |
| 820 | }; |
| 821 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 822 | #if _LIBCPP_STD_VER > 11 |
| 823 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 824 | struct _LIBCPP_TEMPLATE_VIS less_equal<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 825 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 826 | template <class _T1, class _T2> |
| 827 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 828 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 829 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))) |
| 830 | -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)) |
| 831 | { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 832 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 833 | }; |
| 834 | #endif |
| 835 | |
| 836 | |
| 837 | #if _LIBCPP_STD_VER > 11 |
| 838 | template <class _Tp = void> |
| 839 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 840 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 841 | #endif |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 842 | struct _LIBCPP_TEMPLATE_VIS logical_and : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 843 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 844 | typedef bool __result_type; // used by valarray |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 845 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 846 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 847 | {return __x && __y;} |
| 848 | }; |
| 849 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 850 | #if _LIBCPP_STD_VER > 11 |
| 851 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 852 | struct _LIBCPP_TEMPLATE_VIS logical_and<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 853 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 854 | template <class _T1, class _T2> |
| 855 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 856 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 857 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))) |
| 858 | -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)) |
| 859 | { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 860 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 861 | }; |
| 862 | #endif |
| 863 | |
| 864 | |
| 865 | #if _LIBCPP_STD_VER > 11 |
| 866 | template <class _Tp = void> |
| 867 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 868 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 869 | #endif |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 870 | struct _LIBCPP_TEMPLATE_VIS logical_or : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 871 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 872 | typedef bool __result_type; // used by valarray |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 873 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 874 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 875 | {return __x || __y;} |
| 876 | }; |
| 877 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 878 | #if _LIBCPP_STD_VER > 11 |
| 879 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 880 | struct _LIBCPP_TEMPLATE_VIS logical_or<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 881 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 882 | template <class _T1, class _T2> |
| 883 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 884 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 885 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))) |
| 886 | -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)) |
| 887 | { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 888 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 889 | }; |
| 890 | #endif |
| 891 | |
| 892 | |
| 893 | #if _LIBCPP_STD_VER > 11 |
| 894 | template <class _Tp = void> |
| 895 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 896 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 897 | #endif |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 898 | struct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 899 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 900 | typedef bool __result_type; // used by valarray |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 901 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 902 | bool operator()(const _Tp& __x) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 903 | {return !__x;} |
| 904 | }; |
| 905 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 906 | #if _LIBCPP_STD_VER > 11 |
| 907 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 908 | struct _LIBCPP_TEMPLATE_VIS logical_not<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 909 | { |
| 910 | template <class _Tp> |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 911 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 912 | auto operator()(_Tp&& __x) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 913 | _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x))) |
| 914 | -> decltype (!_VSTD::forward<_Tp>(__x)) |
| 915 | { return !_VSTD::forward<_Tp>(__x); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 916 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 917 | }; |
| 918 | #endif |
| 919 | |
| 920 | |
| 921 | #if _LIBCPP_STD_VER > 11 |
| 922 | template <class _Tp = void> |
| 923 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 924 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 925 | #endif |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 926 | struct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 927 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 928 | typedef _Tp __result_type; // used by valarray |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 929 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 930 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 931 | {return __x & __y;} |
| 932 | }; |
| 933 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 934 | #if _LIBCPP_STD_VER > 11 |
| 935 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 936 | struct _LIBCPP_TEMPLATE_VIS bit_and<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 937 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 938 | template <class _T1, class _T2> |
| 939 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 940 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 941 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))) |
| 942 | -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)) |
| 943 | { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 944 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 945 | }; |
| 946 | #endif |
| 947 | |
| 948 | |
| 949 | #if _LIBCPP_STD_VER > 11 |
| 950 | template <class _Tp = void> |
| 951 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 952 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 953 | #endif |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 954 | struct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 955 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 956 | typedef _Tp __result_type; // used by valarray |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 957 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 958 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 959 | {return __x | __y;} |
| 960 | }; |
| 961 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 962 | #if _LIBCPP_STD_VER > 11 |
| 963 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 964 | struct _LIBCPP_TEMPLATE_VIS bit_or<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 965 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 966 | template <class _T1, class _T2> |
| 967 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 968 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 969 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))) |
| 970 | -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)) |
| 971 | { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 972 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 973 | }; |
| 974 | #endif |
| 975 | |
| 976 | |
| 977 | #if _LIBCPP_STD_VER > 11 |
| 978 | template <class _Tp = void> |
| 979 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 980 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 981 | #endif |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 982 | struct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 983 | { |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame^] | 984 | typedef _Tp __result_type; // used by valarray |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 985 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 986 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 987 | {return __x ^ __y;} |
| 988 | }; |
| 989 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 990 | #if _LIBCPP_STD_VER > 11 |
| 991 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 992 | struct _LIBCPP_TEMPLATE_VIS bit_xor<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 993 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 994 | template <class _T1, class _T2> |
| 995 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 996 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 997 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))) |
| 998 | -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)) |
| 999 | { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 1000 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1001 | }; |
| 1002 | #endif |
| 1003 | |
| 1004 | |
| 1005 | #if _LIBCPP_STD_VER > 11 |
| 1006 | template <class _Tp = void> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1007 | struct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1008 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1009 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1010 | _Tp operator()(const _Tp& __x) const |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1011 | {return ~__x;} |
| 1012 | }; |
| 1013 | |
| 1014 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1015 | struct _LIBCPP_TEMPLATE_VIS bit_not<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1016 | { |
| 1017 | template <class _Tp> |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1018 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1019 | auto operator()(_Tp&& __x) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 1020 | _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x))) |
| 1021 | -> decltype (~_VSTD::forward<_Tp>(__x)) |
| 1022 | { return ~_VSTD::forward<_Tp>(__x); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 1023 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1024 | }; |
| 1025 | #endif |
| 1026 | |
Arthur O'Dwyer | a6b5107 | 2021-05-24 18:36:17 -0400 | [diff] [blame] | 1027 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1028 | template <class _Predicate> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1029 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1030 | : public unary_function<typename _Predicate::argument_type, bool> |
| 1031 | { |
| 1032 | _Predicate __pred_; |
| 1033 | public: |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1034 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1035 | explicit unary_negate(const _Predicate& __pred) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1036 | : __pred_(__pred) {} |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1037 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1038 | bool operator()(const typename _Predicate::argument_type& __x) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1039 | {return !__pred_(__x);} |
| 1040 | }; |
| 1041 | |
| 1042 | template <class _Predicate> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1043 | _LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1044 | unary_negate<_Predicate> |
| 1045 | not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} |
| 1046 | |
| 1047 | template <class _Predicate> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1048 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1049 | : public binary_function<typename _Predicate::first_argument_type, |
| 1050 | typename _Predicate::second_argument_type, |
| 1051 | bool> |
| 1052 | { |
| 1053 | _Predicate __pred_; |
| 1054 | public: |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 1055 | _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1056 | binary_negate(const _Predicate& __pred) : __pred_(__pred) {} |
| 1057 | |
| 1058 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1059 | bool operator()(const typename _Predicate::first_argument_type& __x, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1060 | const typename _Predicate::second_argument_type& __y) const |
| 1061 | {return !__pred_(__x, __y);} |
| 1062 | }; |
| 1063 | |
| 1064 | template <class _Predicate> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1065 | _LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1066 | binary_negate<_Predicate> |
| 1067 | not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} |
Arthur O'Dwyer | a6b5107 | 2021-05-24 18:36:17 -0400 | [diff] [blame] | 1068 | #endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1069 | |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 1070 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1071 | template <class __Operation> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1072 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1073 | : public unary_function<typename __Operation::second_argument_type, |
| 1074 | typename __Operation::result_type> |
| 1075 | { |
| 1076 | protected: |
| 1077 | __Operation op; |
| 1078 | typename __Operation::first_argument_type value; |
| 1079 | public: |
| 1080 | _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x, |
| 1081 | const typename __Operation::first_argument_type __y) |
| 1082 | : op(__x), value(__y) {} |
| 1083 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 1084 | (typename __Operation::second_argument_type& __x) const |
| 1085 | {return op(value, __x);} |
| 1086 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 1087 | (const typename __Operation::second_argument_type& __x) const |
| 1088 | {return op(value, __x);} |
| 1089 | }; |
| 1090 | |
| 1091 | template <class __Operation, class _Tp> |
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 | binder1st<__Operation> |
| 1094 | bind1st(const __Operation& __op, const _Tp& __x) |
| 1095 | {return binder1st<__Operation>(__op, __x);} |
| 1096 | |
| 1097 | template <class __Operation> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1098 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1099 | : public unary_function<typename __Operation::first_argument_type, |
| 1100 | typename __Operation::result_type> |
| 1101 | { |
| 1102 | protected: |
| 1103 | __Operation op; |
| 1104 | typename __Operation::second_argument_type value; |
| 1105 | public: |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1106 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1107 | binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) |
| 1108 | : op(__x), value(__y) {} |
| 1109 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 1110 | ( typename __Operation::first_argument_type& __x) const |
| 1111 | {return op(__x, value);} |
| 1112 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 1113 | (const typename __Operation::first_argument_type& __x) const |
| 1114 | {return op(__x, value);} |
| 1115 | }; |
| 1116 | |
| 1117 | template <class __Operation, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1118 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1119 | binder2nd<__Operation> |
| 1120 | bind2nd(const __Operation& __op, const _Tp& __x) |
| 1121 | {return binder2nd<__Operation>(__op, __x);} |
| 1122 | |
| 1123 | template <class _Arg, class _Result> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1124 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1125 | : public unary_function<_Arg, _Result> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1126 | { |
| 1127 | _Result (*__f_)(_Arg); |
| 1128 | public: |
| 1129 | _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) |
| 1130 | : __f_(__f) {} |
| 1131 | _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const |
| 1132 | {return __f_(__x);} |
| 1133 | }; |
| 1134 | |
| 1135 | template <class _Arg, class _Result> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1136 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1137 | pointer_to_unary_function<_Arg,_Result> |
| 1138 | ptr_fun(_Result (*__f)(_Arg)) |
| 1139 | {return pointer_to_unary_function<_Arg,_Result>(__f);} |
| 1140 | |
| 1141 | template <class _Arg1, class _Arg2, class _Result> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1142 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1143 | : public binary_function<_Arg1, _Arg2, _Result> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1144 | { |
| 1145 | _Result (*__f_)(_Arg1, _Arg2); |
| 1146 | public: |
| 1147 | _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) |
| 1148 | : __f_(__f) {} |
| 1149 | _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const |
| 1150 | {return __f_(__x, __y);} |
| 1151 | }; |
| 1152 | |
| 1153 | template <class _Arg1, class _Arg2, class _Result> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1154 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1155 | pointer_to_binary_function<_Arg1,_Arg2,_Result> |
| 1156 | ptr_fun(_Result (*__f)(_Arg1,_Arg2)) |
| 1157 | {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} |
| 1158 | |
| 1159 | template<class _Sp, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1160 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t |
| 1161 | : public unary_function<_Tp*, _Sp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1162 | { |
| 1163 | _Sp (_Tp::*__p_)(); |
| 1164 | public: |
| 1165 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) |
| 1166 | : __p_(__p) {} |
| 1167 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const |
| 1168 | {return (__p->*__p_)();} |
| 1169 | }; |
| 1170 | |
| 1171 | template<class _Sp, class _Tp, class _Ap> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1172 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t |
| 1173 | : public binary_function<_Tp*, _Ap, _Sp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1174 | { |
| 1175 | _Sp (_Tp::*__p_)(_Ap); |
| 1176 | public: |
| 1177 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) |
| 1178 | : __p_(__p) {} |
| 1179 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const |
| 1180 | {return (__p->*__p_)(__x);} |
| 1181 | }; |
| 1182 | |
| 1183 | template<class _Sp, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1184 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1185 | mem_fun_t<_Sp,_Tp> |
| 1186 | mem_fun(_Sp (_Tp::*__f)()) |
| 1187 | {return mem_fun_t<_Sp,_Tp>(__f);} |
| 1188 | |
| 1189 | template<class _Sp, class _Tp, class _Ap> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1190 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1191 | mem_fun1_t<_Sp,_Tp,_Ap> |
| 1192 | mem_fun(_Sp (_Tp::*__f)(_Ap)) |
| 1193 | {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} |
| 1194 | |
| 1195 | template<class _Sp, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1196 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t |
| 1197 | : public unary_function<_Tp, _Sp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1198 | { |
| 1199 | _Sp (_Tp::*__p_)(); |
| 1200 | public: |
| 1201 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) |
| 1202 | : __p_(__p) {} |
| 1203 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const |
| 1204 | {return (__p.*__p_)();} |
| 1205 | }; |
| 1206 | |
| 1207 | template<class _Sp, class _Tp, class _Ap> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1208 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t |
| 1209 | : public binary_function<_Tp, _Ap, _Sp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1210 | { |
| 1211 | _Sp (_Tp::*__p_)(_Ap); |
| 1212 | public: |
| 1213 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) |
| 1214 | : __p_(__p) {} |
| 1215 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const |
| 1216 | {return (__p.*__p_)(__x);} |
| 1217 | }; |
| 1218 | |
| 1219 | template<class _Sp, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1220 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1221 | mem_fun_ref_t<_Sp,_Tp> |
| 1222 | mem_fun_ref(_Sp (_Tp::*__f)()) |
| 1223 | {return mem_fun_ref_t<_Sp,_Tp>(__f);} |
| 1224 | |
| 1225 | template<class _Sp, class _Tp, class _Ap> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1226 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1227 | mem_fun1_ref_t<_Sp,_Tp,_Ap> |
| 1228 | mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) |
| 1229 | {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} |
| 1230 | |
| 1231 | template <class _Sp, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1232 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t |
| 1233 | : public unary_function<const _Tp*, _Sp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1234 | { |
| 1235 | _Sp (_Tp::*__p_)() const; |
| 1236 | public: |
| 1237 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) |
| 1238 | : __p_(__p) {} |
| 1239 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const |
| 1240 | {return (__p->*__p_)();} |
| 1241 | }; |
| 1242 | |
| 1243 | template <class _Sp, class _Tp, class _Ap> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1244 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t |
| 1245 | : public binary_function<const _Tp*, _Ap, _Sp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1246 | { |
| 1247 | _Sp (_Tp::*__p_)(_Ap) const; |
| 1248 | public: |
| 1249 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) |
| 1250 | : __p_(__p) {} |
| 1251 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const |
| 1252 | {return (__p->*__p_)(__x);} |
| 1253 | }; |
| 1254 | |
| 1255 | template <class _Sp, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1256 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1257 | const_mem_fun_t<_Sp,_Tp> |
| 1258 | mem_fun(_Sp (_Tp::*__f)() const) |
| 1259 | {return const_mem_fun_t<_Sp,_Tp>(__f);} |
| 1260 | |
| 1261 | template <class _Sp, class _Tp, class _Ap> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1262 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1263 | const_mem_fun1_t<_Sp,_Tp,_Ap> |
| 1264 | mem_fun(_Sp (_Tp::*__f)(_Ap) const) |
| 1265 | {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} |
| 1266 | |
| 1267 | template <class _Sp, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1268 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t |
| 1269 | : public unary_function<_Tp, _Sp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1270 | { |
| 1271 | _Sp (_Tp::*__p_)() const; |
| 1272 | public: |
| 1273 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) |
| 1274 | : __p_(__p) {} |
| 1275 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const |
| 1276 | {return (__p.*__p_)();} |
| 1277 | }; |
| 1278 | |
| 1279 | template <class _Sp, class _Tp, class _Ap> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1280 | 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] | 1281 | : public binary_function<_Tp, _Ap, _Sp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1282 | { |
| 1283 | _Sp (_Tp::*__p_)(_Ap) const; |
| 1284 | public: |
| 1285 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) |
| 1286 | : __p_(__p) {} |
| 1287 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const |
| 1288 | {return (__p.*__p_)(__x);} |
| 1289 | }; |
| 1290 | |
| 1291 | template <class _Sp, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1292 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1293 | const_mem_fun_ref_t<_Sp,_Tp> |
| 1294 | mem_fun_ref(_Sp (_Tp::*__f)() const) |
| 1295 | {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} |
| 1296 | |
| 1297 | template <class _Sp, class _Tp, class _Ap> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1298 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1299 | const_mem_fun1_ref_t<_Sp,_Tp,_Ap> |
| 1300 | mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) |
| 1301 | {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 1302 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1303 | |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1304 | //////////////////////////////////////////////////////////////////////////////// |
| 1305 | // MEMFUN |
| 1306 | //============================================================================== |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1307 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1308 | template <class _Tp> |
| 1309 | class __mem_fn |
| 1310 | : public __weak_result_type<_Tp> |
| 1311 | { |
| 1312 | public: |
| 1313 | // types |
| 1314 | typedef _Tp type; |
| 1315 | private: |
| 1316 | type __f_; |
| 1317 | |
| 1318 | public: |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 1319 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 1320 | __mem_fn(type __f) _NOEXCEPT : __f_(__f) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1321 | |
Eric Fiselier | a9ae7a6 | 2017-04-19 01:28:47 +0000 | [diff] [blame] | 1322 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1323 | // invoke |
| 1324 | template <class... _ArgTypes> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 1325 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1326 | typename __invoke_return<type, _ArgTypes...>::type |
| 1327 | operator() (_ArgTypes&&... __args) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1328 | return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...); |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1329 | } |
| 1330 | #else |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1331 | |
| 1332 | template <class _A0> |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1333 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1334 | typename __invoke_return0<type, _A0>::type |
| 1335 | operator() (_A0& __a0) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1336 | return _VSTD::__invoke(__f_, __a0); |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1339 | template <class _A0> |
| 1340 | _LIBCPP_INLINE_VISIBILITY |
| 1341 | typename __invoke_return0<type, _A0 const>::type |
| 1342 | operator() (_A0 const& __a0) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1343 | return _VSTD::__invoke(__f_, __a0); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1344 | } |
| 1345 | |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1346 | template <class _A0, class _A1> |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1347 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1348 | typename __invoke_return1<type, _A0, _A1>::type |
| 1349 | operator() (_A0& __a0, _A1& __a1) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1350 | return _VSTD::__invoke(__f_, __a0, __a1); |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1351 | } |
| 1352 | |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1353 | template <class _A0, class _A1> |
| 1354 | _LIBCPP_INLINE_VISIBILITY |
| 1355 | typename __invoke_return1<type, _A0 const, _A1>::type |
| 1356 | operator() (_A0 const& __a0, _A1& __a1) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1357 | return _VSTD::__invoke(__f_, __a0, __a1); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | template <class _A0, class _A1> |
| 1361 | _LIBCPP_INLINE_VISIBILITY |
| 1362 | typename __invoke_return1<type, _A0, _A1 const>::type |
| 1363 | operator() (_A0& __a0, _A1 const& __a1) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1364 | return _VSTD::__invoke(__f_, __a0, __a1); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | template <class _A0, class _A1> |
| 1368 | _LIBCPP_INLINE_VISIBILITY |
| 1369 | typename __invoke_return1<type, _A0 const, _A1 const>::type |
| 1370 | operator() (_A0 const& __a0, _A1 const& __a1) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1371 | return _VSTD::__invoke(__f_, __a0, __a1); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1374 | template <class _A0, class _A1, class _A2> |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1375 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1376 | typename __invoke_return2<type, _A0, _A1, _A2>::type |
| 1377 | operator() (_A0& __a0, _A1& __a1, _A2& __a2) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1378 | return _VSTD::__invoke(__f_, __a0, __a1, __a2); |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1379 | } |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1380 | |
| 1381 | template <class _A0, class _A1, class _A2> |
| 1382 | _LIBCPP_INLINE_VISIBILITY |
| 1383 | typename __invoke_return2<type, _A0 const, _A1, _A2>::type |
| 1384 | operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1385 | return _VSTD::__invoke(__f_, __a0, __a1, __a2); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | template <class _A0, class _A1, class _A2> |
| 1389 | _LIBCPP_INLINE_VISIBILITY |
| 1390 | typename __invoke_return2<type, _A0, _A1 const, _A2>::type |
| 1391 | operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1392 | return _VSTD::__invoke(__f_, __a0, __a1, __a2); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | template <class _A0, class _A1, class _A2> |
| 1396 | _LIBCPP_INLINE_VISIBILITY |
| 1397 | typename __invoke_return2<type, _A0, _A1, _A2 const>::type |
| 1398 | operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1399 | return _VSTD::__invoke(__f_, __a0, __a1, __a2); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | template <class _A0, class _A1, class _A2> |
| 1403 | _LIBCPP_INLINE_VISIBILITY |
| 1404 | typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type |
| 1405 | operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1406 | return _VSTD::__invoke(__f_, __a0, __a1, __a2); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | template <class _A0, class _A1, class _A2> |
| 1410 | _LIBCPP_INLINE_VISIBILITY |
| 1411 | typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type |
| 1412 | operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1413 | return _VSTD::__invoke(__f_, __a0, __a1, __a2); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | template <class _A0, class _A1, class _A2> |
| 1417 | _LIBCPP_INLINE_VISIBILITY |
| 1418 | typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type |
| 1419 | operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1420 | return _VSTD::__invoke(__f_, __a0, __a1, __a2); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | template <class _A0, class _A1, class _A2> |
| 1424 | _LIBCPP_INLINE_VISIBILITY |
| 1425 | typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type |
| 1426 | operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1427 | return _VSTD::__invoke(__f_, __a0, __a1, __a2); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1428 | } |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1429 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1430 | }; |
| 1431 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1432 | template<class _Rp, class _Tp> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 1433 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1434 | __mem_fn<_Rp _Tp::*> |
Marshall Clow | ad8ff21 | 2015-10-25 20:12:16 +0000 | [diff] [blame] | 1435 | mem_fn(_Rp _Tp::* __pm) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1436 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1437 | return __mem_fn<_Rp _Tp::*>(__pm); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1440 | //////////////////////////////////////////////////////////////////////////////// |
| 1441 | // FUNCTION |
| 1442 | //============================================================================== |
| 1443 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1444 | // bad_function_call |
| 1445 | |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1446 | class _LIBCPP_EXCEPTION_ABI bad_function_call |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1447 | : public exception |
| 1448 | { |
Shoaib Meenai | c130eaf | 2017-03-28 19:33:31 +0000 | [diff] [blame] | 1449 | #ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION |
| 1450 | public: |
| 1451 | virtual ~bad_function_call() _NOEXCEPT; |
| 1452 | |
| 1453 | virtual const char* what() const _NOEXCEPT; |
| 1454 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1455 | }; |
| 1456 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1457 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 1458 | void __throw_bad_function_call() |
| 1459 | { |
| 1460 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1461 | throw bad_function_call(); |
| 1462 | #else |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 1463 | _VSTD::abort(); |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 1464 | #endif |
| 1465 | } |
| 1466 | |
Louis Dionne | 44d1f81 | 2020-03-09 11:16:22 -0400 | [diff] [blame] | 1467 | #if defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && __has_attribute(deprecated) |
| 1468 | # define _LIBCPP_DEPRECATED_CXX03_FUNCTION \ |
| 1469 | __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a different type"))) |
| 1470 | #else |
| 1471 | # define _LIBCPP_DEPRECATED_CXX03_FUNCTION /* nothing */ |
| 1472 | #endif |
| 1473 | |
| 1474 | template<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function; // undefined |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1475 | |
| 1476 | namespace __function |
| 1477 | { |
| 1478 | |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1479 | template<class _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1480 | struct __maybe_derive_from_unary_function |
| 1481 | { |
| 1482 | }; |
| 1483 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1484 | template<class _Rp, class _A1> |
| 1485 | struct __maybe_derive_from_unary_function<_Rp(_A1)> |
| 1486 | : public unary_function<_A1, _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1487 | { |
| 1488 | }; |
| 1489 | |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1490 | template<class _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1491 | struct __maybe_derive_from_binary_function |
| 1492 | { |
| 1493 | }; |
| 1494 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1495 | template<class _Rp, class _A1, class _A2> |
| 1496 | struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> |
| 1497 | : public binary_function<_A1, _A2, _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1498 | { |
| 1499 | }; |
| 1500 | |
Eric Fiselier | a584a1e | 2015-08-18 19:41:51 +0000 | [diff] [blame] | 1501 | template <class _Fp> |
| 1502 | _LIBCPP_INLINE_VISIBILITY |
| 1503 | bool __not_null(_Fp const&) { return true; } |
| 1504 | |
| 1505 | template <class _Fp> |
| 1506 | _LIBCPP_INLINE_VISIBILITY |
| 1507 | bool __not_null(_Fp* __ptr) { return __ptr; } |
| 1508 | |
| 1509 | template <class _Ret, class _Class> |
| 1510 | _LIBCPP_INLINE_VISIBILITY |
| 1511 | bool __not_null(_Ret _Class::*__ptr) { return __ptr; } |
| 1512 | |
| 1513 | template <class _Fp> |
| 1514 | _LIBCPP_INLINE_VISIBILITY |
| 1515 | bool __not_null(function<_Fp> const& __f) { return !!__f; } |
| 1516 | |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 1517 | #ifdef _LIBCPP_HAS_EXTENSION_BLOCKS |
| 1518 | template <class _Rp, class ..._Args> |
| 1519 | _LIBCPP_INLINE_VISIBILITY |
| 1520 | bool __not_null(_Rp (^__p)(_Args...)) { return __p; } |
| 1521 | #endif |
| 1522 | |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1523 | } // namespace __function |
| 1524 | |
Eric Fiselier | a9ae7a6 | 2017-04-19 01:28:47 +0000 | [diff] [blame] | 1525 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1526 | |
| 1527 | namespace __function { |
| 1528 | |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1529 | // __alloc_func holds a functor and an allocator. |
| 1530 | |
| 1531 | template <class _Fp, class _Ap, class _FB> class __alloc_func; |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 1532 | template <class _Fp, class _FB> |
| 1533 | class __default_alloc_func; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1534 | |
| 1535 | template <class _Fp, class _Ap, class _Rp, class... _ArgTypes> |
| 1536 | class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> |
| 1537 | { |
| 1538 | __compressed_pair<_Fp, _Ap> __f_; |
| 1539 | |
| 1540 | public: |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1541 | typedef _LIBCPP_NODEBUG_TYPE _Fp _Target; |
| 1542 | typedef _LIBCPP_NODEBUG_TYPE _Ap _Alloc; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1543 | |
| 1544 | _LIBCPP_INLINE_VISIBILITY |
| 1545 | const _Target& __target() const { return __f_.first(); } |
| 1546 | |
Thomas Anderson | f88da8d | 2019-01-29 23:19:45 +0000 | [diff] [blame] | 1547 | // WIN32 APIs may define __allocator, so use __get_allocator instead. |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1548 | _LIBCPP_INLINE_VISIBILITY |
Thomas Anderson | f88da8d | 2019-01-29 23:19:45 +0000 | [diff] [blame] | 1549 | const _Alloc& __get_allocator() const { return __f_.second(); } |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1550 | |
| 1551 | _LIBCPP_INLINE_VISIBILITY |
| 1552 | explicit __alloc_func(_Target&& __f) |
| 1553 | : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), |
| 1554 | _VSTD::forward_as_tuple()) |
| 1555 | { |
| 1556 | } |
| 1557 | |
| 1558 | _LIBCPP_INLINE_VISIBILITY |
| 1559 | explicit __alloc_func(const _Target& __f, const _Alloc& __a) |
| 1560 | : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), |
| 1561 | _VSTD::forward_as_tuple(__a)) |
| 1562 | { |
| 1563 | } |
| 1564 | |
| 1565 | _LIBCPP_INLINE_VISIBILITY |
| 1566 | explicit __alloc_func(const _Target& __f, _Alloc&& __a) |
| 1567 | : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), |
| 1568 | _VSTD::forward_as_tuple(_VSTD::move(__a))) |
| 1569 | { |
| 1570 | } |
| 1571 | |
| 1572 | _LIBCPP_INLINE_VISIBILITY |
| 1573 | explicit __alloc_func(_Target&& __f, _Alloc&& __a) |
| 1574 | : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), |
| 1575 | _VSTD::forward_as_tuple(_VSTD::move(__a))) |
| 1576 | { |
| 1577 | } |
| 1578 | |
| 1579 | _LIBCPP_INLINE_VISIBILITY |
| 1580 | _Rp operator()(_ArgTypes&&... __arg) |
| 1581 | { |
| 1582 | typedef __invoke_void_return_wrapper<_Rp> _Invoker; |
| 1583 | return _Invoker::__call(__f_.first(), |
| 1584 | _VSTD::forward<_ArgTypes>(__arg)...); |
| 1585 | } |
| 1586 | |
| 1587 | _LIBCPP_INLINE_VISIBILITY |
| 1588 | __alloc_func* __clone() const |
| 1589 | { |
| 1590 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 1591 | typedef |
| 1592 | typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type |
| 1593 | _AA; |
| 1594 | _AA __a(__f_.second()); |
| 1595 | typedef __allocator_destructor<_AA> _Dp; |
| 1596 | unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
| 1597 | ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a)); |
| 1598 | return __hold.release(); |
| 1599 | } |
| 1600 | |
| 1601 | _LIBCPP_INLINE_VISIBILITY |
| 1602 | void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); } |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 1603 | |
| 1604 | static void __destroy_and_delete(__alloc_func* __f) { |
| 1605 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 1606 | typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type |
| 1607 | _FunAlloc; |
| 1608 | _FunAlloc __a(__f->__get_allocator()); |
| 1609 | __f->destroy(); |
| 1610 | __a.deallocate(__f, 1); |
| 1611 | } |
| 1612 | }; |
| 1613 | |
| 1614 | template <class _Fp, class _Rp, class... _ArgTypes> |
| 1615 | class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> { |
| 1616 | _Fp __f_; |
| 1617 | |
| 1618 | public: |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1619 | typedef _LIBCPP_NODEBUG_TYPE _Fp _Target; |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 1620 | |
| 1621 | _LIBCPP_INLINE_VISIBILITY |
| 1622 | const _Target& __target() const { return __f_; } |
| 1623 | |
| 1624 | _LIBCPP_INLINE_VISIBILITY |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 1625 | explicit __default_alloc_func(_Target&& __f) : __f_(_VSTD::move(__f)) {} |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 1626 | |
| 1627 | _LIBCPP_INLINE_VISIBILITY |
| 1628 | explicit __default_alloc_func(const _Target& __f) : __f_(__f) {} |
| 1629 | |
| 1630 | _LIBCPP_INLINE_VISIBILITY |
| 1631 | _Rp operator()(_ArgTypes&&... __arg) { |
| 1632 | typedef __invoke_void_return_wrapper<_Rp> _Invoker; |
| 1633 | return _Invoker::__call(__f_, _VSTD::forward<_ArgTypes>(__arg)...); |
| 1634 | } |
| 1635 | |
| 1636 | _LIBCPP_INLINE_VISIBILITY |
| 1637 | __default_alloc_func* __clone() const { |
| 1638 | __builtin_new_allocator::__holder_t __hold = |
| 1639 | __builtin_new_allocator::__allocate_type<__default_alloc_func>(1); |
| 1640 | __default_alloc_func* __res = |
Arthur O'Dwyer | 0c4472a | 2020-12-11 20:30:28 -0500 | [diff] [blame] | 1641 | ::new ((void*)__hold.get()) __default_alloc_func(__f_); |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 1642 | (void)__hold.release(); |
| 1643 | return __res; |
| 1644 | } |
| 1645 | |
| 1646 | _LIBCPP_INLINE_VISIBILITY |
| 1647 | void destroy() _NOEXCEPT { __f_.~_Target(); } |
| 1648 | |
| 1649 | static void __destroy_and_delete(__default_alloc_func* __f) { |
| 1650 | __f->destroy(); |
| 1651 | __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1); |
| 1652 | } |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1653 | }; |
| 1654 | |
| 1655 | // __base provides an abstract interface for copyable functors. |
| 1656 | |
Yunlian Jiang | 06c6f27 | 2020-03-18 17:06:18 -0400 | [diff] [blame] | 1657 | template<class _Fp> class _LIBCPP_TEMPLATE_VIS __base; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1658 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1659 | template<class _Rp, class ..._ArgTypes> |
| 1660 | class __base<_Rp(_ArgTypes...)> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1661 | { |
| 1662 | __base(const __base&); |
| 1663 | __base& operator=(const __base&); |
| 1664 | public: |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1665 | _LIBCPP_INLINE_VISIBILITY __base() {} |
| 1666 | _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1667 | virtual __base* __clone() const = 0; |
| 1668 | virtual void __clone(__base*) const = 0; |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1669 | virtual void destroy() _NOEXCEPT = 0; |
| 1670 | virtual void destroy_deallocate() _NOEXCEPT = 0; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1671 | virtual _Rp operator()(_ArgTypes&& ...) = 0; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1672 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1673 | virtual const void* target(const type_info&) const _NOEXCEPT = 0; |
| 1674 | virtual const std::type_info& target_type() const _NOEXCEPT = 0; |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1675 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1676 | }; |
| 1677 | |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1678 | // __func implements __base for a given functor type. |
| 1679 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1680 | template<class _FD, class _Alloc, class _FB> class __func; |
| 1681 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1682 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 1683 | class __func<_Fp, _Alloc, _Rp(_ArgTypes...)> |
| 1684 | : public __base<_Rp(_ArgTypes...)> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1685 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1686 | __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1687 | public: |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1688 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4828c4a | 2012-02-28 19:47:38 +0000 | [diff] [blame] | 1689 | explicit __func(_Fp&& __f) |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1690 | : __f_(_VSTD::move(__f)) {} |
| 1691 | |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1692 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4828c4a | 2012-02-28 19:47:38 +0000 | [diff] [blame] | 1693 | explicit __func(const _Fp& __f, const _Alloc& __a) |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1694 | : __f_(__f, __a) {} |
Howard Hinnant | 4828c4a | 2012-02-28 19:47:38 +0000 | [diff] [blame] | 1695 | |
| 1696 | _LIBCPP_INLINE_VISIBILITY |
| 1697 | explicit __func(const _Fp& __f, _Alloc&& __a) |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1698 | : __f_(__f, _VSTD::move(__a)) {} |
Howard Hinnant | 4828c4a | 2012-02-28 19:47:38 +0000 | [diff] [blame] | 1699 | |
| 1700 | _LIBCPP_INLINE_VISIBILITY |
| 1701 | explicit __func(_Fp&& __f, _Alloc&& __a) |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1702 | : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} |
| 1703 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1704 | virtual __base<_Rp(_ArgTypes...)>* __clone() const; |
| 1705 | virtual void __clone(__base<_Rp(_ArgTypes...)>*) const; |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1706 | virtual void destroy() _NOEXCEPT; |
| 1707 | virtual void destroy_deallocate() _NOEXCEPT; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1708 | virtual _Rp operator()(_ArgTypes&&... __arg); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1709 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1710 | virtual const void* target(const type_info&) const _NOEXCEPT; |
| 1711 | virtual const std::type_info& target_type() const _NOEXCEPT; |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1712 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1713 | }; |
| 1714 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1715 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 1716 | __base<_Rp(_ArgTypes...)>* |
| 1717 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1718 | { |
Eric Fiselier | b5826ad | 2015-03-18 22:56:50 +0000 | [diff] [blame] | 1719 | typedef allocator_traits<_Alloc> __alloc_traits; |
Marshall Clow | 940e01c | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1720 | typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; |
Thomas Anderson | f88da8d | 2019-01-29 23:19:45 +0000 | [diff] [blame] | 1721 | _Ap __a(__f_.__get_allocator()); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1722 | typedef __allocator_destructor<_Ap> _Dp; |
| 1723 | unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1724 | ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1725 | return __hold.release(); |
| 1726 | } |
| 1727 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1728 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1729 | void |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1730 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1731 | { |
Arthur O'Dwyer | 0c4472a | 2020-12-11 20:30:28 -0500 | [diff] [blame] | 1732 | ::new ((void*)__p) __func(__f_.__target(), __f_.__get_allocator()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1733 | } |
| 1734 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1735 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1736 | void |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1737 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1738 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1739 | __f_.destroy(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1740 | } |
| 1741 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1742 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1743 | void |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1744 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1745 | { |
Eric Fiselier | b5826ad | 2015-03-18 22:56:50 +0000 | [diff] [blame] | 1746 | typedef allocator_traits<_Alloc> __alloc_traits; |
Marshall Clow | 940e01c | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1747 | typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; |
Thomas Anderson | f88da8d | 2019-01-29 23:19:45 +0000 | [diff] [blame] | 1748 | _Ap __a(__f_.__get_allocator()); |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1749 | __f_.destroy(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1750 | __a.deallocate(this, 1); |
| 1751 | } |
| 1752 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1753 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 1754 | _Rp |
| 1755 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1756 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1757 | return __f_(_VSTD::forward<_ArgTypes>(__arg)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1760 | #ifndef _LIBCPP_NO_RTTI |
| 1761 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1762 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1763 | const void* |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1764 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1765 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1766 | if (__ti == typeid(_Fp)) |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1767 | return &__f_.__target(); |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1768 | return nullptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1769 | } |
| 1770 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1771 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1772 | const std::type_info& |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1773 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1774 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1775 | return typeid(_Fp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1778 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1779 | |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1780 | // __value_func creates a value-type from a __func. |
| 1781 | |
| 1782 | template <class _Fp> class __value_func; |
| 1783 | |
| 1784 | template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)> |
| 1785 | { |
| 1786 | typename aligned_storage<3 * sizeof(void*)>::type __buf_; |
| 1787 | |
| 1788 | typedef __base<_Rp(_ArgTypes...)> __func; |
| 1789 | __func* __f_; |
| 1790 | |
| 1791 | _LIBCPP_NO_CFI static __func* __as_base(void* p) |
| 1792 | { |
| 1793 | return reinterpret_cast<__func*>(p); |
| 1794 | } |
| 1795 | |
| 1796 | public: |
| 1797 | _LIBCPP_INLINE_VISIBILITY |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1798 | __value_func() _NOEXCEPT : __f_(nullptr) {} |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1799 | |
| 1800 | template <class _Fp, class _Alloc> |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 1801 | _LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a) |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1802 | : __f_(nullptr) |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1803 | { |
| 1804 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 1805 | typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; |
| 1806 | typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type |
| 1807 | _FunAlloc; |
| 1808 | |
| 1809 | if (__function::__not_null(__f)) |
| 1810 | { |
| 1811 | _FunAlloc __af(__a); |
| 1812 | if (sizeof(_Fun) <= sizeof(__buf_) && |
| 1813 | is_nothrow_copy_constructible<_Fp>::value && |
| 1814 | is_nothrow_copy_constructible<_FunAlloc>::value) |
| 1815 | { |
| 1816 | __f_ = |
| 1817 | ::new ((void*)&__buf_) _Fun(_VSTD::move(__f), _Alloc(__af)); |
| 1818 | } |
| 1819 | else |
| 1820 | { |
| 1821 | typedef __allocator_destructor<_FunAlloc> _Dp; |
| 1822 | unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1)); |
| 1823 | ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f), _Alloc(__a)); |
| 1824 | __f_ = __hold.release(); |
| 1825 | } |
| 1826 | } |
| 1827 | } |
| 1828 | |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 1829 | template <class _Fp, |
| 1830 | class = typename enable_if<!is_same<typename decay<_Fp>::type, __value_func>::value>::type> |
| 1831 | _LIBCPP_INLINE_VISIBILITY explicit __value_func(_Fp&& __f) |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 1832 | : __value_func(_VSTD::forward<_Fp>(__f), allocator<_Fp>()) {} |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 1833 | |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1834 | _LIBCPP_INLINE_VISIBILITY |
| 1835 | __value_func(const __value_func& __f) |
| 1836 | { |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1837 | if (__f.__f_ == nullptr) |
| 1838 | __f_ = nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1839 | else if ((void*)__f.__f_ == &__f.__buf_) |
| 1840 | { |
| 1841 | __f_ = __as_base(&__buf_); |
| 1842 | __f.__f_->__clone(__f_); |
| 1843 | } |
| 1844 | else |
| 1845 | __f_ = __f.__f_->__clone(); |
| 1846 | } |
| 1847 | |
| 1848 | _LIBCPP_INLINE_VISIBILITY |
| 1849 | __value_func(__value_func&& __f) _NOEXCEPT |
| 1850 | { |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1851 | if (__f.__f_ == nullptr) |
| 1852 | __f_ = nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1853 | else if ((void*)__f.__f_ == &__f.__buf_) |
| 1854 | { |
| 1855 | __f_ = __as_base(&__buf_); |
| 1856 | __f.__f_->__clone(__f_); |
| 1857 | } |
| 1858 | else |
| 1859 | { |
| 1860 | __f_ = __f.__f_; |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1861 | __f.__f_ = nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | _LIBCPP_INLINE_VISIBILITY |
| 1866 | ~__value_func() |
| 1867 | { |
| 1868 | if ((void*)__f_ == &__buf_) |
| 1869 | __f_->destroy(); |
| 1870 | else if (__f_) |
| 1871 | __f_->destroy_deallocate(); |
| 1872 | } |
| 1873 | |
| 1874 | _LIBCPP_INLINE_VISIBILITY |
| 1875 | __value_func& operator=(__value_func&& __f) |
| 1876 | { |
| 1877 | *this = nullptr; |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1878 | if (__f.__f_ == nullptr) |
| 1879 | __f_ = nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1880 | else if ((void*)__f.__f_ == &__f.__buf_) |
| 1881 | { |
| 1882 | __f_ = __as_base(&__buf_); |
| 1883 | __f.__f_->__clone(__f_); |
| 1884 | } |
| 1885 | else |
| 1886 | { |
| 1887 | __f_ = __f.__f_; |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1888 | __f.__f_ = nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1889 | } |
| 1890 | return *this; |
| 1891 | } |
| 1892 | |
| 1893 | _LIBCPP_INLINE_VISIBILITY |
| 1894 | __value_func& operator=(nullptr_t) |
| 1895 | { |
| 1896 | __func* __f = __f_; |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1897 | __f_ = nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1898 | if ((void*)__f == &__buf_) |
| 1899 | __f->destroy(); |
| 1900 | else if (__f) |
| 1901 | __f->destroy_deallocate(); |
| 1902 | return *this; |
| 1903 | } |
| 1904 | |
| 1905 | _LIBCPP_INLINE_VISIBILITY |
| 1906 | _Rp operator()(_ArgTypes&&... __args) const |
| 1907 | { |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1908 | if (__f_ == nullptr) |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1909 | __throw_bad_function_call(); |
| 1910 | return (*__f_)(_VSTD::forward<_ArgTypes>(__args)...); |
| 1911 | } |
| 1912 | |
| 1913 | _LIBCPP_INLINE_VISIBILITY |
| 1914 | void swap(__value_func& __f) _NOEXCEPT |
| 1915 | { |
| 1916 | if (&__f == this) |
| 1917 | return; |
| 1918 | if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_) |
| 1919 | { |
| 1920 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 1921 | __func* __t = __as_base(&__tempbuf); |
| 1922 | __f_->__clone(__t); |
| 1923 | __f_->destroy(); |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1924 | __f_ = nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1925 | __f.__f_->__clone(__as_base(&__buf_)); |
| 1926 | __f.__f_->destroy(); |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1927 | __f.__f_ = nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1928 | __f_ = __as_base(&__buf_); |
| 1929 | __t->__clone(__as_base(&__f.__buf_)); |
| 1930 | __t->destroy(); |
| 1931 | __f.__f_ = __as_base(&__f.__buf_); |
| 1932 | } |
| 1933 | else if ((void*)__f_ == &__buf_) |
| 1934 | { |
| 1935 | __f_->__clone(__as_base(&__f.__buf_)); |
| 1936 | __f_->destroy(); |
| 1937 | __f_ = __f.__f_; |
| 1938 | __f.__f_ = __as_base(&__f.__buf_); |
| 1939 | } |
| 1940 | else if ((void*)__f.__f_ == &__f.__buf_) |
| 1941 | { |
| 1942 | __f.__f_->__clone(__as_base(&__buf_)); |
| 1943 | __f.__f_->destroy(); |
| 1944 | __f.__f_ = __f_; |
| 1945 | __f_ = __as_base(&__buf_); |
| 1946 | } |
| 1947 | else |
| 1948 | _VSTD::swap(__f_, __f.__f_); |
| 1949 | } |
| 1950 | |
| 1951 | _LIBCPP_INLINE_VISIBILITY |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1952 | _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { return __f_ != nullptr; } |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1953 | |
| 1954 | #ifndef _LIBCPP_NO_RTTI |
| 1955 | _LIBCPP_INLINE_VISIBILITY |
| 1956 | const std::type_info& target_type() const _NOEXCEPT |
| 1957 | { |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1958 | if (__f_ == nullptr) |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1959 | return typeid(void); |
| 1960 | return __f_->target_type(); |
| 1961 | } |
| 1962 | |
| 1963 | template <typename _Tp> |
| 1964 | _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT |
| 1965 | { |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1966 | if (__f_ == nullptr) |
| 1967 | return nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1968 | return (const _Tp*)__f_->target(typeid(_Tp)); |
| 1969 | } |
| 1970 | #endif // _LIBCPP_NO_RTTI |
| 1971 | }; |
| 1972 | |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 1973 | // Storage for a functor object, to be used with __policy to manage copy and |
| 1974 | // destruction. |
| 1975 | union __policy_storage |
| 1976 | { |
| 1977 | mutable char __small[sizeof(void*) * 2]; |
| 1978 | void* __large; |
| 1979 | }; |
| 1980 | |
| 1981 | // True if _Fun can safely be held in __policy_storage.__small. |
| 1982 | template <typename _Fun> |
| 1983 | struct __use_small_storage |
Arthur O'Dwyer | d8dddf5 | 2021-05-10 13:13:04 -0400 | [diff] [blame] | 1984 | : public integral_constant< |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 1985 | bool, sizeof(_Fun) <= sizeof(__policy_storage) && |
Eric Fiselier | 0f0ed9d | 2019-01-16 01:51:12 +0000 | [diff] [blame] | 1986 | _LIBCPP_ALIGNOF(_Fun) <= _LIBCPP_ALIGNOF(__policy_storage) && |
Arthur O'Dwyer | d8dddf5 | 2021-05-10 13:13:04 -0400 | [diff] [blame] | 1987 | is_trivially_copy_constructible<_Fun>::value && |
| 1988 | is_trivially_destructible<_Fun>::value> {}; |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 1989 | |
| 1990 | // Policy contains information about how to copy, destroy, and move the |
| 1991 | // underlying functor. You can think of it as a vtable of sorts. |
| 1992 | struct __policy |
| 1993 | { |
| 1994 | // Used to copy or destroy __large values. null for trivial objects. |
| 1995 | void* (*const __clone)(const void*); |
| 1996 | void (*const __destroy)(void*); |
| 1997 | |
| 1998 | // True if this is the null policy (no value). |
| 1999 | const bool __is_null; |
| 2000 | |
| 2001 | // The target type. May be null if RTTI is disabled. |
| 2002 | const std::type_info* const __type_info; |
| 2003 | |
| 2004 | // Returns a pointer to a static policy object suitable for the functor |
| 2005 | // type. |
| 2006 | template <typename _Fun> |
| 2007 | _LIBCPP_INLINE_VISIBILITY static const __policy* __create() |
| 2008 | { |
| 2009 | return __choose_policy<_Fun>(__use_small_storage<_Fun>()); |
| 2010 | } |
| 2011 | |
| 2012 | _LIBCPP_INLINE_VISIBILITY |
| 2013 | static const __policy* __create_empty() |
| 2014 | { |
| 2015 | static const _LIBCPP_CONSTEXPR __policy __policy_ = {nullptr, nullptr, |
| 2016 | true, |
| 2017 | #ifndef _LIBCPP_NO_RTTI |
| 2018 | &typeid(void) |
| 2019 | #else |
| 2020 | nullptr |
| 2021 | #endif |
| 2022 | }; |
| 2023 | return &__policy_; |
| 2024 | } |
| 2025 | |
| 2026 | private: |
| 2027 | template <typename _Fun> static void* __large_clone(const void* __s) |
| 2028 | { |
| 2029 | const _Fun* __f = static_cast<const _Fun*>(__s); |
| 2030 | return __f->__clone(); |
| 2031 | } |
| 2032 | |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 2033 | template <typename _Fun> |
| 2034 | static void __large_destroy(void* __s) { |
| 2035 | _Fun::__destroy_and_delete(static_cast<_Fun*>(__s)); |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | template <typename _Fun> |
| 2039 | _LIBCPP_INLINE_VISIBILITY static const __policy* |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 2040 | __choose_policy(/* is_small = */ false_type) { |
| 2041 | static const _LIBCPP_CONSTEXPR __policy __policy_ = { |
| 2042 | &__large_clone<_Fun>, &__large_destroy<_Fun>, false, |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2043 | #ifndef _LIBCPP_NO_RTTI |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 2044 | &typeid(typename _Fun::_Target) |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2045 | #else |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 2046 | nullptr |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2047 | #endif |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 2048 | }; |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2049 | return &__policy_; |
| 2050 | } |
| 2051 | |
| 2052 | template <typename _Fun> |
| 2053 | _LIBCPP_INLINE_VISIBILITY static const __policy* |
| 2054 | __choose_policy(/* is_small = */ true_type) |
| 2055 | { |
| 2056 | static const _LIBCPP_CONSTEXPR __policy __policy_ = { |
| 2057 | nullptr, nullptr, false, |
| 2058 | #ifndef _LIBCPP_NO_RTTI |
| 2059 | &typeid(typename _Fun::_Target) |
| 2060 | #else |
| 2061 | nullptr |
| 2062 | #endif |
| 2063 | }; |
| 2064 | return &__policy_; |
| 2065 | } |
| 2066 | }; |
| 2067 | |
| 2068 | // Used to choose between perfect forwarding or pass-by-value. Pass-by-value is |
| 2069 | // faster for types that can be passed in registers. |
| 2070 | template <typename _Tp> |
| 2071 | using __fast_forward = |
Mark de Wever | 9d7aa7a | 2021-05-09 18:22:52 +0200 | [diff] [blame] | 2072 | typename conditional<is_scalar<_Tp>::value, _Tp, _Tp&&>::type; |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2073 | |
| 2074 | // __policy_invoker calls an instance of __alloc_func held in __policy_storage. |
| 2075 | |
| 2076 | template <class _Fp> struct __policy_invoker; |
| 2077 | |
| 2078 | template <class _Rp, class... _ArgTypes> |
| 2079 | struct __policy_invoker<_Rp(_ArgTypes...)> |
| 2080 | { |
| 2081 | typedef _Rp (*__Call)(const __policy_storage*, |
| 2082 | __fast_forward<_ArgTypes>...); |
| 2083 | |
| 2084 | __Call __call_; |
| 2085 | |
| 2086 | // Creates an invoker that throws bad_function_call. |
| 2087 | _LIBCPP_INLINE_VISIBILITY |
| 2088 | __policy_invoker() : __call_(&__call_empty) {} |
| 2089 | |
| 2090 | // Creates an invoker that calls the given instance of __func. |
| 2091 | template <typename _Fun> |
| 2092 | _LIBCPP_INLINE_VISIBILITY static __policy_invoker __create() |
| 2093 | { |
| 2094 | return __policy_invoker(&__call_impl<_Fun>); |
| 2095 | } |
| 2096 | |
| 2097 | private: |
| 2098 | _LIBCPP_INLINE_VISIBILITY |
| 2099 | explicit __policy_invoker(__Call __c) : __call_(__c) {} |
| 2100 | |
| 2101 | static _Rp __call_empty(const __policy_storage*, |
| 2102 | __fast_forward<_ArgTypes>...) |
| 2103 | { |
| 2104 | __throw_bad_function_call(); |
| 2105 | } |
| 2106 | |
| 2107 | template <typename _Fun> |
| 2108 | static _Rp __call_impl(const __policy_storage* __buf, |
| 2109 | __fast_forward<_ArgTypes>... __args) |
| 2110 | { |
| 2111 | _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value |
| 2112 | ? &__buf->__small |
| 2113 | : __buf->__large); |
| 2114 | return (*__f)(_VSTD::forward<_ArgTypes>(__args)...); |
| 2115 | } |
| 2116 | }; |
| 2117 | |
| 2118 | // __policy_func uses a __policy and __policy_invoker to create a type-erased, |
| 2119 | // copyable functor. |
| 2120 | |
| 2121 | template <class _Fp> class __policy_func; |
| 2122 | |
| 2123 | template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)> |
| 2124 | { |
| 2125 | // Inline storage for small objects. |
| 2126 | __policy_storage __buf_; |
| 2127 | |
| 2128 | // Calls the value stored in __buf_. This could technically be part of |
| 2129 | // policy, but storing it here eliminates a level of indirection inside |
| 2130 | // operator(). |
| 2131 | typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker; |
| 2132 | __invoker __invoker_; |
| 2133 | |
| 2134 | // The policy that describes how to move / copy / destroy __buf_. Never |
| 2135 | // null, even if the function is empty. |
| 2136 | const __policy* __policy_; |
| 2137 | |
| 2138 | public: |
| 2139 | _LIBCPP_INLINE_VISIBILITY |
| 2140 | __policy_func() : __policy_(__policy::__create_empty()) {} |
| 2141 | |
| 2142 | template <class _Fp, class _Alloc> |
| 2143 | _LIBCPP_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a) |
| 2144 | : __policy_(__policy::__create_empty()) |
| 2145 | { |
| 2146 | typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; |
| 2147 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 2148 | typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type |
| 2149 | _FunAlloc; |
| 2150 | |
| 2151 | if (__function::__not_null(__f)) |
| 2152 | { |
| 2153 | __invoker_ = __invoker::template __create<_Fun>(); |
| 2154 | __policy_ = __policy::__create<_Fun>(); |
| 2155 | |
| 2156 | _FunAlloc __af(__a); |
| 2157 | if (__use_small_storage<_Fun>()) |
| 2158 | { |
| 2159 | ::new ((void*)&__buf_.__small) |
| 2160 | _Fun(_VSTD::move(__f), _Alloc(__af)); |
| 2161 | } |
| 2162 | else |
| 2163 | { |
| 2164 | typedef __allocator_destructor<_FunAlloc> _Dp; |
| 2165 | unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1)); |
| 2166 | ::new ((void*)__hold.get()) |
| 2167 | _Fun(_VSTD::move(__f), _Alloc(__af)); |
| 2168 | __buf_.__large = __hold.release(); |
| 2169 | } |
| 2170 | } |
| 2171 | } |
| 2172 | |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 2173 | template <class _Fp, class = typename enable_if<!is_same<typename decay<_Fp>::type, __policy_func>::value>::type> |
| 2174 | _LIBCPP_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f) |
| 2175 | : __policy_(__policy::__create_empty()) { |
| 2176 | typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun; |
| 2177 | |
| 2178 | if (__function::__not_null(__f)) { |
| 2179 | __invoker_ = __invoker::template __create<_Fun>(); |
| 2180 | __policy_ = __policy::__create<_Fun>(); |
| 2181 | if (__use_small_storage<_Fun>()) { |
| 2182 | ::new ((void*)&__buf_.__small) _Fun(_VSTD::move(__f)); |
| 2183 | } else { |
| 2184 | __builtin_new_allocator::__holder_t __hold = |
| 2185 | __builtin_new_allocator::__allocate_type<_Fun>(1); |
Arthur O'Dwyer | 0c4472a | 2020-12-11 20:30:28 -0500 | [diff] [blame] | 2186 | __buf_.__large = ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f)); |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 2187 | (void)__hold.release(); |
| 2188 | } |
| 2189 | } |
| 2190 | } |
| 2191 | |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2192 | _LIBCPP_INLINE_VISIBILITY |
| 2193 | __policy_func(const __policy_func& __f) |
| 2194 | : __buf_(__f.__buf_), __invoker_(__f.__invoker_), |
| 2195 | __policy_(__f.__policy_) |
| 2196 | { |
| 2197 | if (__policy_->__clone) |
| 2198 | __buf_.__large = __policy_->__clone(__f.__buf_.__large); |
| 2199 | } |
| 2200 | |
| 2201 | _LIBCPP_INLINE_VISIBILITY |
| 2202 | __policy_func(__policy_func&& __f) |
| 2203 | : __buf_(__f.__buf_), __invoker_(__f.__invoker_), |
| 2204 | __policy_(__f.__policy_) |
| 2205 | { |
| 2206 | if (__policy_->__destroy) |
| 2207 | { |
| 2208 | __f.__policy_ = __policy::__create_empty(); |
| 2209 | __f.__invoker_ = __invoker(); |
| 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | _LIBCPP_INLINE_VISIBILITY |
| 2214 | ~__policy_func() |
| 2215 | { |
| 2216 | if (__policy_->__destroy) |
| 2217 | __policy_->__destroy(__buf_.__large); |
| 2218 | } |
| 2219 | |
| 2220 | _LIBCPP_INLINE_VISIBILITY |
| 2221 | __policy_func& operator=(__policy_func&& __f) |
| 2222 | { |
| 2223 | *this = nullptr; |
| 2224 | __buf_ = __f.__buf_; |
| 2225 | __invoker_ = __f.__invoker_; |
| 2226 | __policy_ = __f.__policy_; |
| 2227 | __f.__policy_ = __policy::__create_empty(); |
| 2228 | __f.__invoker_ = __invoker(); |
| 2229 | return *this; |
| 2230 | } |
| 2231 | |
| 2232 | _LIBCPP_INLINE_VISIBILITY |
| 2233 | __policy_func& operator=(nullptr_t) |
| 2234 | { |
| 2235 | const __policy* __p = __policy_; |
| 2236 | __policy_ = __policy::__create_empty(); |
| 2237 | __invoker_ = __invoker(); |
| 2238 | if (__p->__destroy) |
| 2239 | __p->__destroy(__buf_.__large); |
| 2240 | return *this; |
| 2241 | } |
| 2242 | |
| 2243 | _LIBCPP_INLINE_VISIBILITY |
| 2244 | _Rp operator()(_ArgTypes&&... __args) const |
| 2245 | { |
| 2246 | return __invoker_.__call_(_VSTD::addressof(__buf_), |
| 2247 | _VSTD::forward<_ArgTypes>(__args)...); |
| 2248 | } |
| 2249 | |
| 2250 | _LIBCPP_INLINE_VISIBILITY |
| 2251 | void swap(__policy_func& __f) |
| 2252 | { |
| 2253 | _VSTD::swap(__invoker_, __f.__invoker_); |
| 2254 | _VSTD::swap(__policy_, __f.__policy_); |
| 2255 | _VSTD::swap(__buf_, __f.__buf_); |
| 2256 | } |
| 2257 | |
| 2258 | _LIBCPP_INLINE_VISIBILITY |
| 2259 | explicit operator bool() const _NOEXCEPT |
| 2260 | { |
| 2261 | return !__policy_->__is_null; |
| 2262 | } |
| 2263 | |
| 2264 | #ifndef _LIBCPP_NO_RTTI |
| 2265 | _LIBCPP_INLINE_VISIBILITY |
| 2266 | const std::type_info& target_type() const _NOEXCEPT |
| 2267 | { |
| 2268 | return *__policy_->__type_info; |
| 2269 | } |
| 2270 | |
| 2271 | template <typename _Tp> |
| 2272 | _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT |
| 2273 | { |
| 2274 | if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info) |
| 2275 | return nullptr; |
| 2276 | if (__policy_->__clone) // Out of line storage. |
| 2277 | return reinterpret_cast<const _Tp*>(__buf_.__large); |
| 2278 | else |
| 2279 | return reinterpret_cast<const _Tp*>(&__buf_.__small); |
| 2280 | } |
| 2281 | #endif // _LIBCPP_NO_RTTI |
| 2282 | }; |
| 2283 | |
Louis Dionne | 3a63292 | 2020-04-23 16:47:52 -0400 | [diff] [blame] | 2284 | #if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC) |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2285 | |
Louis Dionne | 91cf444 | 2020-07-31 12:56:36 -0400 | [diff] [blame] | 2286 | extern "C" void *_Block_copy(const void *); |
| 2287 | extern "C" void _Block_release(const void *); |
| 2288 | |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2289 | template<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes> |
| 2290 | class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> |
| 2291 | : public __base<_Rp(_ArgTypes...)> |
| 2292 | { |
| 2293 | typedef _Rp1(^__block_type)(_ArgTypes1...); |
| 2294 | __block_type __f_; |
| 2295 | |
| 2296 | public: |
| 2297 | _LIBCPP_INLINE_VISIBILITY |
| 2298 | explicit __func(__block_type const& __f) |
Louis Dionne | 91cf444 | 2020-07-31 12:56:36 -0400 | [diff] [blame] | 2299 | : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr)) |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2300 | { } |
| 2301 | |
| 2302 | // [TODO] add && to save on a retain |
| 2303 | |
| 2304 | _LIBCPP_INLINE_VISIBILITY |
| 2305 | explicit __func(__block_type __f, const _Alloc& /* unused */) |
Louis Dionne | 91cf444 | 2020-07-31 12:56:36 -0400 | [diff] [blame] | 2306 | : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr)) |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2307 | { } |
| 2308 | |
| 2309 | virtual __base<_Rp(_ArgTypes...)>* __clone() const { |
| 2310 | _LIBCPP_ASSERT(false, |
| 2311 | "Block pointers are just pointers, so they should always fit into " |
| 2312 | "std::function's small buffer optimization. This function should " |
| 2313 | "never be invoked."); |
| 2314 | return nullptr; |
| 2315 | } |
| 2316 | |
| 2317 | virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const { |
Arthur O'Dwyer | 0c4472a | 2020-12-11 20:30:28 -0500 | [diff] [blame] | 2318 | ::new ((void*)__p) __func(__f_); |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | virtual void destroy() _NOEXCEPT { |
| 2322 | if (__f_) |
Louis Dionne | 91cf444 | 2020-07-31 12:56:36 -0400 | [diff] [blame] | 2323 | _Block_release(__f_); |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2324 | __f_ = 0; |
| 2325 | } |
| 2326 | |
| 2327 | virtual void destroy_deallocate() _NOEXCEPT { |
| 2328 | _LIBCPP_ASSERT(false, |
| 2329 | "Block pointers are just pointers, so they should always fit into " |
| 2330 | "std::function's small buffer optimization. This function should " |
| 2331 | "never be invoked."); |
| 2332 | } |
| 2333 | |
| 2334 | virtual _Rp operator()(_ArgTypes&& ... __arg) { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 2335 | return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__arg)...); |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2336 | } |
| 2337 | |
| 2338 | #ifndef _LIBCPP_NO_RTTI |
| 2339 | virtual const void* target(type_info const& __ti) const _NOEXCEPT { |
| 2340 | if (__ti == typeid(__func::__block_type)) |
| 2341 | return &__f_; |
| 2342 | return (const void*)nullptr; |
| 2343 | } |
| 2344 | |
| 2345 | virtual const std::type_info& target_type() const _NOEXCEPT { |
| 2346 | return typeid(__func::__block_type); |
| 2347 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2348 | #endif // _LIBCPP_NO_RTTI |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2349 | }; |
| 2350 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2351 | #endif // _LIBCPP_HAS_EXTENSION_BLOCKS && !_LIBCPP_HAS_OBJC_ARC |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2352 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2353 | } // __function |
| 2354 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2355 | template<class _Rp, class ..._ArgTypes> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2356 | class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)> |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2357 | : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>, |
| 2358 | public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2359 | { |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2360 | #ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2361 | typedef __function::__value_func<_Rp(_ArgTypes...)> __func; |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2362 | #else |
| 2363 | typedef __function::__policy_func<_Rp(_ArgTypes...)> __func; |
| 2364 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2365 | |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2366 | __func __f_; |
Evgeniy Stepanov | 076b237 | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 2367 | |
Eric Fiselier | 3906a13 | 2019-06-23 20:28:29 +0000 | [diff] [blame] | 2368 | template <class _Fp, bool = _And< |
| 2369 | _IsNotSame<__uncvref_t<_Fp>, function>, |
zoecarver | 3e722f2 | 2020-05-19 17:15:28 -0700 | [diff] [blame] | 2370 | __invokable<_Fp, _ArgTypes...> |
Eric Fiselier | 43c04f7 | 2017-09-10 23:41:20 +0000 | [diff] [blame] | 2371 | >::value> |
| 2372 | struct __callable; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2373 | template <class _Fp> |
| 2374 | struct __callable<_Fp, true> |
Howard Hinnant | 9575593 | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 2375 | { |
Arthur O'Dwyer | 4ba8e3d | 2021-01-11 16:29:17 -0500 | [diff] [blame] | 2376 | static const bool value = is_void<_Rp>::value || |
| 2377 | __is_core_convertible<typename __invoke_of<_Fp, _ArgTypes...>::type, |
| 2378 | _Rp>::value; |
Howard Hinnant | 9575593 | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 2379 | }; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2380 | template <class _Fp> |
| 2381 | struct __callable<_Fp, false> |
Howard Hinnant | 9575593 | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 2382 | { |
| 2383 | static const bool value = false; |
| 2384 | }; |
Eric Fiselier | 43c04f7 | 2017-09-10 23:41:20 +0000 | [diff] [blame] | 2385 | |
| 2386 | template <class _Fp> |
zoecarver | 3e722f2 | 2020-05-19 17:15:28 -0700 | [diff] [blame] | 2387 | using _EnableIfLValueCallable = typename enable_if<__callable<_Fp&>::value>::type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2388 | public: |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2389 | typedef _Rp result_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2390 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2391 | // construct/copy/destroy: |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2392 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2393 | function() _NOEXCEPT { } |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2394 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2395 | function(nullptr_t) _NOEXCEPT {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2396 | function(const function&); |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2397 | function(function&&) _NOEXCEPT; |
zoecarver | 3e722f2 | 2020-05-19 17:15:28 -0700 | [diff] [blame] | 2398 | template<class _Fp, class = _EnableIfLValueCallable<_Fp>> |
Eric Fiselier | f3e18cf | 2016-07-20 05:21:00 +0000 | [diff] [blame] | 2399 | function(_Fp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2400 | |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 2401 | #if _LIBCPP_STD_VER <= 14 |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2402 | template<class _Alloc> |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2403 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2404 | function(allocator_arg_t, const _Alloc&) _NOEXCEPT {} |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2405 | template<class _Alloc> |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2406 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2407 | function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {} |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2408 | template<class _Alloc> |
| 2409 | function(allocator_arg_t, const _Alloc&, const function&); |
| 2410 | template<class _Alloc> |
| 2411 | function(allocator_arg_t, const _Alloc&, function&&); |
zoecarver | 3e722f2 | 2020-05-19 17:15:28 -0700 | [diff] [blame] | 2412 | template<class _Fp, class _Alloc, class = _EnableIfLValueCallable<_Fp>> |
Eric Fiselier | f3e18cf | 2016-07-20 05:21:00 +0000 | [diff] [blame] | 2413 | function(allocator_arg_t, const _Alloc& __a, _Fp __f); |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 2414 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2415 | |
| 2416 | function& operator=(const function&); |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2417 | function& operator=(function&&) _NOEXCEPT; |
| 2418 | function& operator=(nullptr_t) _NOEXCEPT; |
zoecarver | 3e722f2 | 2020-05-19 17:15:28 -0700 | [diff] [blame] | 2419 | template<class _Fp, class = _EnableIfLValueCallable<typename decay<_Fp>::type>> |
Eric Fiselier | 43c04f7 | 2017-09-10 23:41:20 +0000 | [diff] [blame] | 2420 | function& operator=(_Fp&&); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2421 | |
| 2422 | ~function(); |
| 2423 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2424 | // function modifiers: |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2425 | void swap(function&) _NOEXCEPT; |
Marshall Clow | fc8fd83 | 2016-01-25 17:29:55 +0000 | [diff] [blame] | 2426 | |
| 2427 | #if _LIBCPP_STD_VER <= 14 |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2428 | template<class _Fp, class _Alloc> |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2429 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2430 | void assign(_Fp&& __f, const _Alloc& __a) |
| 2431 | {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);} |
Marshall Clow | fc8fd83 | 2016-01-25 17:29:55 +0000 | [diff] [blame] | 2432 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2433 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2434 | // function capacity: |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2435 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2436 | _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { |
| 2437 | return static_cast<bool>(__f_); |
| 2438 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2439 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2440 | // deleted overloads close possible hole in the type system |
| 2441 | template<class _R2, class... _ArgTypes2> |
Howard Hinnant | 5e9a1cf | 2010-09-11 15:33:21 +0000 | [diff] [blame] | 2442 | bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2443 | template<class _R2, class... _ArgTypes2> |
Howard Hinnant | 5e9a1cf | 2010-09-11 15:33:21 +0000 | [diff] [blame] | 2444 | bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2445 | public: |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2446 | // function invocation: |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2447 | _Rp operator()(_ArgTypes...) const; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2448 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2449 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2450 | // function target access: |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2451 | const std::type_info& target_type() const _NOEXCEPT; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2452 | template <typename _Tp> _Tp* target() _NOEXCEPT; |
| 2453 | template <typename _Tp> const _Tp* target() const _NOEXCEPT; |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2454 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2455 | }; |
| 2456 | |
Louis Dionne | 4af4971 | 2019-07-18 19:50:56 +0000 | [diff] [blame] | 2457 | #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES |
| 2458 | template<class _Rp, class ..._Ap> |
| 2459 | function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>; |
| 2460 | |
| 2461 | template<class _Fp> |
| 2462 | struct __strip_signature; |
| 2463 | |
| 2464 | template<class _Rp, class _Gp, class ..._Ap> |
| 2465 | struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); }; |
| 2466 | template<class _Rp, class _Gp, class ..._Ap> |
| 2467 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); }; |
| 2468 | template<class _Rp, class _Gp, class ..._Ap> |
| 2469 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); }; |
| 2470 | template<class _Rp, class _Gp, class ..._Ap> |
| 2471 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); }; |
| 2472 | |
| 2473 | template<class _Rp, class _Gp, class ..._Ap> |
| 2474 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); }; |
| 2475 | template<class _Rp, class _Gp, class ..._Ap> |
| 2476 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); }; |
| 2477 | template<class _Rp, class _Gp, class ..._Ap> |
| 2478 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); }; |
| 2479 | template<class _Rp, class _Gp, class ..._Ap> |
| 2480 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); }; |
| 2481 | |
| 2482 | template<class _Rp, class _Gp, class ..._Ap> |
| 2483 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); }; |
| 2484 | template<class _Rp, class _Gp, class ..._Ap> |
| 2485 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); }; |
| 2486 | template<class _Rp, class _Gp, class ..._Ap> |
| 2487 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); }; |
| 2488 | template<class _Rp, class _Gp, class ..._Ap> |
| 2489 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); }; |
| 2490 | |
| 2491 | template<class _Rp, class _Gp, class ..._Ap> |
| 2492 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); }; |
| 2493 | template<class _Rp, class _Gp, class ..._Ap> |
| 2494 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); }; |
| 2495 | template<class _Rp, class _Gp, class ..._Ap> |
| 2496 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); }; |
| 2497 | template<class _Rp, class _Gp, class ..._Ap> |
| 2498 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); }; |
| 2499 | |
| 2500 | template<class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type> |
| 2501 | function(_Fp) -> function<_Stripped>; |
| 2502 | #endif // !_LIBCPP_HAS_NO_DEDUCTION_GUIDES |
| 2503 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2504 | template<class _Rp, class ..._ArgTypes> |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2505 | function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2506 | |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 2507 | #if _LIBCPP_STD_VER <= 14 |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2508 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2509 | template <class _Alloc> |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2510 | function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2511 | const function& __f) : __f_(__f.__f_) {} |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 2512 | #endif |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2513 | |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2514 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2515 | function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2516 | : __f_(_VSTD::move(__f.__f_)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2517 | |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 2518 | #if _LIBCPP_STD_VER <= 14 |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2519 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2520 | template <class _Alloc> |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2521 | function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2522 | function&& __f) |
| 2523 | : __f_(_VSTD::move(__f.__f_)) {} |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 2524 | #endif |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2525 | |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2526 | template <class _Rp, class... _ArgTypes> |
Eric Fiselier | f3e18cf | 2016-07-20 05:21:00 +0000 | [diff] [blame] | 2527 | template <class _Fp, class> |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 2528 | function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_VSTD::move(__f)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2529 | |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 2530 | #if _LIBCPP_STD_VER <= 14 |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2531 | template <class _Rp, class... _ArgTypes> |
Eric Fiselier | f3e18cf | 2016-07-20 05:21:00 +0000 | [diff] [blame] | 2532 | template <class _Fp, class _Alloc, class> |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2533 | function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a, |
| 2534 | _Fp __f) |
| 2535 | : __f_(_VSTD::move(__f), __a) {} |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 2536 | #endif |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2537 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2538 | template<class _Rp, class ..._ArgTypes> |
| 2539 | function<_Rp(_ArgTypes...)>& |
| 2540 | function<_Rp(_ArgTypes...)>::operator=(const function& __f) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2541 | { |
| 2542 | function(__f).swap(*this); |
| 2543 | return *this; |
| 2544 | } |
| 2545 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2546 | template<class _Rp, class ..._ArgTypes> |
| 2547 | function<_Rp(_ArgTypes...)>& |
| 2548 | function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2549 | { |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 2550 | __f_ = _VSTD::move(__f.__f_); |
Argyrios Kyrtzidis | af90465 | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 2551 | return *this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2552 | } |
| 2553 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2554 | template<class _Rp, class ..._ArgTypes> |
| 2555 | function<_Rp(_ArgTypes...)>& |
| 2556 | function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2557 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2558 | __f_ = nullptr; |
Argyrios Kyrtzidis | af90465 | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 2559 | return *this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2560 | } |
| 2561 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2562 | template<class _Rp, class ..._ArgTypes> |
Eric Fiselier | 43c04f7 | 2017-09-10 23:41:20 +0000 | [diff] [blame] | 2563 | template <class _Fp, class> |
| 2564 | function<_Rp(_ArgTypes...)>& |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2565 | function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2566 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2567 | function(_VSTD::forward<_Fp>(__f)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2568 | return *this; |
| 2569 | } |
| 2570 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2571 | template<class _Rp, class ..._ArgTypes> |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2572 | function<_Rp(_ArgTypes...)>::~function() {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2573 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2574 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2575 | void |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2576 | function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2577 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2578 | __f_.swap(__f.__f_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2579 | } |
| 2580 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2581 | template<class _Rp, class ..._ArgTypes> |
| 2582 | _Rp |
| 2583 | function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2584 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2585 | return __f_(_VSTD::forward<_ArgTypes>(__arg)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2586 | } |
| 2587 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2588 | #ifndef _LIBCPP_NO_RTTI |
| 2589 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2590 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2591 | const std::type_info& |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2592 | function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2593 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2594 | return __f_.target_type(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2595 | } |
| 2596 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2597 | template<class _Rp, class ..._ArgTypes> |
| 2598 | template <typename _Tp> |
| 2599 | _Tp* |
| 2600 | function<_Rp(_ArgTypes...)>::target() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2601 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2602 | return (_Tp*)(__f_.template target<_Tp>()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2603 | } |
| 2604 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2605 | template<class _Rp, class ..._ArgTypes> |
| 2606 | template <typename _Tp> |
| 2607 | const _Tp* |
| 2608 | function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2609 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2610 | return __f_.template target<_Tp>(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2611 | } |
| 2612 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2613 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2614 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2615 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2616 | inline _LIBCPP_INLINE_VISIBILITY |
| 2617 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2618 | operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2619 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2620 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2621 | inline _LIBCPP_INLINE_VISIBILITY |
| 2622 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2623 | operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2624 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2625 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2626 | inline _LIBCPP_INLINE_VISIBILITY |
| 2627 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2628 | operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2629 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2630 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2631 | inline _LIBCPP_INLINE_VISIBILITY |
| 2632 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2633 | operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2634 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2635 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2636 | inline _LIBCPP_INLINE_VISIBILITY |
| 2637 | void |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2638 | swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2639 | {return __x.swap(__y);} |
| 2640 | |
Eric Fiselier | a9ae7a6 | 2017-04-19 01:28:47 +0000 | [diff] [blame] | 2641 | #else // _LIBCPP_CXX03_LANG |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 2642 | |
| 2643 | #include <__functional_03> |
| 2644 | |
| 2645 | #endif |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 2646 | |
| 2647 | //////////////////////////////////////////////////////////////////////////////// |
| 2648 | // BIND |
| 2649 | //============================================================================== |
| 2650 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2651 | template<class _Tp> struct __is_bind_expression : public false_type {}; |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2652 | template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2653 | : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; |
| 2654 | |
Marshall Clow | 2d2d7f1 | 2016-09-22 00:23:15 +0000 | [diff] [blame] | 2655 | #if _LIBCPP_STD_VER > 14 |
| 2656 | template <class _Tp> |
Marshall Clow | f1bf62f | 2018-01-02 17:17:01 +0000 | [diff] [blame] | 2657 | _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] | 2658 | #endif |
| 2659 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2660 | template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2661 | template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2662 | : public __is_placeholder<typename remove_cv<_Tp>::type> {}; |
| 2663 | |
Marshall Clow | 2d2d7f1 | 2016-09-22 00:23:15 +0000 | [diff] [blame] | 2664 | #if _LIBCPP_STD_VER > 14 |
| 2665 | template <class _Tp> |
Marshall Clow | f1bf62f | 2018-01-02 17:17:01 +0000 | [diff] [blame] | 2666 | _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] | 2667 | #endif |
| 2668 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2669 | namespace placeholders |
| 2670 | { |
| 2671 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2672 | template <int _Np> struct __ph {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2673 | |
Louis Dionne | 5e0eadd | 2018-08-01 02:08:59 +0000 | [diff] [blame] | 2674 | #if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) |
Eric Fiselier | b7f51d6 | 2016-06-26 21:01:34 +0000 | [diff] [blame] | 2675 | _LIBCPP_FUNC_VIS extern const __ph<1> _1; |
| 2676 | _LIBCPP_FUNC_VIS extern const __ph<2> _2; |
| 2677 | _LIBCPP_FUNC_VIS extern const __ph<3> _3; |
| 2678 | _LIBCPP_FUNC_VIS extern const __ph<4> _4; |
| 2679 | _LIBCPP_FUNC_VIS extern const __ph<5> _5; |
| 2680 | _LIBCPP_FUNC_VIS extern const __ph<6> _6; |
| 2681 | _LIBCPP_FUNC_VIS extern const __ph<7> _7; |
| 2682 | _LIBCPP_FUNC_VIS extern const __ph<8> _8; |
| 2683 | _LIBCPP_FUNC_VIS extern const __ph<9> _9; |
| 2684 | _LIBCPP_FUNC_VIS extern const __ph<10> _10; |
| 2685 | #else |
Marshall Clow | 396b213 | 2018-01-02 19:01:45 +0000 | [diff] [blame] | 2686 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{}; |
| 2687 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{}; |
| 2688 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{}; |
| 2689 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{}; |
| 2690 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{}; |
| 2691 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{}; |
| 2692 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{}; |
| 2693 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{}; |
| 2694 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{}; |
| 2695 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{}; |
Louis Dionne | 5e0eadd | 2018-08-01 02:08:59 +0000 | [diff] [blame] | 2696 | #endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2697 | |
| 2698 | } // placeholders |
| 2699 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2700 | template<int _Np> |
| 2701 | struct __is_placeholder<placeholders::__ph<_Np> > |
| 2702 | : public integral_constant<int, _Np> {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2703 | |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 2704 | |
Eric Fiselier | a9ae7a6 | 2017-04-19 01:28:47 +0000 | [diff] [blame] | 2705 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 2706 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2707 | template <class _Tp, class _Uj> |
| 2708 | inline _LIBCPP_INLINE_VISIBILITY |
| 2709 | _Tp& |
| 2710 | __mu(reference_wrapper<_Tp> __t, _Uj&) |
| 2711 | { |
| 2712 | return __t.get(); |
| 2713 | } |
| 2714 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2715 | template <class _Ti, class ..._Uj, size_t ..._Indx> |
| 2716 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c1132eb | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2717 | typename __invoke_of<_Ti&, _Uj...>::type |
| 2718 | __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2719 | { |
Marshall Clow | 60e4aa7 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 2720 | return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | template <class _Ti, class ..._Uj> |
| 2724 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 3906a13 | 2019-06-23 20:28:29 +0000 | [diff] [blame] | 2725 | typename _EnableIf |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2726 | < |
| 2727 | is_bind_expression<_Ti>::value, |
Eric Fiselier | f3a1cea | 2014-12-23 05:54:34 +0000 | [diff] [blame] | 2728 | __invoke_of<_Ti&, _Uj...> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2729 | >::type |
| 2730 | __mu(_Ti& __ti, tuple<_Uj...>& __uj) |
| 2731 | { |
| 2732 | typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; |
Arthur O'Dwyer | 34465da | 2020-12-15 19:32:29 -0500 | [diff] [blame] | 2733 | return _VSTD::__mu_expand(__ti, __uj, __indices()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | template <bool IsPh, class _Ti, class _Uj> |
| 2737 | struct __mu_return2 {}; |
| 2738 | |
| 2739 | template <class _Ti, class _Uj> |
| 2740 | struct __mu_return2<true, _Ti, _Uj> |
| 2741 | { |
| 2742 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; |
| 2743 | }; |
| 2744 | |
| 2745 | template <class _Ti, class _Uj> |
| 2746 | inline _LIBCPP_INLINE_VISIBILITY |
| 2747 | typename enable_if |
| 2748 | < |
| 2749 | 0 < is_placeholder<_Ti>::value, |
| 2750 | typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type |
| 2751 | >::type |
| 2752 | __mu(_Ti&, _Uj& __uj) |
| 2753 | { |
| 2754 | const size_t _Indx = is_placeholder<_Ti>::value - 1; |
Marshall Clow | 60e4aa7 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 2755 | 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] | 2756 | } |
| 2757 | |
| 2758 | template <class _Ti, class _Uj> |
| 2759 | inline _LIBCPP_INLINE_VISIBILITY |
| 2760 | typename enable_if |
| 2761 | < |
| 2762 | !is_bind_expression<_Ti>::value && |
| 2763 | is_placeholder<_Ti>::value == 0 && |
| 2764 | !__is_reference_wrapper<_Ti>::value, |
| 2765 | _Ti& |
| 2766 | >::type |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2767 | __mu(_Ti& __ti, _Uj&) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2768 | { |
| 2769 | return __ti; |
| 2770 | } |
| 2771 | |
Howard Hinnant | 0415d79 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 2772 | template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh, |
| 2773 | class _TupleUj> |
Louis Dionne | cbbd7b1 | 2018-09-23 16:44:50 +0000 | [diff] [blame] | 2774 | struct __mu_return_impl; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2775 | |
Howard Hinnant | 51dae7a | 2013-06-30 19:48:15 +0000 | [diff] [blame] | 2776 | template <bool _Invokable, class _Ti, class ..._Uj> |
Louis Dionne | cbbd7b1 | 2018-09-23 16:44:50 +0000 | [diff] [blame] | 2777 | struct __mu_return_invokable // false |
Howard Hinnant | 51dae7a | 2013-06-30 19:48:15 +0000 | [diff] [blame] | 2778 | { |
| 2779 | typedef __nat type; |
| 2780 | }; |
| 2781 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2782 | template <class _Ti, class ..._Uj> |
Louis Dionne | cbbd7b1 | 2018-09-23 16:44:50 +0000 | [diff] [blame] | 2783 | struct __mu_return_invokable<true, _Ti, _Uj...> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2784 | { |
Howard Hinnant | c1132eb | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2785 | typedef typename __invoke_of<_Ti&, _Uj...>::type type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2786 | }; |
| 2787 | |
Howard Hinnant | 51dae7a | 2013-06-30 19:48:15 +0000 | [diff] [blame] | 2788 | template <class _Ti, class ..._Uj> |
Louis Dionne | cbbd7b1 | 2018-09-23 16:44:50 +0000 | [diff] [blame] | 2789 | struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> > |
| 2790 | : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> |
Howard Hinnant | 51dae7a | 2013-06-30 19:48:15 +0000 | [diff] [blame] | 2791 | { |
| 2792 | }; |
| 2793 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2794 | template <class _Ti, class _TupleUj> |
Louis Dionne | cbbd7b1 | 2018-09-23 16:44:50 +0000 | [diff] [blame] | 2795 | struct __mu_return_impl<_Ti, false, false, true, _TupleUj> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2796 | { |
| 2797 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, |
| 2798 | _TupleUj>::type&& type; |
| 2799 | }; |
| 2800 | |
| 2801 | template <class _Ti, class _TupleUj> |
Louis Dionne | cbbd7b1 | 2018-09-23 16:44:50 +0000 | [diff] [blame] | 2802 | struct __mu_return_impl<_Ti, true, false, false, _TupleUj> |
Howard Hinnant | 0415d79 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 2803 | { |
| 2804 | typedef typename _Ti::type& type; |
| 2805 | }; |
| 2806 | |
| 2807 | template <class _Ti, class _TupleUj> |
Louis Dionne | cbbd7b1 | 2018-09-23 16:44:50 +0000 | [diff] [blame] | 2808 | struct __mu_return_impl<_Ti, false, false, false, _TupleUj> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2809 | { |
| 2810 | typedef _Ti& type; |
| 2811 | }; |
| 2812 | |
| 2813 | template <class _Ti, class _TupleUj> |
| 2814 | struct __mu_return |
Louis Dionne | cbbd7b1 | 2018-09-23 16:44:50 +0000 | [diff] [blame] | 2815 | : public __mu_return_impl<_Ti, |
| 2816 | __is_reference_wrapper<_Ti>::value, |
| 2817 | is_bind_expression<_Ti>::value, |
| 2818 | 0 < is_placeholder<_Ti>::value && |
| 2819 | is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value, |
| 2820 | _TupleUj> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2821 | { |
| 2822 | }; |
| 2823 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2824 | template <class _Fp, class _BoundArgs, class _TupleUj> |
Eric Fiselier | 99fffba | 2015-05-19 22:27:18 +0000 | [diff] [blame] | 2825 | struct __is_valid_bind_return |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2826 | { |
| 2827 | static const bool value = false; |
| 2828 | }; |
| 2829 | |
| 2830 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
Eric Fiselier | 99fffba | 2015-05-19 22:27:18 +0000 | [diff] [blame] | 2831 | struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2832 | { |
| 2833 | static const bool value = __invokable<_Fp, |
| 2834 | typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; |
| 2835 | }; |
| 2836 | |
| 2837 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
Eric Fiselier | 99fffba | 2015-05-19 22:27:18 +0000 | [diff] [blame] | 2838 | struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2839 | { |
| 2840 | static const bool value = __invokable<_Fp, |
| 2841 | typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value; |
| 2842 | }; |
| 2843 | |
| 2844 | template <class _Fp, class _BoundArgs, class _TupleUj, |
Eric Fiselier | 99fffba | 2015-05-19 22:27:18 +0000 | [diff] [blame] | 2845 | bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2846 | struct __bind_return; |
| 2847 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2848 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2849 | struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2850 | { |
Howard Hinnant | c1132eb | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2851 | typedef typename __invoke_of |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2852 | < |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2853 | _Fp&, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2854 | typename __mu_return |
| 2855 | < |
| 2856 | _BoundArgs, |
| 2857 | _TupleUj |
| 2858 | >::type... |
| 2859 | >::type type; |
| 2860 | }; |
| 2861 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2862 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2863 | struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2864 | { |
Howard Hinnant | c1132eb | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2865 | typedef typename __invoke_of |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2866 | < |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2867 | _Fp&, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2868 | typename __mu_return |
| 2869 | < |
| 2870 | const _BoundArgs, |
| 2871 | _TupleUj |
| 2872 | >::type... |
| 2873 | >::type type; |
| 2874 | }; |
| 2875 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2876 | template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2877 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2878 | typename __bind_return<_Fp, _BoundArgs, _Args>::type |
| 2879 | __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2880 | _Args&& __args) |
| 2881 | { |
Eric Fiselier | 17264eb | 2017-05-03 21:02:19 +0000 | [diff] [blame] | 2882 | return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2883 | } |
| 2884 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2885 | template<class _Fp, class ..._BoundArgs> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2886 | class __bind |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2887 | : public __weak_result_type<typename decay<_Fp>::type> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2888 | { |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2889 | protected: |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2890 | typedef typename decay<_Fp>::type _Fd; |
Howard Hinnant | c1132eb | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2891 | typedef tuple<typename decay<_BoundArgs>::type...> _Td; |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2892 | private: |
Howard Hinnant | c1132eb | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2893 | _Fd __f_; |
| 2894 | _Td __bound_args_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2895 | |
| 2896 | typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; |
| 2897 | public: |
Howard Hinnant | 0337ade | 2012-05-04 17:21:02 +0000 | [diff] [blame] | 2898 | template <class _Gp, class ..._BA, |
| 2899 | class = typename enable_if |
| 2900 | < |
Howard Hinnant | f292a92 | 2013-07-01 00:01:51 +0000 | [diff] [blame] | 2901 | is_constructible<_Fd, _Gp>::value && |
| 2902 | !is_same<typename remove_reference<_Gp>::type, |
| 2903 | __bind>::value |
Howard Hinnant | 0337ade | 2012-05-04 17:21:02 +0000 | [diff] [blame] | 2904 | >::type> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 2905 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2906 | explicit __bind(_Gp&& __f, _BA&& ...__bound_args) |
| 2907 | : __f_(_VSTD::forward<_Gp>(__f)), |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2908 | __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2909 | |
| 2910 | template <class ..._Args> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 2911 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c1132eb | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2912 | typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2913 | operator()(_Args&& ...__args) |
| 2914 | { |
Eric Fiselier | 17264eb | 2017-05-03 21:02:19 +0000 | [diff] [blame] | 2915 | return _VSTD::__apply_functor(__f_, __bound_args_, __indices(), |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2916 | tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | template <class ..._Args> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 2920 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2921 | typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2922 | operator()(_Args&& ...__args) const |
| 2923 | { |
Eric Fiselier | 17264eb | 2017-05-03 21:02:19 +0000 | [diff] [blame] | 2924 | return _VSTD::__apply_functor(__f_, __bound_args_, __indices(), |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2925 | tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2926 | } |
| 2927 | }; |
| 2928 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2929 | template<class _Fp, class ..._BoundArgs> |
| 2930 | struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2931 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2932 | template<class _Rp, class _Fp, class ..._BoundArgs> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2933 | class __bind_r |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2934 | : public __bind<_Fp, _BoundArgs...> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2935 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2936 | typedef __bind<_Fp, _BoundArgs...> base; |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2937 | typedef typename base::_Fd _Fd; |
| 2938 | typedef typename base::_Td _Td; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2939 | public: |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2940 | typedef _Rp result_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2941 | |
Howard Hinnant | 7091e65 | 2011-07-02 18:22:36 +0000 | [diff] [blame] | 2942 | |
Howard Hinnant | f292a92 | 2013-07-01 00:01:51 +0000 | [diff] [blame] | 2943 | template <class _Gp, class ..._BA, |
| 2944 | class = typename enable_if |
| 2945 | < |
| 2946 | is_constructible<_Fd, _Gp>::value && |
| 2947 | !is_same<typename remove_reference<_Gp>::type, |
| 2948 | __bind_r>::value |
| 2949 | >::type> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 2950 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2951 | explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) |
| 2952 | : base(_VSTD::forward<_Gp>(__f), |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2953 | _VSTD::forward<_BA>(__bound_args)...) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2954 | |
| 2955 | template <class ..._Args> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 2956 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2957 | typename enable_if |
| 2958 | < |
| 2959 | is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type, |
Eric Fiselier | 7a8710a | 2015-07-10 23:29:18 +0000 | [diff] [blame] | 2960 | result_type>::value || is_void<_Rp>::value, |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2961 | result_type |
| 2962 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2963 | operator()(_Args&& ...__args) |
| 2964 | { |
Eric Fiselier | 7a8710a | 2015-07-10 23:29:18 +0000 | [diff] [blame] | 2965 | typedef __invoke_void_return_wrapper<_Rp> _Invoker; |
| 2966 | return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | template <class ..._Args> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 2970 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2971 | typename enable_if |
| 2972 | < |
| 2973 | is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type, |
Eric Fiselier | 7a8710a | 2015-07-10 23:29:18 +0000 | [diff] [blame] | 2974 | result_type>::value || is_void<_Rp>::value, |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2975 | result_type |
| 2976 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2977 | operator()(_Args&& ...__args) const |
| 2978 | { |
Eric Fiselier | 7a8710a | 2015-07-10 23:29:18 +0000 | [diff] [blame] | 2979 | typedef __invoke_void_return_wrapper<_Rp> _Invoker; |
| 2980 | return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2981 | } |
| 2982 | }; |
| 2983 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2984 | template<class _Rp, class _Fp, class ..._BoundArgs> |
| 2985 | struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2986 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2987 | template<class _Fp, class ..._BoundArgs> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 2988 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2989 | __bind<_Fp, _BoundArgs...> |
| 2990 | bind(_Fp&& __f, _BoundArgs&&... __bound_args) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2991 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2992 | typedef __bind<_Fp, _BoundArgs...> type; |
| 2993 | return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2994 | } |
| 2995 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2996 | template<class _Rp, class _Fp, class ..._BoundArgs> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 2997 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2998 | __bind_r<_Rp, _Fp, _BoundArgs...> |
| 2999 | bind(_Fp&& __f, _BoundArgs&&... __bound_args) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3000 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3001 | typedef __bind_r<_Rp, _Fp, _BoundArgs...> type; |
| 3002 | return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3003 | } |
| 3004 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3005 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3006 | |
Eric Fiselier | 0d974f1 | 2015-07-14 20:16:15 +0000 | [diff] [blame] | 3007 | #if _LIBCPP_STD_VER > 14 |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 3008 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3009 | template<class _Op, class _Tuple, |
| 3010 | class _Idxs = typename __make_tuple_indices<tuple_size<_Tuple>::value>::type> |
| 3011 | struct __perfect_forward_impl; |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 3012 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3013 | template<class _Op, class... _Bound, size_t... _Idxs> |
| 3014 | struct __perfect_forward_impl<_Op, __tuple_types<_Bound...>, __tuple_indices<_Idxs...>> |
| 3015 | { |
| 3016 | tuple<_Bound...> __bound_; |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 3017 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3018 | template<class... _Args> |
| 3019 | _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) & |
| 3020 | noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))) |
| 3021 | -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)) |
| 3022 | {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);} |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 3023 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3024 | template<class... _Args> |
| 3025 | _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const& |
| 3026 | noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))) |
| 3027 | -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)) |
| 3028 | {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);} |
Eric Fiselier | e8303a3 | 2016-06-27 00:40:41 +0000 | [diff] [blame] | 3029 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3030 | template<class... _Args> |
| 3031 | _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) && |
| 3032 | noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))..., |
| 3033 | _VSTD::forward<_Args>(__args)...))) |
| 3034 | -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))..., |
| 3035 | _VSTD::forward<_Args>(__args)...)) |
| 3036 | {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))..., |
| 3037 | _VSTD::forward<_Args>(__args)...);} |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 3038 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3039 | template<class... _Args> |
| 3040 | _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&& |
| 3041 | noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))..., |
| 3042 | _VSTD::forward<_Args>(__args)...))) |
| 3043 | -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))..., |
| 3044 | _VSTD::forward<_Args>(__args)...)) |
| 3045 | {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))..., |
| 3046 | _VSTD::forward<_Args>(__args)...);} |
Eric Fiselier | e8303a3 | 2016-06-27 00:40:41 +0000 | [diff] [blame] | 3047 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3048 | template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type, |
| 3049 | class = _EnableIf<is_copy_constructible_v<_Fn>>> |
| 3050 | constexpr __perfect_forward_impl(__perfect_forward_impl const& __other) |
| 3051 | : __bound_(__other.__bound_) {} |
Eric Fiselier | e8303a3 | 2016-06-27 00:40:41 +0000 | [diff] [blame] | 3052 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3053 | template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type, |
| 3054 | class = _EnableIf<is_move_constructible_v<_Fn>>> |
| 3055 | constexpr __perfect_forward_impl(__perfect_forward_impl && __other) |
| 3056 | : __bound_(_VSTD::move(__other.__bound_)) {} |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 3057 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3058 | template<class... _BoundArgs> |
| 3059 | explicit constexpr __perfect_forward_impl(_BoundArgs&&... __bound) : |
| 3060 | __bound_(_VSTD::forward<_BoundArgs>(__bound)...) { } |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 3061 | }; |
| 3062 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3063 | template<class _Op, class... _Args> |
| 3064 | using __perfect_forward = |
| 3065 | __perfect_forward_impl<_Op, __tuple_types<decay_t<_Args>...>>; |
| 3066 | |
| 3067 | struct __not_fn_op |
| 3068 | { |
| 3069 | template<class... _Args> |
| 3070 | static _LIBCPP_CONSTEXPR_AFTER_CXX17 auto __call(_Args&&... __args) |
| 3071 | noexcept(noexcept(!_VSTD::invoke(_VSTD::forward<_Args>(__args)...))) |
| 3072 | -> decltype( !_VSTD::invoke(_VSTD::forward<_Args>(__args)...)) |
| 3073 | { return !_VSTD::invoke(_VSTD::forward<_Args>(__args)...); } |
| 3074 | }; |
| 3075 | |
| 3076 | template<class _Fn, |
| 3077 | class = _EnableIf<is_constructible_v<decay_t<_Fn>, _Fn> && |
| 3078 | is_move_constructible_v<_Fn>>> |
| 3079 | _LIBCPP_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f) |
| 3080 | { |
| 3081 | return __perfect_forward<__not_fn_op, _Fn>(_VSTD::forward<_Fn>(__f)); |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 3082 | } |
| 3083 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3084 | #endif // _LIBCPP_STD_VER > 14 |
| 3085 | |
| 3086 | #if _LIBCPP_STD_VER > 17 |
| 3087 | |
| 3088 | struct __bind_front_op |
| 3089 | { |
| 3090 | template<class... _Args> |
| 3091 | constexpr static auto __call(_Args&&... __args) |
| 3092 | noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...))) |
| 3093 | -> decltype( _VSTD::invoke(_VSTD::forward<_Args>(__args)...)) |
| 3094 | { return _VSTD::invoke(_VSTD::forward<_Args>(__args)...); } |
| 3095 | }; |
| 3096 | |
| 3097 | template<class _Fn, class... _Args, |
| 3098 | class = _EnableIf<conjunction<is_constructible<decay_t<_Fn>, _Fn>, |
| 3099 | is_move_constructible<decay_t<_Fn>>, |
| 3100 | is_constructible<decay_t<_Args>, _Args>..., |
| 3101 | is_move_constructible<decay_t<_Args>>... |
| 3102 | >::value>> |
| 3103 | constexpr auto bind_front(_Fn&& __f, _Args&&... __args) |
| 3104 | { |
| 3105 | return __perfect_forward<__bind_front_op, _Fn, _Args...>(_VSTD::forward<_Fn>(__f), |
| 3106 | _VSTD::forward<_Args>(__args)...); |
| 3107 | } |
| 3108 | |
| 3109 | #endif // _LIBCPP_STD_VER > 17 |
Eric Fiselier | 0d974f1 | 2015-07-14 20:16:15 +0000 | [diff] [blame] | 3110 | |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3111 | // struct hash<T*> in <memory> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3112 | |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3113 | template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2> |
Marshall Clow | 323fc5b | 2018-01-16 15:48:27 +0000 | [diff] [blame] | 3114 | pair<_ForwardIterator1, _ForwardIterator1> _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3115 | __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, |
| 3116 | _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, |
| 3117 | forward_iterator_tag, forward_iterator_tag) |
| 3118 | { |
| 3119 | if (__first2 == __last2) |
Logan Smith | 4528b5f | 2020-05-07 11:54:25 -0400 | [diff] [blame] | 3120 | return _VSTD::make_pair(__first1, __first1); // Everything matches an empty sequence |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3121 | while (true) |
| 3122 | { |
| 3123 | // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks |
| 3124 | while (true) |
| 3125 | { |
| 3126 | if (__first1 == __last1) // return __last1 if no element matches *__first2 |
Logan Smith | 4528b5f | 2020-05-07 11:54:25 -0400 | [diff] [blame] | 3127 | return _VSTD::make_pair(__last1, __last1); |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3128 | if (__pred(*__first1, *__first2)) |
| 3129 | break; |
| 3130 | ++__first1; |
| 3131 | } |
| 3132 | // *__first1 matches *__first2, now match elements after here |
| 3133 | _ForwardIterator1 __m1 = __first1; |
| 3134 | _ForwardIterator2 __m2 = __first2; |
| 3135 | while (true) |
| 3136 | { |
| 3137 | if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern) |
Logan Smith | 4528b5f | 2020-05-07 11:54:25 -0400 | [diff] [blame] | 3138 | return _VSTD::make_pair(__first1, __m1); |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3139 | if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found |
Logan Smith | 4528b5f | 2020-05-07 11:54:25 -0400 | [diff] [blame] | 3140 | return _VSTD::make_pair(__last1, __last1); |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3141 | if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1 |
| 3142 | { |
| 3143 | ++__first1; |
| 3144 | break; |
| 3145 | } // else there is a match, check next elements |
| 3146 | } |
| 3147 | } |
| 3148 | } |
| 3149 | |
| 3150 | template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2> |
| 3151 | _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 3152 | pair<_RandomAccessIterator1, _RandomAccessIterator1> |
| 3153 | __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, |
| 3154 | _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, |
| 3155 | random_access_iterator_tag, random_access_iterator_tag) |
| 3156 | { |
| 3157 | typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1; |
| 3158 | typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2; |
| 3159 | // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern |
| 3160 | const _D2 __len2 = __last2 - __first2; |
| 3161 | if (__len2 == 0) |
Logan Smith | 4528b5f | 2020-05-07 11:54:25 -0400 | [diff] [blame] | 3162 | return _VSTD::make_pair(__first1, __first1); |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3163 | const _D1 __len1 = __last1 - __first1; |
| 3164 | if (__len1 < __len2) |
Logan Smith | 4528b5f | 2020-05-07 11:54:25 -0400 | [diff] [blame] | 3165 | return _VSTD::make_pair(__last1, __last1); |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3166 | const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here |
| 3167 | |
| 3168 | while (true) |
| 3169 | { |
| 3170 | while (true) |
| 3171 | { |
| 3172 | if (__first1 == __s) |
Logan Smith | 4528b5f | 2020-05-07 11:54:25 -0400 | [diff] [blame] | 3173 | return _VSTD::make_pair(__last1, __last1); |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3174 | if (__pred(*__first1, *__first2)) |
| 3175 | break; |
| 3176 | ++__first1; |
| 3177 | } |
| 3178 | |
| 3179 | _RandomAccessIterator1 __m1 = __first1; |
| 3180 | _RandomAccessIterator2 __m2 = __first2; |
| 3181 | while (true) |
| 3182 | { |
| 3183 | if (++__m2 == __last2) |
Logan Smith | 4528b5f | 2020-05-07 11:54:25 -0400 | [diff] [blame] | 3184 | return _VSTD::make_pair(__first1, __first1 + __len2); |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3185 | ++__m1; // no need to check range on __m1 because __s guarantees we have enough source |
| 3186 | if (!__pred(*__m1, *__m2)) |
| 3187 | { |
| 3188 | ++__first1; |
| 3189 | break; |
| 3190 | } |
| 3191 | } |
| 3192 | } |
| 3193 | } |
| 3194 | |
| 3195 | #if _LIBCPP_STD_VER > 14 |
| 3196 | |
| 3197 | // default searcher |
| 3198 | template<class _ForwardIterator, class _BinaryPredicate = equal_to<>> |
Martin Storsjö | 4d6f221 | 2021-04-06 10:55:33 +0300 | [diff] [blame] | 3199 | class _LIBCPP_TEMPLATE_VIS default_searcher { |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3200 | public: |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 3201 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 3202 | default_searcher(_ForwardIterator __f, _ForwardIterator __l, |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3203 | _BinaryPredicate __p = _BinaryPredicate()) |
| 3204 | : __first_(__f), __last_(__l), __pred_(__p) {} |
| 3205 | |
| 3206 | template <typename _ForwardIterator2> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 3207 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3208 | pair<_ForwardIterator2, _ForwardIterator2> |
| 3209 | operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const |
| 3210 | { |
| 3211 | return _VSTD::__search(__f, __l, __first_, __last_, __pred_, |
Arthur O'Dwyer | d8dddf5 | 2021-05-10 13:13:04 -0400 | [diff] [blame] | 3212 | typename iterator_traits<_ForwardIterator>::iterator_category(), |
| 3213 | typename iterator_traits<_ForwardIterator2>::iterator_category()); |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | private: |
| 3217 | _ForwardIterator __first_; |
| 3218 | _ForwardIterator __last_; |
| 3219 | _BinaryPredicate __pred_; |
Eric Fiselier | 80663c5 | 2019-08-04 07:13:43 +0000 | [diff] [blame] | 3220 | }; |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3221 | |
| 3222 | #endif // _LIBCPP_STD_VER > 14 |
| 3223 | |
Louis Dionne | db1892a | 2018-12-03 14:03:27 +0000 | [diff] [blame] | 3224 | #if _LIBCPP_STD_VER > 17 |
| 3225 | template <class _Tp> |
| 3226 | using unwrap_reference_t = typename unwrap_reference<_Tp>::type; |
| 3227 | |
| 3228 | template <class _Tp> |
| 3229 | using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type; |
| 3230 | #endif // > C++17 |
| 3231 | |
Christopher Di Bella | e68ec58 | 2021-03-18 17:21:35 +0000 | [diff] [blame] | 3232 | #if _LIBCPP_STD_VER > 17 |
| 3233 | // [func.identity] |
| 3234 | struct identity { |
| 3235 | template<class _Tp> |
Arthur O'Dwyer | 108facb | 2021-04-05 14:56:03 -0400 | [diff] [blame] | 3236 | _LIBCPP_NODISCARD_EXT constexpr _Tp&& operator()(_Tp&& __t) const noexcept |
Christopher Di Bella | e68ec58 | 2021-03-18 17:21:35 +0000 | [diff] [blame] | 3237 | { |
| 3238 | return _VSTD::forward<_Tp>(__t); |
| 3239 | } |
| 3240 | |
| 3241 | using is_transparent = void; |
| 3242 | }; |
| 3243 | #endif // _LIBCPP_STD_VER > 17 |
| 3244 | |
zoecarver | 9ce102c | 2021-04-22 17:33:04 -0700 | [diff] [blame] | 3245 | #if !defined(_LIBCPP_HAS_NO_RANGES) |
| 3246 | |
| 3247 | namespace ranges { |
| 3248 | |
| 3249 | struct equal_to { |
| 3250 | template <class _Tp, class _Up> |
| 3251 | requires equality_comparable_with<_Tp, _Up> |
| 3252 | [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const |
| 3253 | noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u)))) { |
| 3254 | return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u); |
| 3255 | } |
| 3256 | |
| 3257 | using is_transparent = void; |
| 3258 | }; |
| 3259 | |
| 3260 | struct not_equal_to { |
| 3261 | template <class _Tp, class _Up> |
| 3262 | requires equality_comparable_with<_Tp, _Up> |
| 3263 | [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const |
| 3264 | noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u))))) { |
| 3265 | return !(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u)); |
| 3266 | } |
| 3267 | |
| 3268 | using is_transparent = void; |
| 3269 | }; |
| 3270 | |
| 3271 | struct greater { |
| 3272 | template <class _Tp, class _Up> |
| 3273 | requires totally_ordered_with<_Tp, _Up> |
| 3274 | [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const |
| 3275 | noexcept(noexcept(bool(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t)))) { |
| 3276 | return _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t); |
| 3277 | } |
| 3278 | |
| 3279 | using is_transparent = void; |
| 3280 | }; |
| 3281 | |
| 3282 | struct less { |
| 3283 | template <class _Tp, class _Up> |
| 3284 | requires totally_ordered_with<_Tp, _Up> |
| 3285 | [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const |
| 3286 | noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u)))) { |
| 3287 | return _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u); |
| 3288 | } |
| 3289 | |
| 3290 | using is_transparent = void; |
| 3291 | }; |
| 3292 | |
| 3293 | struct greater_equal { |
| 3294 | template <class _Tp, class _Up> |
| 3295 | requires totally_ordered_with<_Tp, _Up> |
| 3296 | [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const |
| 3297 | noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u))))) { |
| 3298 | return !(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u)); |
| 3299 | } |
| 3300 | |
| 3301 | using is_transparent = void; |
| 3302 | }; |
| 3303 | |
| 3304 | struct less_equal { |
| 3305 | template <class _Tp, class _Up> |
| 3306 | requires totally_ordered_with<_Tp, _Up> |
| 3307 | [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const |
| 3308 | noexcept(noexcept(bool(!(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t))))) { |
| 3309 | return !(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t)); |
| 3310 | } |
| 3311 | |
| 3312 | using is_transparent = void; |
| 3313 | }; |
| 3314 | |
| 3315 | } // namespace ranges |
| 3316 | |
| 3317 | #endif // !defined(_LIBCPP_HAS_NO_RANGES) |
| 3318 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3319 | _LIBCPP_END_NAMESPACE_STD |
| 3320 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3321 | #endif // _LIBCPP_FUNCTIONAL |