Chris@16
|
1 //
|
Chris@16
|
2 //=======================================================================
|
Chris@16
|
3 // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
|
Chris@16
|
4 // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
|
Chris@16
|
5 //
|
Chris@16
|
6 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
7 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
8 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 //=======================================================================
|
Chris@16
|
10 //
|
Chris@16
|
11
|
Chris@16
|
12 #ifndef BOOST_INDIRECT_CMP_HPP
|
Chris@16
|
13 #define BOOST_INDIRECT_CMP_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #include <functional>
|
Chris@16
|
16 #include <boost/config.hpp>
|
Chris@16
|
17 #include <boost/property_map/property_map.hpp>
|
Chris@16
|
18
|
Chris@16
|
19 namespace boost {
|
Chris@16
|
20
|
Chris@16
|
21 //: indirect_cmp
|
Chris@16
|
22 //
|
Chris@16
|
23 // could also do this with compose_f_gx_hx, and the member binder...
|
Chris@16
|
24 //
|
Chris@16
|
25 //!category: functors
|
Chris@16
|
26 //!component: type
|
Chris@16
|
27 //!tparam: ReadablePropertyMap - a model of ReadablePropertyMap
|
Chris@16
|
28 //!definition: functor.h
|
Chris@16
|
29 template <class ReadablePropertyMap, class Compare>
|
Chris@16
|
30 class indirect_cmp {
|
Chris@16
|
31 public:
|
Chris@16
|
32 typedef typename boost::property_traits<ReadablePropertyMap>::value_type T;
|
Chris@16
|
33 typedef typename boost::property_traits<ReadablePropertyMap>::key_type K;
|
Chris@16
|
34 typedef K first_argument_type;
|
Chris@16
|
35 typedef K second_argument_type;
|
Chris@16
|
36 typedef bool result_type;
|
Chris@16
|
37 inline indirect_cmp(const ReadablePropertyMap& df, const Compare& c = Compare())
|
Chris@16
|
38 : d(df), cmp(c) { }
|
Chris@16
|
39
|
Chris@16
|
40 template <class A, class B>
|
Chris@16
|
41 inline bool
|
Chris@16
|
42 operator()(const A& u, const B& v) const {
|
Chris@16
|
43 const T& du = get(d, u);
|
Chris@16
|
44 const T& dv = get(d, v);
|
Chris@16
|
45 return cmp(du, dv);
|
Chris@16
|
46 }
|
Chris@16
|
47 protected:
|
Chris@16
|
48 ReadablePropertyMap d;
|
Chris@16
|
49 Compare cmp;
|
Chris@16
|
50 };
|
Chris@16
|
51
|
Chris@16
|
52 template <typename Compare, typename ReadablePropertyMap>
|
Chris@16
|
53 indirect_cmp<ReadablePropertyMap, Compare>
|
Chris@16
|
54 make_indirect_cmp(const Compare& cmp, ReadablePropertyMap pmap) {
|
Chris@16
|
55 indirect_cmp<ReadablePropertyMap, Compare> p(pmap, cmp);
|
Chris@16
|
56 return p;
|
Chris@16
|
57 }
|
Chris@16
|
58
|
Chris@16
|
59 template <class ReadablePropertyMap>
|
Chris@16
|
60 class indirect_pmap {
|
Chris@16
|
61 public:
|
Chris@16
|
62 typedef typename boost::property_traits<ReadablePropertyMap>::value_type T;
|
Chris@16
|
63 typedef typename boost::property_traits<ReadablePropertyMap>::key_type K;
|
Chris@16
|
64 typedef K argument_type;
|
Chris@16
|
65 typedef T result_type;
|
Chris@16
|
66 inline indirect_pmap(const ReadablePropertyMap& df)
|
Chris@16
|
67 : d(df) { }
|
Chris@16
|
68
|
Chris@16
|
69 inline T operator()(const K& u) const {
|
Chris@16
|
70 return get(d, u);
|
Chris@16
|
71 }
|
Chris@16
|
72 protected:
|
Chris@16
|
73 ReadablePropertyMap d;
|
Chris@16
|
74 };
|
Chris@16
|
75
|
Chris@16
|
76 template <typename ReadablePropertyMap>
|
Chris@16
|
77 indirect_pmap<ReadablePropertyMap>
|
Chris@16
|
78 make_indirect_pmap(ReadablePropertyMap pmap) {
|
Chris@16
|
79 indirect_pmap<ReadablePropertyMap> f(pmap);
|
Chris@16
|
80 return f;
|
Chris@16
|
81 }
|
Chris@16
|
82
|
Chris@16
|
83
|
Chris@16
|
84 } // namespace boost
|
Chris@16
|
85
|
Chris@16
|
86
|
Chris@16
|
87 #endif // GGCL_INDIRECT_CMP_HPP
|