Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/c++/v1/functional is written in an unsupported language. File is not indexed.

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP_FUNCTIONAL
0011 #define _LIBCPP_FUNCTIONAL
0012 
0013 /*
0014     functional synopsis
0015 
0016 namespace std
0017 {
0018 
0019 template <class Arg, class Result>
0020 struct unary_function
0021 {
0022     typedef Arg    argument_type;
0023     typedef Result result_type;
0024 };
0025 
0026 template <class Arg1, class Arg2, class Result>
0027 struct binary_function
0028 {
0029     typedef Arg1   first_argument_type;
0030     typedef Arg2   second_argument_type;
0031     typedef Result result_type;
0032 };
0033 
0034 template <class T>
0035 class reference_wrapper
0036     : public unary_function<T1, R> // if wrapping a unary functor
0037     : public binary_function<T1, T2, R> // if wrapping a binary functor
0038 {
0039 public:
0040     // types
0041     typedef T type;
0042     typedef see below result_type; // Not always defined
0043 
0044     // construct/copy/destroy
0045     template<class U>
0046       constexpr reference_wrapper(U&&);                                   // constexpr since C++20
0047     constexpr reference_wrapper(const reference_wrapper<T>& x) noexcept;  // constexpr since C++20
0048 
0049     // assignment
0050     constexpr reference_wrapper&
0051     operator=(const reference_wrapper<T>& x) noexcept;                    // constexpr since C++20
0052 
0053     // access
0054     constexpr operator T& () const noexcept;                              // constexpr since C++20
0055     constexpr T& get() const noexcept;                                    // constexpr since C++20
0056 
0057     // invoke
0058     template <class... ArgTypes>
0059       constexpr typename result_of<T&(ArgTypes&&...)>::type               // constexpr since C++20
0060           operator() (ArgTypes&&...) const
0061               noexcept(is_nothrow_invocable_v<T&, ArgTypes...>);          // noexcept since C++17
0062 };
0063 
0064 template <class T>
0065   reference_wrapper(T&) -> reference_wrapper<T>;
0066 
0067 template <class T> reference_wrapper<T> ref(T& t) noexcept;
0068 template <class T> void ref(const T&& t) = delete;
0069 template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
0070 
0071 template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
0072 template <class T> void cref(const T&& t) = delete;
0073 template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
0074 
0075 template <class T> struct unwrap_reference;                                       // since C++20
0076 template <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { };    // since C++20
0077 template <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20
0078 template <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20
0079 
0080 // [refwrap.comparisons], comparisons
0081 friend constexpr bool operator==(reference_wrapper, reference_wrapper);           // Since C++26
0082 friend constexpr bool operator==(reference_wrapper, const T&);                    // Since C++26
0083 friend constexpr bool operator==(reference_wrapper, reference_wrapper<const T>);  // Since C++26
0084 
0085 friend constexpr auto operator<=>(reference_wrapper, reference_wrapper);          // Since C++26
0086 friend constexpr auto operator<=>(reference_wrapper, const T&);                   // Since C++26
0087 friend constexpr auto operator<=>(reference_wrapper, reference_wrapper<const T>); // Since C++26
0088 
0089 template <class T> // <class T=void> in C++14
0090 struct plus {
0091     T operator()(const T& x, const T& y) const;
0092 };
0093 
0094 template <class T> // <class T=void> in C++14
0095 struct minus {
0096     T operator()(const T& x, const T& y) const;
0097 };
0098 
0099 template <class T> // <class T=void> in C++14
0100 struct multiplies {
0101     T operator()(const T& x, const T& y) const;
0102 };
0103 
0104 template <class T> // <class T=void> in C++14
0105 struct divides {
0106     T operator()(const T& x, const T& y) const;
0107 };
0108 
0109 template <class T> // <class T=void> in C++14
0110 struct modulus {
0111     T operator()(const T& x, const T& y) const;
0112 };
0113 
0114 template <class T> // <class T=void> in C++14
0115 struct negate {
0116     T operator()(const T& x) const;
0117 };
0118 
0119 template <class T> // <class T=void> in C++14
0120 struct equal_to {
0121     bool operator()(const T& x, const T& y) const;
0122 };
0123 
0124 template <class T> // <class T=void> in C++14
0125 struct not_equal_to {
0126     bool operator()(const T& x, const T& y) const;
0127 };
0128 
0129 template <class T> // <class T=void> in C++14
0130 struct greater {
0131     bool operator()(const T& x, const T& y) const;
0132 };
0133 
0134 template <class T> // <class T=void> in C++14
0135 struct less {
0136     bool operator()(const T& x, const T& y) const;
0137 };
0138 
0139 template <class T> // <class T=void> in C++14
0140 struct greater_equal {
0141     bool operator()(const T& x, const T& y) const;
0142 };
0143 
0144 template <class T> // <class T=void> in C++14
0145 struct less_equal {
0146     bool operator()(const T& x, const T& y) const;
0147 };
0148 
0149 // [comparisons.three.way], class compare_three_way
0150 struct compare_three_way;
0151 
0152 template <class T> // <class T=void> in C++14
0153 struct logical_and {
0154     bool operator()(const T& x, const T& y) const;
0155 };
0156 
0157 template <class T> // <class T=void> in C++14
0158 struct logical_or {
0159     bool operator()(const T& x, const T& y) const;
0160 };
0161 
0162 template <class T> // <class T=void> in C++14
0163 struct logical_not {
0164     bool operator()(const T& x) const;
0165 };
0166 
0167 template <class T> // <class T=void> in C++14
0168 struct bit_and {
0169     T operator()(const T& x, const T& y) const;
0170 };
0171 
0172 template <class T> // <class T=void> in C++14
0173 struct bit_or {
0174     T operator()(const T& x, const T& y) const;
0175 };
0176 
0177 template <class T> // <class T=void> in C++14
0178 struct bit_xor {
0179     T operator()(const T& x, const T& y) const;
0180 };
0181 
0182 template <class T=void> // C++14
0183 struct bit_not {
0184     T operator()(const T& x) const;
0185 };
0186 
0187 struct identity; // C++20
0188 
0189 template <class Predicate>
0190 class unary_negate // deprecated in C++17, removed in C++20
0191     : public unary_function<typename Predicate::argument_type, bool>
0192 {
0193 public:
0194     explicit unary_negate(const Predicate& pred);
0195     bool operator()(const typename Predicate::argument_type& x) const;
0196 };
0197 
0198 template <class Predicate> // deprecated in C++17, removed in C++20
0199 unary_negate<Predicate> not1(const Predicate& pred);
0200 
0201 template <class Predicate>
0202 class binary_negate // deprecated in C++17, removed in C++20
0203     : public binary_function<typename Predicate::first_argument_type,
0204                              typename Predicate::second_argument_type,
0205                              bool>
0206 {
0207 public:
0208     explicit binary_negate(const Predicate& pred);
0209     bool operator()(const typename Predicate::first_argument_type& x,
0210                     const typename Predicate::second_argument_type& y) const;
0211 };
0212 
0213 template <class Predicate> // deprecated in C++17, removed in C++20
0214 binary_negate<Predicate> not2(const Predicate& pred);
0215 
0216 template <class F>
0217   constexpr unspecified not_fn(F&& f);     // C++17, constexpr in C++20
0218 template <auto f>
0219   constexpr unspecified not_fn() noexcept; // C++26
0220 
0221 // [func.bind.partial], function templates bind_front and bind_back
0222 template<class F, class... Args>
0223   constexpr unspecified bind_front(F&&, Args&&...); // C++20
0224 template<class F, class... Args>
0225   constexpr unspecified bind_back(F&&, Args&&...);  // C++23
0226 
0227 template<class T> struct is_bind_expression;
0228 template<class T> struct is_placeholder;
0229 
0230     // See C++14 20.9.9, Function object binders
0231 template <class T> inline constexpr bool is_bind_expression_v
0232   = is_bind_expression<T>::value; // C++17
0233 template <class T> inline constexpr int is_placeholder_v
0234   = is_placeholder<T>::value; // C++17
0235 
0236 
0237 template<class Fn, class... BoundArgs>
0238   constexpr unspecified bind(Fn&&, BoundArgs&&...);  // constexpr in C++20
0239 template<class R, class Fn, class... BoundArgs>
0240   constexpr unspecified bind(Fn&&, BoundArgs&&...);  // constexpr in C++20
0241 
0242 // [func.invoke]
0243 template<class F, class... Args>
0244  constexpr // constexpr in C++20
0245  invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17
0246     noexcept(is_nothrow_invocable_v<F, Args...>);
0247 
0248 template<class R, class F, class... Args>
0249   constexpr R invoke_r(F&& f, Args&&... args)              // C++23
0250     noexcept(is_nothrow_invocable_r_v<R, F, Args...>);
0251 
0252 namespace placeholders {
0253   // M is the implementation-defined number of placeholders
0254   extern unspecified _1;
0255   extern unspecified _2;
0256   .
0257   .
0258   .
0259   extern unspecified _Mp;
0260 }
0261 
0262 template <class Operation>
0263 class binder1st     // deprecated in C++11, removed in C++17
0264     : public unary_function<typename Operation::second_argument_type,
0265                             typename Operation::result_type>
0266 {
0267 protected:
0268     Operation                               op;
0269     typename Operation::first_argument_type value;
0270 public:
0271     binder1st(const Operation& x, const typename Operation::first_argument_type y);
0272     typename Operation::result_type operator()(      typename Operation::second_argument_type& x) const;
0273     typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
0274 };
0275 
0276 template <class Operation, class T>
0277 binder1st<Operation> bind1st(const Operation& op, const T& x);                  // deprecated in C++11, removed in C++17
0278 
0279 template <class Operation>
0280 class binder2nd                                                                 // deprecated in C++11, removed in C++17
0281     : public unary_function<typename Operation::first_argument_type,
0282                             typename Operation::result_type>
0283 {
0284 protected:
0285     Operation                                op;
0286     typename Operation::second_argument_type value;
0287 public:
0288     binder2nd(const Operation& x, const typename Operation::second_argument_type y);
0289     typename Operation::result_type operator()(      typename Operation::first_argument_type& x) const;
0290     typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
0291 };
0292 
0293 template <class Operation, class T>
0294 binder2nd<Operation> bind2nd(const Operation& op, const T& x);                  // deprecated in C++11, removed in C++17
0295 
0296 template <class Arg, class Result>                                              // deprecated in C++11, removed in C++17
0297 class pointer_to_unary_function : public unary_function<Arg, Result>
0298 {
0299 public:
0300     explicit pointer_to_unary_function(Result (*f)(Arg));
0301     Result operator()(Arg x) const;
0302 };
0303 
0304 template <class Arg, class Result>
0305 pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));                // deprecated in C++11, removed in C++17
0306 
0307 template <class Arg1, class Arg2, class Result>                                 // deprecated in C++11, removed in C++17
0308 class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
0309 {
0310 public:
0311     explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
0312     Result operator()(Arg1 x, Arg2 y) const;
0313 };
0314 
0315 template <class Arg1, class Arg2, class Result>
0316 pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));   // deprecated in C++11, removed in C++17
0317 
0318 template<class S, class T>                                                      // deprecated in C++11, removed in C++17
0319 class mem_fun_t : public unary_function<T*, S>
0320 {
0321 public:
0322     explicit mem_fun_t(S (T::*p)());
0323     S operator()(T* p) const;
0324 };
0325 
0326 template<class S, class T, class A>
0327 class mem_fun1_t : public binary_function<T*, A, S>                             // deprecated in C++11, removed in C++17
0328 {
0329 public:
0330     explicit mem_fun1_t(S (T::*p)(A));
0331     S operator()(T* p, A x) const;
0332 };
0333 
0334 template<class S, class T>          mem_fun_t<S,T>    mem_fun(S (T::*f)());     // deprecated in C++11, removed in C++17
0335 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
0336 
0337 template<class S, class T>
0338 class mem_fun_ref_t : public unary_function<T, S>                               // deprecated in C++11, removed in C++17
0339 {
0340 public:
0341     explicit mem_fun_ref_t(S (T::*p)());
0342     S operator()(T& p) const;
0343 };
0344 
0345 template<class S, class T, class A>
0346 class mem_fun1_ref_t : public binary_function<T, A, S>                          // deprecated in C++11, removed in C++17
0347 {
0348 public:
0349     explicit mem_fun1_ref_t(S (T::*p)(A));
0350     S operator()(T& p, A x) const;
0351 };
0352 
0353 template<class S, class T>
0354 mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)());                                 // deprecated in C++11, removed in C++17
0355 template<class S, class T, class A>
0356 mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));                                // deprecated in C++11, removed in C++17
0357 
0358 template <class S, class T>
0359 class const_mem_fun_t : public unary_function<const T*, S>                      // deprecated in C++11, removed in C++17
0360 {
0361 public:
0362     explicit const_mem_fun_t(S (T::*p)() const);
0363     S operator()(const T* p) const;
0364 };
0365 
0366 template <class S, class T, class A>
0367 class const_mem_fun1_t : public binary_function<const T*, A, S>                 // deprecated in C++11, removed in C++17
0368 {
0369 public:
0370     explicit const_mem_fun1_t(S (T::*p)(A) const);
0371     S operator()(const T* p, A x) const;
0372 };
0373 
0374 template <class S, class T>
0375 const_mem_fun_t<S,T>    mem_fun(S (T::*f)() const);                             // deprecated in C++11, removed in C++17
0376 template <class S, class T, class A>
0377 const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);                            // deprecated in C++11, removed in C++17
0378 
0379 template <class S, class T>
0380 class const_mem_fun_ref_t : public unary_function<T, S>                         // deprecated in C++11, removed in C++17
0381 {
0382 public:
0383     explicit const_mem_fun_ref_t(S (T::*p)() const);
0384     S operator()(const T& p) const;
0385 };
0386 
0387 template <class S, class T, class A>
0388 class const_mem_fun1_ref_t : public binary_function<T, A, S>                    // deprecated in C++11, removed in C++17
0389 {
0390 public:
0391     explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
0392     S operator()(const T& p, A x) const;
0393 };
0394 
0395 template <class S, class T>
0396 const_mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)() const);                     // deprecated in C++11, removed in C++17
0397 template <class S, class T, class A>
0398 const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);                    // deprecated in C++11, removed in C++17
0399 
0400 template<class R, class T> constexpr unspecified mem_fn(R T::*) noexcept;       // constexpr in C++20
0401 
0402 class bad_function_call
0403     : public exception
0404 {
0405 };
0406 
0407 template<class> class function; // undefined
0408 
0409 template<class R, class... ArgTypes>
0410 class function<R(ArgTypes...)>
0411   : public unary_function<T1, R>      // iff sizeof...(ArgTypes) == 1 and
0412                                       // ArgTypes contains T1
0413   : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
0414                                       // ArgTypes contains T1 and T2
0415 {
0416 public:
0417     typedef R result_type;
0418 
0419     // construct/copy/destroy:
0420     function() noexcept;
0421     function(nullptr_t) noexcept;
0422     function(const function&);
0423     function(function&&) noexcept;
0424     template<class F>
0425       function(F);
0426     template<Allocator Alloc>
0427       function(allocator_arg_t, const Alloc&) noexcept;            // removed in C++17
0428     template<Allocator Alloc>
0429       function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
0430     template<Allocator Alloc>
0431       function(allocator_arg_t, const Alloc&, const function&);    // removed in C++17
0432     template<Allocator Alloc>
0433       function(allocator_arg_t, const Alloc&, function&&);         // removed in C++17
0434     template<class F, Allocator Alloc>
0435       function(allocator_arg_t, const Alloc&, F);                  // removed in C++17
0436 
0437     function& operator=(const function&);
0438     function& operator=(function&&) noexcept;
0439     function& operator=(nullptr_t) noexcept;
0440     template<class F>
0441       function& operator=(F&&);
0442     template<class F>
0443       function& operator=(reference_wrapper<F>) noexcept;
0444 
0445     ~function();
0446 
0447     // function modifiers:
0448     void swap(function&) noexcept;
0449     template<class F, class Alloc>
0450       void assign(F&&, const Alloc&);                 // Removed in C++17
0451 
0452     // function capacity:
0453     explicit operator bool() const noexcept;
0454 
0455     // function invocation:
0456     R operator()(ArgTypes...) const;
0457 
0458     // function target access:
0459     const std::type_info& target_type() const noexcept;
0460     template <typename T>       T* target() noexcept;
0461     template <typename T> const T* target() const noexcept;
0462 };
0463 
0464 // Deduction guides
0465 template<class R, class ...Args>
0466 function(R(*)(Args...)) -> function<R(Args...)>; // since C++17
0467 
0468 template<class F>
0469 function(F) -> function<see-below>; // since C++17
0470 
0471 // Null pointer comparisons:
0472 template <class R, class ... ArgTypes>
0473   bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
0474 
0475 template <class R, class ... ArgTypes>
0476   bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; // removed in C++20
0477 
0478 template <class R, class ... ArgTypes>
0479   bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; // removed in C++20
0480 
0481 template <class  R, class ... ArgTypes>
0482   bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; // removed in C++20
0483 
0484 // specialized algorithms:
0485 template <class  R, class ... ArgTypes>
0486   void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
0487 
0488 template <class T> struct hash;
0489 
0490 template <> struct hash<bool>;
0491 template <> struct hash<char>;
0492 template <> struct hash<signed char>;
0493 template <> struct hash<unsigned char>;
0494 template <> struct hash<char8_t>; // since C++20
0495 template <> struct hash<char16_t>;
0496 template <> struct hash<char32_t>;
0497 template <> struct hash<wchar_t>;
0498 template <> struct hash<short>;
0499 template <> struct hash<unsigned short>;
0500 template <> struct hash<int>;
0501 template <> struct hash<unsigned int>;
0502 template <> struct hash<long>;
0503 template <> struct hash<long long>;
0504 template <> struct hash<unsigned long>;
0505 template <> struct hash<unsigned long long>;
0506 
0507 template <> struct hash<float>;
0508 template <> struct hash<double>;
0509 template <> struct hash<long double>;
0510 
0511 template<class T> struct hash<T*>;
0512 template <> struct hash<nullptr_t>;  // C++17
0513 
0514 namespace ranges {
0515   // [range.cmp], concept-constrained comparisons
0516   struct equal_to;
0517   struct not_equal_to;
0518   struct greater;
0519   struct less;
0520   struct greater_equal;
0521   struct less_equal;
0522 }
0523 
0524 }  // std
0525 
0526 POLICY:  For non-variadic implementations, the number of arguments is limited
0527          to 3.  It is hoped that the need for non-variadic implementations
0528          will be minimal.
0529 
0530 */
0531 
0532 #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0533 #  include <__cxx03/functional>
0534 #else
0535 #  include <__config>
0536 
0537 #  include <__functional/binary_function.h>
0538 #  include <__functional/binary_negate.h>
0539 #  include <__functional/bind.h>
0540 #  include <__functional/binder1st.h>
0541 #  include <__functional/binder2nd.h>
0542 #  include <__functional/hash.h>
0543 #  include <__functional/mem_fn.h> // TODO: deprecate
0544 #  include <__functional/mem_fun_ref.h>
0545 #  include <__functional/operations.h>
0546 #  include <__functional/pointer_to_binary_function.h>
0547 #  include <__functional/pointer_to_unary_function.h>
0548 #  include <__functional/reference_wrapper.h>
0549 #  include <__functional/unary_function.h>
0550 #  include <__functional/unary_negate.h>
0551 
0552 #  ifndef _LIBCPP_CXX03_LANG
0553 #    include <__functional/function.h>
0554 #  endif
0555 
0556 #  if _LIBCPP_STD_VER >= 17
0557 #    include <__functional/boyer_moore_searcher.h>
0558 #    include <__functional/default_searcher.h>
0559 #    include <__functional/invoke.h>
0560 #    include <__functional/not_fn.h>
0561 #  endif
0562 
0563 #  if _LIBCPP_STD_VER >= 20
0564 #    include <__functional/bind_back.h>
0565 #    include <__functional/bind_front.h>
0566 #    include <__functional/identity.h>
0567 #    include <__functional/ranges_operations.h>
0568 #    include <__type_traits/unwrap_ref.h>
0569 #  endif
0570 
0571 #  include <version>
0572 
0573 #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0574 #    pragma GCC system_header
0575 #  endif
0576 
0577 #  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && defined(_LIBCPP_CXX03_LANG)
0578 #    include <limits>
0579 #    include <new>
0580 #  endif
0581 
0582 #  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 14
0583 #    include <array>
0584 #    include <initializer_list>
0585 #    include <unordered_map>
0586 #  endif
0587 
0588 #  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
0589 #    include <atomic>
0590 #    include <concepts>
0591 #    include <cstdlib>
0592 #    include <exception>
0593 #    include <iosfwd>
0594 #    include <memory>
0595 #    include <stdexcept>
0596 #    include <tuple>
0597 #    include <type_traits>
0598 #    include <typeinfo>
0599 #    include <utility>
0600 #    include <vector>
0601 #  endif
0602 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0603 
0604 #endif // _LIBCPP_FUNCTIONAL