| 1 |
/* Copyright (C) 2015 Povilas Kanapickas <[email protected]> |
| 2 |
|
| 3 |
This file is part of cppreference-doc |
| 4 |
|
| 5 |
This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 |
| 6 |
Unported License. To view a copy of this license, visit |
| 7 |
http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative |
| 8 |
Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. |
| 9 |
|
| 10 |
Permission is granted to copy, distribute and/or modify this document |
| 11 |
under the terms of the GNU Free Documentation License, Version 1.3 or |
| 12 |
any later version published by the Free Software Foundation; with no |
| 13 |
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. |
| 14 |
*/ |
| 15 |
|
| 16 |
#ifndef CPPREFERENCE_FUNCTIONAL_H |
| 17 |
#define CPPREFERENCE_FUNCTIONAL_H |
| 18 |
|
| 19 |
namespace std { |
| 20 |
|
| 21 |
#if CPPREFERENCE_STDVER >= 2011 |
| 22 |
template<class R, class... Args> |
| 23 |
class function<R(Args...)> { |
| 24 |
public: |
| 25 |
typedef R result_type; |
| 26 |
function(); |
| 27 |
function(std::nullptr_t); |
| 28 |
function(const function& other); |
| 29 |
function(function&& other); |
| 30 |
template<class F > |
| 31 |
function(F f); |
| 32 |
template<class Alloc > |
| 33 |
function(std::allocator_arg_t, const Alloc& alloc); |
| 34 |
|
| 35 |
template<class Alloc > |
| 36 |
function(std::allocator_arg_t, const Alloc& alloc, |
| 37 |
std::nullptr_t); |
| 38 |
|
| 39 |
template<class Alloc > |
| 40 |
function(std::allocator_arg_t, const Alloc& alloc, |
| 41 |
const function& other); |
| 42 |
|
| 43 |
template<class Alloc > |
| 44 |
function(std::allocator_arg_t, const Alloc& alloc, |
| 45 |
function&& other); |
| 46 |
|
| 47 |
template<class F, class Alloc > |
| 48 |
function(std::allocator_arg_t, const Alloc& alloc, F f); |
| 49 |
|
| 50 |
~function(); |
| 51 |
|
| 52 |
function& operator=(const function& other); |
| 53 |
function& operator=(function&& other); |
| 54 |
function& operator=(std::nullptr_t); |
| 55 |
|
| 56 |
template<class F > |
| 57 |
function& operator=(F&& f); |
| 58 |
|
| 59 |
template<class F > |
| 60 |
function& operator=(std::reference_wrapper<F> f); |
| 61 |
|
| 62 |
void swap(function& other); |
| 63 |
|
| 64 |
template<class F, class Alloc > |
| 65 |
void assign(F&& f, const Alloc& alloc); |
| 66 |
|
| 67 |
explicit operator bool() const; |
| 68 |
|
| 69 |
R operator()(ArgTypes... args) const; |
| 70 |
|
| 71 |
const std::type_info& target_type() const; |
| 72 |
|
| 73 |
template<class T > |
| 74 |
T* target(); |
| 75 |
|
| 76 |
template<class T > |
| 77 |
const T* target() const; |
| 78 |
}; |
| 79 |
|
| 80 |
template<class R, class... Args> |
| 81 |
void swap(function<R(Args...)>& lhs, function<R(Args...)>& rhs); |
| 82 |
|
| 83 |
template<class R, class... ArgTypes > |
| 84 |
bool operator==(const std::function<R(ArgTypes...)>& f, std::nullptr_t); |
| 85 |
|
| 86 |
template<class R, class... ArgTypes > |
| 87 |
bool operator==(std::nullptr_t, const std::function<R(ArgTypes...)>& f); |
| 88 |
|
| 89 |
template<class R, class... ArgTypes > |
| 90 |
bool operator!=(const std::function<R(ArgTypes...)>& f, std::nullptr_t); |
| 91 |
|
| 92 |
template<class R, class... ArgTypes > |
| 93 |
bool operator!=(std::nullptr_t, const std::function<R(ArgTypes...)>& f); |
| 94 |
|
| 95 |
class bad_function_call : public std::exception { |
| 96 |
public: |
| 97 |
bad_function_call(); |
| 98 |
}; |
| 99 |
|
| 100 |
// SIMPLIFIED: actual result is unspecified, std::function<R> is only for |
| 101 |
// providing return type |
| 102 |
template<class R, class T > |
| 103 |
std::function<R> mem_fn(R T::* pm); |
| 104 |
|
| 105 |
template<class F, class... Args > |
| 106 |
std::function<R> bind(F&& f, Args&& ... args); |
| 107 |
|
| 108 |
template<class R, class F, class... Args > |
| 109 |
std::function<R> bind(F&& f, Args&& ... args); |
| 110 |
|
| 111 |
#if CPPREFERENCE_STDVER >= 2017 |
| 112 |
template<class F, class... ArgTypes> |
| 113 |
std::result_of_t < F&& (ArgTypes&& ...) > invoke(F&& f, ArgTypes&& ... args); |
| 114 |
#endif |
| 115 |
|
| 116 |
// SIMPLIFIED: the inherited type is simplified |
| 117 |
template<class T > |
| 118 |
struct is_bind_expression : std::integral_constant<bool, true> {}; |
| 119 |
|
| 120 |
template<class T > |
| 121 |
struct is_placeholder : std::integral_constant<bool, true> {}; |
| 122 |
|
| 123 |
namespace placeholders { // SIMPLIFIED: the actual type is unspecified |
| 124 |
extern int _1; |
| 125 |
extern int _2; |
| 126 |
extern int _3; |
| 127 |
extern int _4; |
| 128 |
extern int _5; |
| 129 |
extern int _6; |
| 130 |
extern int _7; |
| 131 |
extern int _8; |
| 132 |
extern int _9; |
| 133 |
} // namespace placeholders |
| 134 |
|
| 135 |
template<class T> |
| 136 |
class reference_wrapper { |
| 137 |
public: |
| 138 |
typedef T type; |
| 139 |
// SIMPLIFIED: actual types are dependent on T |
| 140 |
typedef void result_type; |
| 141 |
typedef void argument_type; |
| 142 |
typedef void first_argument_type; |
| 143 |
typedef void second_argument_type; |
| 144 |
|
| 145 |
reference_wrapper(T& x); |
| 146 |
reference_wrapper(T&& x) = delete; |
| 147 |
reference_wrapper(const reference_wrapper<T>& other); |
| 148 |
|
| 149 |
reference_wrapper& operator=(const reference_wrapper<T>& other); |
| 150 |
|
| 151 |
operator T& () const; |
| 152 |
T& get() const; |
| 153 |
|
| 154 |
template<class... ArgTypes > |
| 155 |
typename std::result_of < T& (ArgTypes&& ...) >::type |
| 156 |
operator()(ArgTypes&& ... args) const; // only if T is function |
| 157 |
}; |
| 158 |
|
| 159 |
template<class T > |
| 160 |
std::reference_wrapper<T> ref(T& t); |
| 161 |
|
| 162 |
template<class T > |
| 163 |
std::reference_wrapper<T> ref(std::reference_wrapper<T> t); |
| 164 |
|
| 165 |
template <class T> |
| 166 |
void ref(const T&&) = delete; |
| 167 |
|
| 168 |
template<class T > |
| 169 |
std::reference_wrapper<const T> cref(const T& t); |
| 170 |
|
| 171 |
template<class T > |
| 172 |
std::reference_wrapper<const T> cref(std::reference_wrapper<T> t); |
| 173 |
|
| 174 |
template <class T> |
| 175 |
void cref(const T&&) = delete; |
| 176 |
|
| 177 |
#endif // CPPREFERENCE_STDVER >= 2011 |
| 178 |
|
| 179 |
template<class T = void> |
| 180 |
struct plus { |
| 181 |
typedef T result_type; |
| 182 |
typedef T first_argument_type; |
| 183 |
typedef T second_argument_type; |
| 184 |
T operator()(const T& lhs, const T& rhs) const; |
| 185 |
}; |
| 186 |
|
| 187 |
template<class T = void> |
| 188 |
struct minus { |
| 189 |
typedef T result_type; |
| 190 |
typedef T first_argument_type; |
| 191 |
typedef T second_argument_type; |
| 192 |
T operator()(const T& lhs, const T& rhs) const; |
| 193 |
}; |
| 194 |
|
| 195 |
template<class T = void> |
| 196 |
struct multiplies { |
| 197 |
typedef T result_type; |
| 198 |
typedef T first_argument_type; |
| 199 |
typedef T second_argument_type; |
| 200 |
T operator()(const T& lhs, const T& rhs) const; |
| 201 |
}; |
| 202 |
|
| 203 |
template<class T = void> |
| 204 |
struct divides { |
| 205 |
typedef T result_type; |
| 206 |
typedef T first_argument_type; |
| 207 |
typedef T second_argument_type; |
| 208 |
T operator()(const T& lhs, const T& rhs) const; |
| 209 |
}; |
| 210 |
|
| 211 |
template<class T = void> |
| 212 |
struct modulus { |
| 213 |
typedef T result_type; |
| 214 |
typedef T first_argument_type; |
| 215 |
typedef T second_argument_type; |
| 216 |
T operator()(const T& lhs, const T& rhs) const; |
| 217 |
}; |
| 218 |
|
| 219 |
template<class T = void> |
| 220 |
struct negate { |
| 221 |
typedef T result_type; |
| 222 |
typedef T argument_type; |
| 223 |
T operator()(const T& arg) const; |
| 224 |
}; |
| 225 |
|
| 226 |
template<class T = void> |
| 227 |
struct equal_to { |
| 228 |
typedef bool result_type; |
| 229 |
typedef T first_argument_type; |
| 230 |
typedef T second_argument_type; |
| 231 |
bool operator()(const T& lhs, const T& rhs) const; |
| 232 |
}; |
| 233 |
|
| 234 |
template<class T = void> |
| 235 |
struct not_equal_to { |
| 236 |
typedef bool result_type; |
| 237 |
typedef T first_argument_type; |
| 238 |
typedef T second_argument_type; |
| 239 |
bool operator()(const T& lhs, const T& rhs) const; |
| 240 |
}; |
| 241 |
|
| 242 |
template<class T = void> |
| 243 |
struct greater { |
| 244 |
typedef bool result_type; |
| 245 |
typedef T first_argument_type; |
| 246 |
typedef T second_argument_type; |
| 247 |
bool operator()(const T& lhs, const T& rhs) const; |
| 248 |
}; |
| 249 |
|
| 250 |
template<class T = void> |
| 251 |
struct less { |
| 252 |
typedef bool result_type; |
| 253 |
typedef T first_argument_type; |
| 254 |
typedef T second_argument_type; |
| 255 |
bool operator()(const T& lhs, const T& rhs) const; |
| 256 |
}; |
| 257 |
|
| 258 |
template<class T = void> |
| 259 |
struct greater_equal { |
| 260 |
typedef bool result_type; |
| 261 |
typedef T first_argument_type; |
| 262 |
typedef T second_argument_type; |
| 263 |
bool operator()(const T& lhs, const T& rhs) const; |
| 264 |
}; |
| 265 |
|
| 266 |
template<class T = void> |
| 267 |
struct less_equal { |
| 268 |
typedef bool result_type; |
| 269 |
typedef T first_argument_type; |
| 270 |
typedef T second_argument_type; |
| 271 |
bool operator()(const T& lhs, const T& rhs) const; |
| 272 |
}; |
| 273 |
|
| 274 |
template<class T = void> |
| 275 |
struct logical_and { |
| 276 |
typedef bool result_type; |
| 277 |
typedef T first_argument_type; |
| 278 |
typedef T second_argument_type; |
| 279 |
bool operator()(const T& lhs, const T& rhs) const; |
| 280 |
}; |
| 281 |
|
| 282 |
template<class T = void> |
| 283 |
struct logical_or { |
| 284 |
typedef bool result_type; |
| 285 |
typedef T first_argument_type; |
| 286 |
typedef T second_argument_type; |
| 287 |
bool operator()(const T& lhs, const T& rhs) const; |
| 288 |
}; |
| 289 |
|
| 290 |
template<class T = void> |
| 291 |
struct logical_not { |
| 292 |
typedef bool result_type; |
| 293 |
typedef T argument_type; |
| 294 |
bool operator()(const T& arg) const; |
| 295 |
}; |
| 296 |
|
| 297 |
template<class T = void> |
| 298 |
struct bit_and { |
| 299 |
typedef T result_type; |
| 300 |
typedef T first_argument_type; |
| 301 |
typedef T second_argument_type; |
| 302 |
T operator()(const T& lhs, const T& rhs) const; |
| 303 |
}; |
| 304 |
|
| 305 |
template<class T = void> |
| 306 |
struct bit_or { |
| 307 |
typedef T result_type; |
| 308 |
typedef T first_argument_type; |
| 309 |
typedef T second_argument_type; |
| 310 |
T operator()(const T& lhs, const T& rhs) const; |
| 311 |
}; |
| 312 |
|
| 313 |
template<class T = void> |
| 314 |
struct bit_xor { |
| 315 |
typedef T result_type; |
| 316 |
typedef T first_argument_type; |
| 317 |
typedef T second_argument_type; |
| 318 |
T operator()(const T& lhs, const T& rhs) const; |
| 319 |
}; |
| 320 |
|
| 321 |
template<class T = void> |
| 322 |
struct bit_not { |
| 323 |
typedef T result_type; |
| 324 |
typedef T argument_type; |
| 325 |
T operator()(const T& arg) const; |
| 326 |
}; |
| 327 |
|
| 328 |
template<class Predicate > |
| 329 |
struct unary_negate { |
| 330 |
typedef bool result_type; |
| 331 |
typedef typename Predicate::argument_type argument_type; |
| 332 |
|
| 333 |
explicit unary_negate(const Predicate& pred); |
| 334 |
result_type operator()(argument_type const& x) const; |
| 335 |
}; |
| 336 |
|
| 337 |
template<class Predicate > |
| 338 |
struct binary_negate { |
| 339 |
typedef bool result_type; |
| 340 |
typedef typename Predicate::first_argument_type first_argument_type; |
| 341 |
typedef typename Predicate::second_argument_type second_argument_type; |
| 342 |
|
| 343 |
explicit binary_negate(const Predicate& pred); |
| 344 |
result_type operator()(const T& lhs, const T& rhs) const; |
| 345 |
}; |
| 346 |
|
| 347 |
template<class Predicate > |
| 348 |
std::unary_negate<Predicate> not1(const Predicate& pred); |
| 349 |
|
| 350 |
template<class Predicate > |
| 351 |
std::binary_negate<Predicate> not2(const Predicate& pred); |
| 352 |
|
| 353 |
#if CPPREFERENCE_STDVER >= 2011 |
| 354 |
template<class Key > |
| 355 |
struct hash { |
| 356 |
typedef Key argument_type; |
| 357 |
typedef std::size_t result_type; |
| 358 |
|
| 359 |
std::size_t operator()(const Key& key) const; |
| 360 |
}; |
| 361 |
#endif |
| 362 |
} // namespace std |
| 363 |
|
| 364 |
#endif // CPPREFERENCE_FUNCTIONAL_H |