sl@0: // sl@0: //======================================================================= sl@0: // Copyright 1997, 1998, 1999, 2000 University of Notre Dame. sl@0: // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek sl@0: // sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: //======================================================================= sl@0: // sl@0: sl@0: #ifndef BOOST_INDIRECT_CMP_HPP sl@0: #define BOOST_INDIRECT_CMP_HPP sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: namespace boost { sl@0: sl@0: //: indirect_cmp sl@0: // sl@0: // could also do this with compose_f_gx_hx, and the member binder... sl@0: // sl@0: //!category: functors sl@0: //!component: type sl@0: //!tparam: ReadablePropertyMap - a model of ReadablePropertyMap sl@0: //!definition: functor.h sl@0: template sl@0: class indirect_cmp { sl@0: public: sl@0: typedef typename boost::property_traits::value_type T; sl@0: typedef typename boost::property_traits::key_type K; sl@0: typedef K first_argument_type; sl@0: typedef K second_argument_type; sl@0: typedef T result_type; sl@0: inline indirect_cmp(const ReadablePropertyMap& df, const Compare& c = Compare()) sl@0: : d(df), cmp(c) { } sl@0: sl@0: template sl@0: inline bool sl@0: operator()(const A& u, const B& v) const { sl@0: T du = get(d, u), dv = get(d, v); sl@0: return cmp(du, dv); sl@0: } sl@0: protected: sl@0: ReadablePropertyMap d; sl@0: Compare cmp; sl@0: }; sl@0: sl@0: template sl@0: indirect_cmp sl@0: make_indirect_cmp(const Compare& cmp, ReadablePropertyMap pmap) { sl@0: indirect_cmp p(pmap, cmp); sl@0: return p; sl@0: } sl@0: sl@0: template sl@0: class indirect_pmap { sl@0: public: sl@0: typedef typename boost::property_traits::value_type T; sl@0: typedef typename boost::property_traits::key_type K; sl@0: typedef K argument_type; sl@0: typedef T result_type; sl@0: inline indirect_pmap(const ReadablePropertyMap& df) sl@0: : d(df) { } sl@0: sl@0: inline bool operator()(const K& u) const { sl@0: return get(d, u); sl@0: } sl@0: protected: sl@0: ReadablePropertyMap d; sl@0: }; sl@0: sl@0: template sl@0: indirect_pmap sl@0: make_indirect_pmap(ReadablePropertyMap pmap) { sl@0: indirect_pmap f(pmap); sl@0: return f; sl@0: } sl@0: sl@0: sl@0: } // namespace boost sl@0: sl@0: sl@0: #endif // GGCL_INDIRECT_CMP_HPP