3 #ifndef LYX_FUNCTIONAL_H
4 #define LYX_FUNCTIONAL_H
8 template<class R, class C, class A>
11 class_fun_t(C & ct, R(C::*p)(A))
13 R operator()(A & a) const {
22 template<class C, class A>
23 class void_class_fun_t {
25 void_class_fun_t(C & ct, void(C::*p)(A))
27 void operator()(A & a) const {
36 template <class R, class C, class A> class_fun_t<R, C, A>
37 class_fun(C & c, R(C::*f)(A))
39 return class_fun_t<R, C, A>(c, f);
43 template <class C, class A> void_class_fun_t<C, A>
44 class_fun(C & c, void(C::*f)(A))
46 return void_class_fun_t<C, A>(c, f);
50 template <class Cont, class Type, class MemRet>
51 class back_insert_fun_iterator {
56 back_insert_fun_iterator(Cont & x, MemRet(Type::*p)())
57 : container(x), pmf(p) {}
59 back_insert_fun_iterator &
60 operator=(Type * val) {
61 container.push_back((val->*pmf)());
65 back_insert_fun_iterator &
66 operator=(Type & val) {
67 container.push_back((val.*pmf)());
71 back_insert_fun_iterator & operator*() {
74 back_insert_fun_iterator & operator++() { // prefix ++
77 back_insert_fun_iterator & operator++(int) { // postfix ++
83 template <class Cont, class Type, class MemRet>
84 class const_back_insert_fun_iterator {
87 MemRet(Type::*pmf)() const;
89 const_back_insert_fun_iterator(Cont & x, MemRet(Type::*p)() const)
90 : container(x), pmf(p) {}
92 const_back_insert_fun_iterator &
93 operator=(Type const * val) {
94 container.push_back((val->*pmf)());
98 const_back_insert_fun_iterator &
99 operator=(Type const & val) {
100 container.push_back((val.*pmf)());
104 const_back_insert_fun_iterator & operator*() {
107 const_back_insert_fun_iterator & operator++() { // prefix ++
110 const_back_insert_fun_iterator & operator++(int) { // postfix ++
116 template <class Cont, class Type, class MemRet>
117 back_insert_fun_iterator<Cont, Type, MemRet>
118 back_inserter_fun(Cont & cont, MemRet(Type::*p)())
120 return back_insert_fun_iterator<Cont, Type, MemRet>(cont, p);
124 template <class Cont, class Type, class MemRet>
125 const_back_insert_fun_iterator<Cont, Type, MemRet>
126 back_inserter_fun(Cont & cont, MemRet(Type::*p)() const)
128 return const_back_insert_fun_iterator<Cont, Type, MemRet>(cont, p);
132 template <class R, class C, class A>
133 class compare_memfun_t {
135 compare_memfun_t(R(C::*p)(), A const & a)
137 bool operator()(C * c) {
138 return (c->*pmf)() == arg;
140 bool operator()(C & c) {
141 return (c.*pmf)() == arg;
149 template <class R, class C, class A>
150 class const_compare_memfun_t {
152 const_compare_memfun_t(R(C::*p)() const, A const & a)
154 bool operator()(C const * c) {
155 return (c->*pmf)() == arg;
157 bool operator()(C const & c) {
158 return (c.*pmf)() == arg;
166 template <class R, class C, class A>
167 compare_memfun_t<R, C, A>
168 compare_memfun(R(C::*p)(), A const & a)
170 return compare_memfun_t<R, C, A>(p, a);
174 template <class R, class C, class A>
175 const_compare_memfun_t<R, C, A>
176 compare_memfun(R(C::*p)() const, A const & a)
178 return const_compare_memfun_t<R, C, A>(p, a);
182 // Functors used in the template.
185 template<typename T1, typename T2>
186 class equal_1st_in_pair {
189 equal_1st_in_pair(T1 const & value) : value_(value) {}
191 typedef std::pair<T1, T2> pair_type;
193 bool operator() (pair_type const & p) const {
194 return p.first == value_;
203 template<typename T1, typename T2>
204 class equal_2nd_in_pair {
207 equal_2nd_in_pair(T2 const & value) : value_(value) {}
209 typedef std::pair<T1, T2> pair_type;
211 bool operator() (pair_type const & p) const {
212 return p.second == value_;
220 // } // end of namespace lyx