1 // Copyright (C) 2013 Eurodecision
2 // Authors: Guillaume Pinot
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // See http://www.boost.org/libs/property_map for documentation.
10 #ifndef BOOST_PROPERTY_MAP_COMPOSE_PROPERTY_MAP_HPP
11 #define BOOST_PROPERTY_MAP_COMPOSE_PROPERTY_MAP_HPP
13 #include <boost/property_map/property_map.hpp>
14 #include <boost/type_traits.hpp>
18 // A compose property map: make_compose_property_map(f, g)[x] == f[g[x]]
20 // g must be a readable property map.
21 // The category of compose_property_map(f, g) is the category of f.
23 template <typename FPMap
, typename GPMap
>
24 class compose_property_map
27 typedef typename
boost::property_traits
<FPMap
>::category category
;
28 typedef typename
boost::property_traits
<GPMap
>::key_type key_type
;
29 typedef typename
boost::property_traits
<FPMap
>::value_type value_type
;
30 typedef typename
boost::property_traits
<FPMap
>::reference reference
;
32 inline compose_property_map(const FPMap
&f_p
, const GPMap
&g_p
):
36 inline compose_property_map() {}
39 operator[](const key_type
&v
) const {
43 // return type of get():
44 // if (reference is not a ref)
46 // else if (reference is const)
50 inline friend typename
boost::mpl::if_
<
51 boost::mpl::not_
< boost::is_reference
<reference
> >,
53 typename
boost::mpl::if_
<
54 boost::is_const
<reference
>,
59 get(const compose_property_map
&m
, const key_type
&k
) {
60 return get(m
.f
, get(m
.g
, k
));
64 put(const compose_property_map
&m
, const key_type
&k
, const value_type
&v
) {
65 put(m
.f
, get(m
.g
, k
), v
);
73 template <class FPMap
, class GPMap
>
74 inline compose_property_map
<FPMap
, GPMap
>
75 make_compose_property_map(const FPMap
&f
, const GPMap
&g
) {
76 return compose_property_map
<FPMap
, GPMap
>(f
, g
);
81 #endif // BOOST_PROPERTY_MAP_COMPOSE_PROPERTY_MAP_HPP