3 * \file lyxfunctional.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
11 * \brief Convenient function objects for use with LyX
13 * This is currently a small collection of small function objects for use
14 * together with std::algorithms.
18 #ifndef LYX_FUNCTIONAL_H
19 #define LYX_FUNCTIONAL_H
25 template <class R, class C, class A>
26 class compare_memfun_t {
28 compare_memfun_t(R(C::*p)(), A const & a)
30 bool operator()(C * c) {
31 return (c->*pmf)() == arg;
33 bool operator()(C & c) {
34 return (c.*pmf)() == arg;
42 template <class R, class C, class A>
43 class const_compare_memfun_t {
45 const_compare_memfun_t(R(C::*p)() const, A const & a)
47 bool operator()(C const * c) {
48 return (c->*pmf)() == arg;
50 bool operator()(C const & c) {
51 return (c.*pmf)() == arg;
59 template <class R, class C, class A>
60 compare_memfun_t<R, C, A>
61 compare_memfun(R(C::*p)(), A const & a)
63 return compare_memfun_t<R, C, A>(p, a);
67 template <class R, class C, class A>
68 const_compare_memfun_t<R, C, A>
69 compare_memfun(R(C::*p)() const, A const & a)
71 return const_compare_memfun_t<R, C, A>(p, a);
75 // Functors used in the template.
79 class equal_1st_in_pair {
82 typedef typename T::first_type first_type;
86 equal_1st_in_pair(first_type const & value) : value_(value) {}
88 bool operator() (pair_type const & p) const {
89 return p.first == value_;
93 first_type const & value_;
99 class equal_2nd_in_pair {
102 typedef typename T::second_type second_type;
106 equal_2nd_in_pair(second_type const & value) : value_(value) {}
108 bool operator() (pair_type const & p) const {
109 return p.second == value_;
113 second_type const & value_;
116 } // end of namespace lyx