2 //=======================================================================
3 // Author: Philipp Moeller
5 // Copyright 2012, Philipp Moeller
7 // Distributed under the Boost Software License, Version 1.0. (See
8 // accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 //=======================================================================
13 #ifndef BOOST_PROPERTY_MAP_FUNCTION_PROPERTY_MAP_HPP
14 #define BOOST_PROPERTY_MAP_FUNCTION_PROPERTY_MAP_HPP
16 #include <boost/config.hpp>
17 #include <boost/property_map/property_map.hpp>
18 #include <boost/type_traits.hpp>
19 #include <boost/utility/result_of.hpp>
20 #include <boost/mpl/and.hpp>
21 #include <boost/mpl/not.hpp>
26 template<typename Func, typename Key, typename Ret = typename boost::result_of<const Func(const Key&)>::type>
27 class function_property_map: public put_get_helper<Ret, function_property_map<Func, Key, Ret> > {
30 typedef Ret reference;
31 typedef typename boost::remove_cv<typename boost::remove_reference<Ret>::type>::type value_type;
33 typedef typename boost::mpl::if_<
35 boost::is_reference<Ret>,
36 boost::mpl::not_<boost::is_const<Ret> >
38 boost::lvalue_property_map_tag,
39 boost::readable_property_map_tag>::type
42 function_property_map(Func f = Func()) : f(f) {}
44 reference operator[](const Key& k) const {
52 template<typename Key, typename Func>
53 function_property_map<Func, Key>
54 make_function_property_map(const Func& f) {
55 return function_property_map<Func, Key>(f);
58 template<typename Key, typename Ret, typename Func>
59 function_property_map<Func, Key, Ret>
60 make_function_property_map(const Func& f) {
61 return function_property_map<Func, Key, Ret>(f);
66 #endif /* BOOST_PROPERTY_MAP_FUNCTION_PROPERTY_MAP_HPP */