xref: /freebsd/contrib/llvm-project/libcxx/include/__cxx03/__functional/mem_fun_ref.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
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
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef _LIBCPP___CXX03___FUNCTIONAL_MEM_FUN_REF_H
11 #define _LIBCPP___CXX03___FUNCTIONAL_MEM_FUN_REF_H
12 
13 #include <__cxx03/__config>
14 #include <__cxx03/__functional/binary_function.h>
15 #include <__cxx03/__functional/unary_function.h>
16 
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 #  pragma GCC system_header
19 #endif
20 
21 _LIBCPP_BEGIN_NAMESPACE_STD
22 
23 template <class _Sp, class _Tp>
24 class _LIBCPP_TEMPLATE_VIS mem_fun_t : public __unary_function<_Tp*, _Sp> {
25   _Sp (_Tp::*__p_)();
26 
27 public:
mem_fun_t(_Sp (_Tp::* __p)())28   _LIBCPP_HIDE_FROM_ABI explicit mem_fun_t(_Sp (_Tp::*__p)()) : __p_(__p) {}
operator()29   _LIBCPP_HIDE_FROM_ABI _Sp operator()(_Tp* __p) const { return (__p->*__p_)(); }
30 };
31 
32 template <class _Sp, class _Tp, class _Ap>
33 class _LIBCPP_TEMPLATE_VIS mem_fun1_t : public __binary_function<_Tp*, _Ap, _Sp> {
34   _Sp (_Tp::*__p_)(_Ap);
35 
36 public:
mem_fun1_t(_Sp (_Tp::* __p)(_Ap))37   _LIBCPP_HIDE_FROM_ABI explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) : __p_(__p) {}
operator()38   _LIBCPP_HIDE_FROM_ABI _Sp operator()(_Tp* __p, _Ap __x) const { return (__p->*__p_)(__x); }
39 };
40 
41 template <class _Sp, class _Tp>
mem_fun(_Sp (_Tp::* __f)())42 inline _LIBCPP_HIDE_FROM_ABI mem_fun_t<_Sp, _Tp> mem_fun(_Sp (_Tp::*__f)()) {
43   return mem_fun_t<_Sp, _Tp>(__f);
44 }
45 
46 template <class _Sp, class _Tp, class _Ap>
mem_fun(_Sp (_Tp::* __f)(_Ap))47 inline _LIBCPP_HIDE_FROM_ABI mem_fun1_t<_Sp, _Tp, _Ap> mem_fun(_Sp (_Tp::*__f)(_Ap)) {
48   return mem_fun1_t<_Sp, _Tp, _Ap>(__f);
49 }
50 
51 template <class _Sp, class _Tp>
52 class _LIBCPP_TEMPLATE_VIS mem_fun_ref_t : public __unary_function<_Tp, _Sp> {
53   _Sp (_Tp::*__p_)();
54 
55 public:
mem_fun_ref_t(_Sp (_Tp::* __p)())56   _LIBCPP_HIDE_FROM_ABI explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) : __p_(__p) {}
operator()57   _LIBCPP_HIDE_FROM_ABI _Sp operator()(_Tp& __p) const { return (__p.*__p_)(); }
58 };
59 
60 template <class _Sp, class _Tp, class _Ap>
61 class _LIBCPP_TEMPLATE_VIS mem_fun1_ref_t : public __binary_function<_Tp, _Ap, _Sp> {
62   _Sp (_Tp::*__p_)(_Ap);
63 
64 public:
mem_fun1_ref_t(_Sp (_Tp::* __p)(_Ap))65   _LIBCPP_HIDE_FROM_ABI explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) : __p_(__p) {}
operator()66   _LIBCPP_HIDE_FROM_ABI _Sp operator()(_Tp& __p, _Ap __x) const { return (__p.*__p_)(__x); }
67 };
68 
69 template <class _Sp, class _Tp>
mem_fun_ref(_Sp (_Tp::* __f)())70 inline _LIBCPP_HIDE_FROM_ABI mem_fun_ref_t<_Sp, _Tp> mem_fun_ref(_Sp (_Tp::*__f)()) {
71   return mem_fun_ref_t<_Sp, _Tp>(__f);
72 }
73 
74 template <class _Sp, class _Tp, class _Ap>
mem_fun_ref(_Sp (_Tp::* __f)(_Ap))75 inline _LIBCPP_HIDE_FROM_ABI mem_fun1_ref_t<_Sp, _Tp, _Ap> mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) {
76   return mem_fun1_ref_t<_Sp, _Tp, _Ap>(__f);
77 }
78 
79 template <class _Sp, class _Tp>
80 class _LIBCPP_TEMPLATE_VIS const_mem_fun_t : public __unary_function<const _Tp*, _Sp> {
81   _Sp (_Tp::*__p_)() const;
82 
83 public:
const_mem_fun_t(_Sp (_Tp::* __p)()const)84   _LIBCPP_HIDE_FROM_ABI explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) : __p_(__p) {}
operator()85   _LIBCPP_HIDE_FROM_ABI _Sp operator()(const _Tp* __p) const { return (__p->*__p_)(); }
86 };
87 
88 template <class _Sp, class _Tp, class _Ap>
89 class _LIBCPP_TEMPLATE_VIS const_mem_fun1_t : public __binary_function<const _Tp*, _Ap, _Sp> {
90   _Sp (_Tp::*__p_)(_Ap) const;
91 
92 public:
const_mem_fun1_t(_Sp (_Tp::* __p)(_Ap)const)93   _LIBCPP_HIDE_FROM_ABI explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) : __p_(__p) {}
operator()94   _LIBCPP_HIDE_FROM_ABI _Sp operator()(const _Tp* __p, _Ap __x) const { return (__p->*__p_)(__x); }
95 };
96 
97 template <class _Sp, class _Tp>
mem_fun(_Sp (_Tp::* __f)()const)98 inline _LIBCPP_HIDE_FROM_ABI const_mem_fun_t<_Sp, _Tp> mem_fun(_Sp (_Tp::*__f)() const) {
99   return const_mem_fun_t<_Sp, _Tp>(__f);
100 }
101 
102 template <class _Sp, class _Tp, class _Ap>
mem_fun(_Sp (_Tp::* __f)(_Ap)const)103 inline _LIBCPP_HIDE_FROM_ABI const_mem_fun1_t<_Sp, _Tp, _Ap> mem_fun(_Sp (_Tp::*__f)(_Ap) const) {
104   return const_mem_fun1_t<_Sp, _Tp, _Ap>(__f);
105 }
106 
107 template <class _Sp, class _Tp>
108 class _LIBCPP_TEMPLATE_VIS const_mem_fun_ref_t : public __unary_function<_Tp, _Sp> {
109   _Sp (_Tp::*__p_)() const;
110 
111 public:
const_mem_fun_ref_t(_Sp (_Tp::* __p)()const)112   _LIBCPP_HIDE_FROM_ABI explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) : __p_(__p) {}
operator()113   _LIBCPP_HIDE_FROM_ABI _Sp operator()(const _Tp& __p) const { return (__p.*__p_)(); }
114 };
115 
116 template <class _Sp, class _Tp, class _Ap>
117 class _LIBCPP_TEMPLATE_VIS const_mem_fun1_ref_t : public __binary_function<_Tp, _Ap, _Sp> {
118   _Sp (_Tp::*__p_)(_Ap) const;
119 
120 public:
const_mem_fun1_ref_t(_Sp (_Tp::* __p)(_Ap)const)121   _LIBCPP_HIDE_FROM_ABI explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) : __p_(__p) {}
operator()122   _LIBCPP_HIDE_FROM_ABI _Sp operator()(const _Tp& __p, _Ap __x) const { return (__p.*__p_)(__x); }
123 };
124 
125 template <class _Sp, class _Tp>
mem_fun_ref(_Sp (_Tp::* __f)()const)126 inline _LIBCPP_HIDE_FROM_ABI const_mem_fun_ref_t<_Sp, _Tp> mem_fun_ref(_Sp (_Tp::*__f)() const) {
127   return const_mem_fun_ref_t<_Sp, _Tp>(__f);
128 }
129 
130 template <class _Sp, class _Tp, class _Ap>
mem_fun_ref(_Sp (_Tp::* __f)(_Ap)const)131 inline _LIBCPP_HIDE_FROM_ABI const_mem_fun1_ref_t<_Sp, _Tp, _Ap> mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) {
132   return const_mem_fun1_ref_t<_Sp, _Tp, _Ap>(__f);
133 }
134 
135 _LIBCPP_END_NAMESPACE_STD
136 
137 #endif // _LIBCPP___CXX03___FUNCTIONAL_MEM_FUN_REF_H
138