Chris@16
|
1 //
|
Chris@16
|
2 //=======================================================================
|
Chris@16
|
3 // Author: Philipp Moeller
|
Chris@16
|
4 //
|
Chris@16
|
5 // Copyright 2012, Philipp Moeller
|
Chris@16
|
6 //
|
Chris@16
|
7 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
8 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
9 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
10 //=======================================================================
|
Chris@16
|
11 //
|
Chris@16
|
12
|
Chris@16
|
13 #ifndef BOOST_PROPERTY_MAP_FUNCTION_PROPERTY_MAP_HPP
|
Chris@16
|
14 #define BOOST_PROPERTY_MAP_FUNCTION_PROPERTY_MAP_HPP
|
Chris@16
|
15
|
Chris@16
|
16 #include <boost/config.hpp>
|
Chris@16
|
17 #include <boost/property_map/property_map.hpp>
|
Chris@16
|
18 #include <boost/type_traits.hpp>
|
Chris@16
|
19 #include <boost/utility/result_of.hpp>
|
Chris@16
|
20 #include <boost/mpl/and.hpp>
|
Chris@16
|
21 #include <boost/mpl/not.hpp>
|
Chris@16
|
22 #include <utility>
|
Chris@16
|
23
|
Chris@16
|
24 namespace boost {
|
Chris@16
|
25
|
Chris@16
|
26 template<typename Func, typename Key, typename Ret = typename boost::result_of<const Func(const Key&)>::type>
|
Chris@16
|
27 class function_property_map: public put_get_helper<Ret, function_property_map<Func, Key, Ret> > {
|
Chris@16
|
28 public:
|
Chris@16
|
29 typedef Key key_type;
|
Chris@16
|
30 typedef Ret reference;
|
Chris@16
|
31 typedef typename boost::remove_cv<typename boost::remove_reference<Ret>::type>::type value_type;
|
Chris@16
|
32
|
Chris@16
|
33 typedef typename boost::mpl::if_<
|
Chris@16
|
34 boost::mpl::and_<
|
Chris@16
|
35 boost::is_reference<Ret>,
|
Chris@16
|
36 boost::mpl::not_<boost::is_const<Ret> >
|
Chris@16
|
37 >,
|
Chris@16
|
38 boost::lvalue_property_map_tag,
|
Chris@16
|
39 boost::readable_property_map_tag>::type
|
Chris@16
|
40 category;
|
Chris@16
|
41
|
Chris@16
|
42 function_property_map(Func f = Func()) : f(f) {}
|
Chris@16
|
43
|
Chris@16
|
44 reference operator[](const Key& k) const {
|
Chris@16
|
45 return f(k);
|
Chris@16
|
46 }
|
Chris@16
|
47
|
Chris@16
|
48 private:
|
Chris@16
|
49 Func f;
|
Chris@16
|
50 };
|
Chris@16
|
51
|
Chris@16
|
52 template<typename Key, typename Func>
|
Chris@16
|
53 function_property_map<Func, Key>
|
Chris@16
|
54 make_function_property_map(const Func& f) {
|
Chris@16
|
55 return function_property_map<Func, Key>(f);
|
Chris@16
|
56 }
|
Chris@16
|
57
|
Chris@16
|
58 template<typename Key, typename Ret, typename Func>
|
Chris@16
|
59 function_property_map<Func, Key, Ret>
|
Chris@16
|
60 make_function_property_map(const Func& f) {
|
Chris@16
|
61 return function_property_map<Func, Key, Ret>(f);
|
Chris@16
|
62 }
|
Chris@16
|
63
|
Chris@16
|
64 } // boost
|
Chris@16
|
65
|
Chris@16
|
66 #endif /* BOOST_PROPERTY_MAP_FUNCTION_PROPERTY_MAP_HPP */
|