Warning, /include/c++/v1/__cxx03/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___CXX03_FUNCTIONAL
0011 #define _LIBCPP___CXX03_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
0219 // [func.bind.partial], function templates bind_front and bind_back
0220 template<class F, class... Args>
0221 constexpr unspecified bind_front(F&&, Args&&...); // C++20
0222 template<class F, class... Args>
0223 constexpr unspecified bind_back(F&&, Args&&...); // C++23
0224
0225 template<class T> struct is_bind_expression;
0226 template<class T> struct is_placeholder;
0227
0228 // See C++14 20.9.9, Function object binders
0229 template <class T> inline constexpr bool is_bind_expression_v
0230 = is_bind_expression<T>::value; // C++17
0231 template <class T> inline constexpr int is_placeholder_v
0232 = is_placeholder<T>::value; // C++17
0233
0234
0235 template<class Fn, class... BoundArgs>
0236 constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20
0237 template<class R, class Fn, class... BoundArgs>
0238 constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20
0239
0240 // [func.invoke]
0241 template<class F, class... Args>
0242 constexpr // constexpr in C++20
0243 invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17
0244 noexcept(is_nothrow_invocable_v<F, Args...>);
0245
0246 template<class R, class F, class... Args>
0247 constexpr R invoke_r(F&& f, Args&&... args) // C++23
0248 noexcept(is_nothrow_invocable_r_v<R, F, Args...>);
0249
0250 namespace placeholders {
0251 // M is the implementation-defined number of placeholders
0252 extern unspecified _1;
0253 extern unspecified _2;
0254 .
0255 .
0256 .
0257 extern unspecified _Mp;
0258 }
0259
0260 template <class Operation>
0261 class binder1st // deprecated in C++11, removed in C++17
0262 : public unary_function<typename Operation::second_argument_type,
0263 typename Operation::result_type>
0264 {
0265 protected:
0266 Operation op;
0267 typename Operation::first_argument_type value;
0268 public:
0269 binder1st(const Operation& x, const typename Operation::first_argument_type y);
0270 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
0271 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
0272 };
0273
0274 template <class Operation, class T>
0275 binder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
0276
0277 template <class Operation>
0278 class binder2nd // deprecated in C++11, removed in C++17
0279 : public unary_function<typename Operation::first_argument_type,
0280 typename Operation::result_type>
0281 {
0282 protected:
0283 Operation op;
0284 typename Operation::second_argument_type value;
0285 public:
0286 binder2nd(const Operation& x, const typename Operation::second_argument_type y);
0287 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
0288 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
0289 };
0290
0291 template <class Operation, class T>
0292 binder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
0293
0294 template <class Arg, class Result> // deprecated in C++11, removed in C++17
0295 class pointer_to_unary_function : public unary_function<Arg, Result>
0296 {
0297 public:
0298 explicit pointer_to_unary_function(Result (*f)(Arg));
0299 Result operator()(Arg x) const;
0300 };
0301
0302 template <class Arg, class Result>
0303 pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); // deprecated in C++11, removed in C++17
0304
0305 template <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17
0306 class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
0307 {
0308 public:
0309 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
0310 Result operator()(Arg1 x, Arg2 y) const;
0311 };
0312
0313 template <class Arg1, class Arg2, class Result>
0314 pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); // deprecated in C++11, removed in C++17
0315
0316 template<class S, class T> // deprecated in C++11, removed in C++17
0317 class mem_fun_t : public unary_function<T*, S>
0318 {
0319 public:
0320 explicit mem_fun_t(S (T::*p)());
0321 S operator()(T* p) const;
0322 };
0323
0324 template<class S, class T, class A>
0325 class mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17
0326 {
0327 public:
0328 explicit mem_fun1_t(S (T::*p)(A));
0329 S operator()(T* p, A x) const;
0330 };
0331
0332 template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17
0333 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
0334
0335 template<class S, class T>
0336 class mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17
0337 {
0338 public:
0339 explicit mem_fun_ref_t(S (T::*p)());
0340 S operator()(T& p) const;
0341 };
0342
0343 template<class S, class T, class A>
0344 class mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17
0345 {
0346 public:
0347 explicit mem_fun1_ref_t(S (T::*p)(A));
0348 S operator()(T& p, A x) const;
0349 };
0350
0351 template<class S, class T>
0352 mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17
0353 template<class S, class T, class A>
0354 mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); // deprecated in C++11, removed in C++17
0355
0356 template <class S, class T>
0357 class const_mem_fun_t : public unary_function<const T*, S> // deprecated in C++11, removed in C++17
0358 {
0359 public:
0360 explicit const_mem_fun_t(S (T::*p)() const);
0361 S operator()(const T* p) const;
0362 };
0363
0364 template <class S, class T, class A>
0365 class const_mem_fun1_t : public binary_function<const T*, A, S> // deprecated in C++11, removed in C++17
0366 {
0367 public:
0368 explicit const_mem_fun1_t(S (T::*p)(A) const);
0369 S operator()(const T* p, A x) const;
0370 };
0371
0372 template <class S, class T>
0373 const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17
0374 template <class S, class T, class A>
0375 const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); // deprecated in C++11, removed in C++17
0376
0377 template <class S, class T>
0378 class const_mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17
0379 {
0380 public:
0381 explicit const_mem_fun_ref_t(S (T::*p)() const);
0382 S operator()(const T& p) const;
0383 };
0384
0385 template <class S, class T, class A>
0386 class const_mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17
0387 {
0388 public:
0389 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
0390 S operator()(const T& p, A x) const;
0391 };
0392
0393 template <class S, class T>
0394 const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); // deprecated in C++11, removed in C++17
0395 template <class S, class T, class A>
0396 const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); // deprecated in C++11, removed in C++17
0397
0398 template<class R, class T> constexpr unspecified mem_fn(R T::*); // constexpr in C++20
0399
0400 class bad_function_call
0401 : public exception
0402 {
0403 };
0404
0405 template<class> class function; // undefined
0406
0407 template<class R, class... ArgTypes>
0408 class function<R(ArgTypes...)>
0409 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
0410 // ArgTypes contains T1
0411 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
0412 // ArgTypes contains T1 and T2
0413 {
0414 public:
0415 typedef R result_type;
0416
0417 // construct/copy/destroy:
0418 function() noexcept;
0419 function(nullptr_t) noexcept;
0420 function(const function&);
0421 function(function&&) noexcept;
0422 template<class F>
0423 function(F);
0424 template<Allocator Alloc>
0425 function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17
0426 template<Allocator Alloc>
0427 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
0428 template<Allocator Alloc>
0429 function(allocator_arg_t, const Alloc&, const function&); // removed in C++17
0430 template<Allocator Alloc>
0431 function(allocator_arg_t, const Alloc&, function&&); // removed in C++17
0432 template<class F, Allocator Alloc>
0433 function(allocator_arg_t, const Alloc&, F); // removed in C++17
0434
0435 function& operator=(const function&);
0436 function& operator=(function&&) noexcept;
0437 function& operator=(nullptr_t) noexcept;
0438 template<class F>
0439 function& operator=(F&&);
0440 template<class F>
0441 function& operator=(reference_wrapper<F>) noexcept;
0442
0443 ~function();
0444
0445 // function modifiers:
0446 void swap(function&) noexcept;
0447 template<class F, class Alloc>
0448 void assign(F&&, const Alloc&); // Removed in C++17
0449
0450 // function capacity:
0451 explicit operator bool() const noexcept;
0452
0453 // function invocation:
0454 R operator()(ArgTypes...) const;
0455
0456 // function target access:
0457 const std::type_info& target_type() const noexcept;
0458 template <typename T> T* target() noexcept;
0459 template <typename T> const T* target() const noexcept;
0460 };
0461
0462 // Deduction guides
0463 template<class R, class ...Args>
0464 function(R(*)(Args...)) -> function<R(Args...)>; // since C++17
0465
0466 template<class F>
0467 function(F) -> function<see-below>; // since C++17
0468
0469 // Null pointer comparisons:
0470 template <class R, class ... ArgTypes>
0471 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
0472
0473 template <class R, class ... ArgTypes>
0474 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; // removed in C++20
0475
0476 template <class R, class ... ArgTypes>
0477 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; // removed in C++20
0478
0479 template <class R, class ... ArgTypes>
0480 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; // removed in C++20
0481
0482 // specialized algorithms:
0483 template <class R, class ... ArgTypes>
0484 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
0485
0486 template <class T> struct hash;
0487
0488 template <> struct hash<bool>;
0489 template <> struct hash<char>;
0490 template <> struct hash<signed char>;
0491 template <> struct hash<unsigned char>;
0492 template <> struct hash<char8_t>; // since C++20
0493 template <> struct hash<char16_t>;
0494 template <> struct hash<char32_t>;
0495 template <> struct hash<wchar_t>;
0496 template <> struct hash<short>;
0497 template <> struct hash<unsigned short>;
0498 template <> struct hash<int>;
0499 template <> struct hash<unsigned int>;
0500 template <> struct hash<long>;
0501 template <> struct hash<long long>;
0502 template <> struct hash<unsigned long>;
0503 template <> struct hash<unsigned long long>;
0504
0505 template <> struct hash<float>;
0506 template <> struct hash<double>;
0507 template <> struct hash<long double>;
0508
0509 template<class T> struct hash<T*>;
0510 template <> struct hash<nullptr_t>; // C++17
0511
0512 namespace ranges {
0513 // [range.cmp], concept-constrained comparisons
0514 struct equal_to;
0515 struct not_equal_to;
0516 struct greater;
0517 struct less;
0518 struct greater_equal;
0519 struct less_equal;
0520 }
0521
0522 } // std
0523
0524 POLICY: For non-variadic implementations, the number of arguments is limited
0525 to 3. It is hoped that the need for non-variadic implementations
0526 will be minimal.
0527
0528 */
0529
0530 #include <__cxx03/__config>
0531
0532 #include <__cxx03/__functional/binary_function.h>
0533 #include <__cxx03/__functional/binary_negate.h>
0534 #include <__cxx03/__functional/bind.h>
0535 #include <__cxx03/__functional/binder1st.h>
0536 #include <__cxx03/__functional/binder2nd.h>
0537 #include <__cxx03/__functional/hash.h>
0538 #include <__cxx03/__functional/mem_fn.h> // TODO: deprecate
0539 #include <__cxx03/__functional/mem_fun_ref.h>
0540 #include <__cxx03/__functional/operations.h>
0541 #include <__cxx03/__functional/pointer_to_binary_function.h>
0542 #include <__cxx03/__functional/pointer_to_unary_function.h>
0543 #include <__cxx03/__functional/reference_wrapper.h>
0544 #include <__cxx03/__functional/unary_function.h>
0545 #include <__cxx03/__functional/unary_negate.h>
0546
0547 #ifndef _LIBCPP_CXX03_LANG
0548 # include <__cxx03/__functional/function.h>
0549 #endif
0550
0551 #if _LIBCPP_STD_VER >= 17
0552 # include <__cxx03/__functional/boyer_moore_searcher.h>
0553 # include <__cxx03/__functional/default_searcher.h>
0554 # include <__cxx03/__functional/invoke.h>
0555 # include <__cxx03/__functional/not_fn.h>
0556 #endif
0557
0558 #if _LIBCPP_STD_VER >= 20
0559 # include <__cxx03/__functional/bind_back.h>
0560 # include <__cxx03/__functional/bind_front.h>
0561 # include <__cxx03/__functional/identity.h>
0562 # include <__cxx03/__functional/ranges_operations.h>
0563 # include <__cxx03/__type_traits/unwrap_ref.h>
0564 #endif
0565
0566 #include <__cxx03/version>
0567
0568 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0569 # pragma GCC system_header
0570 #endif
0571
0572 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && defined(_LIBCPP_CXX03_LANG)
0573 # include <__cxx03/limits>
0574 # include <__cxx03/new>
0575 #endif
0576
0577 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 14
0578 # include <__cxx03/array>
0579 # include <__cxx03/initializer_list>
0580 # include <__cxx03/unordered_map>
0581 # include <__cxx03/vector>
0582 #endif
0583
0584 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
0585 # include <__cxx03/atomic>
0586 # include <__cxx03/concepts>
0587 # include <__cxx03/cstdlib>
0588 # include <__cxx03/exception>
0589 # include <__cxx03/iosfwd>
0590 # include <__cxx03/memory>
0591 # include <__cxx03/stdexcept>
0592 # include <__cxx03/tuple>
0593 # include <__cxx03/type_traits>
0594 # include <__cxx03/typeinfo>
0595 # include <__cxx03/utility>
0596 #endif
0597
0598 #endif // _LIBCPP___CXX03_FUNCTIONAL