source: NonGTP/Boost/boost/pending/indirect_cmp.hpp @ 857

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