aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxx/include/functional
blob: 5f9e8fa82a891f842a0bc4129ce79a1b1171ab3d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP_FUNCTIONAL
#define _LIBCPP_FUNCTIONAL

/*
    functional synopsis

namespace std
{

template <class Arg, class Result>
struct unary_function
{
    typedef Arg    argument_type;
    typedef Result result_type;
};

template <class Arg1, class Arg2, class Result>
struct binary_function
{
    typedef Arg1   first_argument_type;
    typedef Arg2   second_argument_type;
    typedef Result result_type;
};

template <class T>
class reference_wrapper
    : public unary_function<T1, R> // if wrapping a unary functor
    : public binary_function<T1, T2, R> // if wrapping a binary functor
{
public:
    // types
    typedef T type;
    typedef see below result_type; // Not always defined

    // construct/copy/destroy
    template<class U>
      constexpr reference_wrapper(U&&);                                   // constexpr since C++20
    constexpr reference_wrapper(const reference_wrapper<T>& x) noexcept;  // constexpr since C++20

    // assignment
    constexpr reference_wrapper&
    operator=(const reference_wrapper<T>& x) noexcept;                    // constexpr since C++20

    // access
    constexpr operator T& () const noexcept;                              // constexpr since C++20
    constexpr T& get() const noexcept;                                    // constexpr since C++20

    // invoke
    template <class... ArgTypes>
      constexpr typename result_of<T&(ArgTypes&&...)>::type               // constexpr since C++20
          operator() (ArgTypes&&...) const
              noexcept(is_nothrow_invocable_v<T&, ArgTypes...>);          // noexcept since C++17
};

template <class T>
  reference_wrapper(T&) -> reference_wrapper<T>;

template <class T> reference_wrapper<T> ref(T& t) noexcept;
template <class T> void ref(const T&& t) = delete;
template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;

template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
template <class T> void cref(const T&& t) = delete;
template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;

template <class T> struct unwrap_reference;                                       // since C++20
template <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { };    // since C++20
template <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20
template <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20

template <class T> // <class T=void> in C++14
struct plus {
    T operator()(const T& x, const T& y) const;
};

template <class T> // <class T=void> in C++14
struct minus {
    T operator()(const T& x, const T& y) const;
};

template <class T> // <class T=void> in C++14
struct multiplies {
    T operator()(const T& x, const T& y) const;
};

template <class T> // <class T=void> in C++14
struct divides {
    T operator()(const T& x, const T& y) const;
};

template <class T> // <class T=void> in C++14
struct modulus {
    T operator()(const T& x, const T& y) const;
};

template <class T> // <class T=void> in C++14
struct negate {
    T operator()(const T& x) const;
};

template <class T> // <class T=void> in C++14
struct equal_to {
    bool operator()(const T& x, const T& y) const;
};

template <class T> // <class T=void> in C++14
struct not_equal_to {
    bool operator()(const T& x, const T& y) const;
};

template <class T> // <class T=void> in C++14
struct greater {
    bool operator()(const T& x, const T& y) const;
};

template <class T> // <class T=void> in C++14
struct less {
    bool operator()(const T& x, const T& y) const;
};

template <class T> // <class T=void> in C++14
struct greater_equal {
    bool operator()(const T& x, const T& y) const;
};

template <class T> // <class T=void> in C++14
struct less_equal {
    bool operator()(const T& x, const T& y) const;
};

// [comparisons.three.way], class compare_three_way
struct compare_three_way;

template <class T> // <class T=void> in C++14
struct logical_and {
    bool operator()(const T& x, const T& y) const;
};

template <class T> // <class T=void> in C++14
struct logical_or {
    bool operator()(const T& x, const T& y) const;
};

template <class T> // <class T=void> in C++14
struct logical_not {
    bool operator()(const T& x) const;
};

template <class T> // <class T=void> in C++14
struct bit_and {
    T operator()(const T& x, const T& y) const;
};

template <class T> // <class T=void> in C++14
struct bit_or {
    T operator()(const T& x, const T& y) const;
};

template <class T> // <class T=void> in C++14
struct bit_xor {
    T operator()(const T& x, const T& y) const;
};

template <class T=void> // C++14
struct bit_not {
    T operator()(const T& x) const;
};

struct identity; // C++20

template <class Predicate>
class unary_negate // deprecated in C++17, removed in C++20
    : public unary_function<typename Predicate::argument_type, bool>
{
public:
    explicit unary_negate(const Predicate& pred);
    bool operator()(const typename Predicate::argument_type& x) const;
};

template <class Predicate> // deprecated in C++17, removed in C++20
unary_negate<Predicate> not1(const Predicate& pred);

template <class Predicate>
class binary_negate // deprecated in C++17, removed in C++20
    : public binary_function<typename Predicate::first_argument_type,
                             typename Predicate::second_argument_type,
                             bool>
{
public:
    explicit binary_negate(const Predicate& pred);
    bool operator()(const typename Predicate::first_argument_type& x,
                    const typename Predicate::second_argument_type& y) const;
};

template <class Predicate> // deprecated in C++17, removed in C++20
binary_negate<Predicate> not2(const Predicate& pred);

template <class F>
constexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20

template<class T> struct is_bind_expression;
template<class T> struct is_placeholder;

    // See C++14 20.9.9, Function object binders
template <class T> inline constexpr bool is_bind_expression_v
  = is_bind_expression<T>::value; // C++17
template <class T> inline constexpr int is_placeholder_v
  = is_placeholder<T>::value; // C++17


template<class Fn, class... BoundArgs>
  constexpr unspecified bind(Fn&&, BoundArgs&&...);  // constexpr in C++20
template<class R, class Fn, class... BoundArgs>
  constexpr unspecified bind(Fn&&, BoundArgs&&...);  // constexpr in C++20

// [func.invoke]
template<class F, class... Args>
 constexpr // constexpr in C++20
 invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17
    noexcept(is_nothrow_invocable_v<F, Args...>);

template<class R, class F, class... Args>
  constexpr R invoke_r(F&& f, Args&&... args)              // C++23
    noexcept(is_nothrow_invocable_r_v<R, F, Args...>);

namespace placeholders {
  // M is the implementation-defined number of placeholders
  extern unspecified _1;
  extern unspecified _2;
  .
  .
  .
  extern unspecified _Mp;
}

template <class Operation>
class binder1st     // deprecated in C++11, removed in C++17
    : public unary_function<typename Operation::second_argument_type,
                            typename Operation::result_type>
{
protected:
    Operation                               op;
    typename Operation::first_argument_type value;
public:
    binder1st(const Operation& x, const typename Operation::first_argument_type y);
    typename Operation::result_type operator()(      typename Operation::second_argument_type& x) const;
    typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
};

template <class Operation, class T>
binder1st<Operation> bind1st(const Operation& op, const T& x);                  // deprecated in C++11, removed in C++17

template <class Operation>
class binder2nd                                                                 // deprecated in C++11, removed in C++17
    : public unary_function<typename Operation::first_argument_type,
                            typename Operation::result_type>
{
protected:
    Operation                                op;
    typename Operation::second_argument_type value;
public:
    binder2nd(const Operation& x, const typename Operation::second_argument_type y);
    typename Operation::result_type operator()(      typename Operation::first_argument_type& x) const;
    typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
};

template <class Operation, class T>
binder2nd<Operation> bind2nd(const Operation& op, const T& x);                  // deprecated in C++11, removed in C++17

template <class Arg, class Result>                                              // deprecated in C++11, removed in C++17
class pointer_to_unary_function : public unary_function<Arg, Result>
{
public:
    explicit pointer_to_unary_function(Result (*f)(Arg));
    Result operator()(Arg x) const;
};

template <class Arg, class Result>
pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));                // deprecated in C++11, removed in C++17

template <class Arg1, class Arg2, class Result>                                 // deprecated in C++11, removed in C++17
class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
{
public:
    explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
    Result operator()(Arg1 x, Arg2 y) const;
};

template <class Arg1, class Arg2, class Result>
pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));   // deprecated in C++11, removed in C++17

template<class S, class T>                                                      // deprecated in C++11, removed in C++17
class mem_fun_t : public unary_function<T*, S>
{
public:
    explicit mem_fun_t(S (T::*p)());
    S operator()(T* p) const;
};

template<class S, class T, class A>
class mem_fun1_t : public binary_function<T*, A, S>                             // deprecated in C++11, removed in C++17
{
public:
    explicit mem_fun1_t(S (T::*p)(A));
    S operator()(T* p, A x) const;
};

template<class S, class T>          mem_fun_t<S,T>    mem_fun(S (T::*f)());     // deprecated in C++11, removed in C++17
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

template<class S, class T>
class mem_fun_ref_t : public unary_function<T, S>                               // deprecated in C++11, removed in C++17
{
public:
    explicit mem_fun_ref_t(S (T::*p)());
    S operator()(T& p) const;
};

template<class S, class T, class A>
class mem_fun1_ref_t : public binary_function<T, A, S>                          // deprecated in C++11, removed in C++17
{
public:
    explicit mem_fun1_ref_t(S (T::*p)(A));
    S operator()(T& p, A x) const;
};

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
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

template <class S, class T>
class const_mem_fun_t : public unary_function<const T*, S>                      // deprecated in C++11, removed in C++17
{
public:
    explicit const_mem_fun_t(S (T::*p)() const);
    S operator()(const T* p) const;
};

template <class S, class T, class A>
class const_mem_fun1_t : public binary_function<const T*, A, S>                 // deprecated in C++11, removed in C++17
{
public:
    explicit const_mem_fun1_t(S (T::*p)(A) const);
    S operator()(const T* p, A x) const;
};

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
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

template <class S, class T>
class const_mem_fun_ref_t : public unary_function<T, S>                         // deprecated in C++11, removed in C++17
{
public:
    explicit const_mem_fun_ref_t(S (T::*p)() const);
    S operator()(const T& p) const;
};

template <class S, class T, class A>
class const_mem_fun1_ref_t : public binary_function<T, A, S>                    // deprecated in C++11, removed in C++17
{
public:
    explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
    S operator()(const T& p, A x) const;
};

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
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

template<class R, class T> constexpr unspecified mem_fn(R T::*);                // constexpr in C++20

class bad_function_call
    : public exception
{
};

template<class> class function; // undefined

template<class R, class... ArgTypes>
class function<R(ArgTypes...)>
  : public unary_function<T1, R>      // iff sizeof...(ArgTypes) == 1 and
                                      // ArgTypes contains T1
  : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
                                      // ArgTypes contains T1 and T2
{
public:
    typedef R result_type;

    // construct/copy/destroy:
    function() noexcept;
    function(nullptr_t) noexcept;
    function(const function&);
    function(function&&) noexcept;
    template<class F>
      function(F);
    template<Allocator Alloc>
      function(allocator_arg_t, const Alloc&) noexcept;            // removed in C++17
    template<Allocator Alloc>
      function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
    template<Allocator Alloc>
      function(allocator_arg_t, const Alloc&, const function&);    // removed in C++17
    template<Allocator Alloc>
      function(allocator_arg_t, const Alloc&, function&&);         // removed in C++17
    template<class F, Allocator Alloc>
      function(allocator_arg_t, const Alloc&, F);                  // removed in C++17

    function& operator=(const function&);
    function& operator=(function&&) noexcept;
    function& operator=(nullptr_t) noexcept;
    template<class F>
      function& operator=(F&&);
    template<class F>
      function& operator=(reference_wrapper<F>) noexcept;

    ~function();

    // function modifiers:
    void swap(function&) noexcept;
    template<class F, class Alloc>
      void assign(F&&, const Alloc&);                 // Removed in C++17

    // function capacity:
    explicit operator bool() const noexcept;

    // function invocation:
    R operator()(ArgTypes...) const;

    // function target access:
    const std::type_info& target_type() const noexcept;
    template <typename T>       T* target() noexcept;
    template <typename T> const T* target() const noexcept;
};

// Deduction guides
template<class R, class ...Args>
function(R(*)(Args...)) -> function<R(Args...)>; // since C++17

template<class F>
function(F) -> function<see-below>; // since C++17

// Null pointer comparisons:
template <class R, class ... ArgTypes>
  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;

template <class R, class ... ArgTypes>
  bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; // removed in C++20

template <class R, class ... ArgTypes>
  bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; // removed in C++20

template <class  R, class ... ArgTypes>
  bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; // removed in C++20

// specialized algorithms:
template <class  R, class ... ArgTypes>
  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;

template <class T> struct hash;

template <> struct hash<bool>;
template <> struct hash<char>;
template <> struct hash<signed char>;
template <> struct hash<unsigned char>;
template <> struct hash<char8_t>; // since C++20
template <> struct hash<char16_t>;
template <> struct hash<char32_t>;
template <> struct hash<wchar_t>;
template <> struct hash<short>;
template <> struct hash<unsigned short>;
template <> struct hash<int>;
template <> struct hash<unsigned int>;
template <> struct hash<long>;
template <> struct hash<long long>;
template <> struct hash<unsigned long>;
template <> struct hash<unsigned long long>;

template <> struct hash<float>;
template <> struct hash<double>;
template <> struct hash<long double>;

template<class T> struct hash<T*>;
template <> struct hash<nullptr_t>;  // C++17

namespace ranges {
  // [range.cmp], concept-constrained comparisons
  struct equal_to;
  struct not_equal_to;
  struct greater;
  struct less;
  struct greater_equal;
  struct less_equal;
}

}  // std

POLICY:  For non-variadic implementations, the number of arguments is limited
         to 3.  It is hoped that the need for non-variadic implementations
         will be minimal.

*/

