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 R, class C, class A> class_fun_t<R, C, A>
23 class_fun(C & c, R(C::*f)(A))
25 return class_fun_t<R, C, A>(c, f);
29 template <class Cont, class Type, class MemRet>
30 class back_insert_fun_iterator {
35 back_insert_fun_iterator(Cont & x, MemRet(Type::*p)())
36 : container(x), pmf(p) {}
38 back_insert_fun_iterator &
39 operator=(Type * val) {
40 container.push_back((val->*pmf)());
44 back_insert_fun_iterator &
45 operator=(Type & val) {
46 container.push_back((val.*pmf)());
50 back_insert_fun_iterator & operator*() {
53 back_insert_fun_iterator & operator++() { // prefix ++
56 back_insert_fun_iterator & operator++(int) { // postfix ++
62 template <class Cont, class Type, class MemRet>
63 back_insert_fun_iterator<Cont, Type, MemRet>
64 back_inserter_fun(Cont & cont, MemRet(Type::*p)())
66 return back_insert_fun_iterator<Cont, Type, MemRet>(cont, p);
70 template <class R, class C, class A>
71 class compare_memfun_t {
73 compare_memfun_t(R(C::*p)(), A const & a)
75 bool operator()(C * c) {
76 return (c->*pmf)() == arg;
78 bool operator()(C & c) {
79 return (c.*pmf)() == arg;
87 template <class R, class C, class A>
88 compare_memfun_t<R, C, A>
89 compare_memfun(R(C::*p)(), A const & a)
91 return compare_memfun_t<R, C, A>(p, a);
95 // Functors used in the template.
98 template<typename T1, typename T2>
99 class equal_1st_in_pair {
102 equal_1st_in_pair(T1 const & value) : value_(value) {}
104 typedef std::pair<T1, T2> pair_type;
106 bool operator() (pair_type const & p) const {
107 return p.first == value_;
116 template<typename T1, typename T2>
117 class equal_2nd_in_pair {
120 equal_2nd_in_pair(T2 const & value) : value_(value) {}
122 typedef std::pair<T1, T2> pair_type;
124 bool operator() (pair_type const & p) const {
125 return p.second == value_;
133 // } // end of namespace lyx