#include <__algorithm/search.h>
#include <__assert> // all public C++ headers provide the assertion handler
#include <__compare/compare_three_way.h>
#include <__config>
#include <__functional/binary_function.h>
#include <__functional/binary_negate.h>
#include <__functional/bind.h>
#include <__functional/bind_back.h>
#include <__functional/bind_front.h>
#include <__functional/binder1st.h>
#include <__functional/binder2nd.h>
#include <__functional/boyer_moore_searcher.h>
#include <__functional/compose.h>
#include <__functional/default_searcher.h>
#include <__functional/function.h>
#include <__functional/hash.h>
#include <__functional/identity.h>
#include <__functional/invoke.h>
#include <__functional/mem_fn.h> // TODO: deprecate
#include <__functional/mem_fun_ref.h>
#include <__functional/not_fn.h>
#include <__functional/operations.h>
#include <__functional/pointer_to_binary_function.h>
#include <__functional/pointer_to_unary_function.h>
#include <__functional/ranges_operations.h>
#include <__functional/reference_wrapper.h>
#include <__functional/unary_function.h>
#include <__functional/unary_negate.h>
#include <__type_traits/unwrap_ref.h>
#include <__utility/forward.h>
#include <memory> // TODO: find out why removing this breaks the modules build
#include <typeinfo>
#include <version>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#  pragma GCC system_header
#endif

#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
#  include <atomic>
#  include <concepts>
#  include <cstdlib>
#  include <exception>
#  include <tuple>
#  include <type_traits>
#  include <utility>
#endif

#endif // _LIBCPP_FUNCTIONAL