Project revived from Feb2017
[EroSomnia.git] / deps / boost_1_63_0 / boost / property_map / compose_property_map.hpp
blob4d8941d38e3268091cf9df75f721fbe2686ddcd7
1 // Copyright (C) 2013 Eurodecision
2 // Authors: Guillaume Pinot
3 //
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)
7 //
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>
16 namespace boost {
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
26 public:
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):
33 f(f_p), g(g_p)
36 inline compose_property_map() {}
38 inline reference
39 operator[](const key_type &v) const {
40 return f[get(g, v)];
43 // return type of get():
44 // if (reference is not a ref)
45 // value_type
46 // else if (reference is const)
47 // reference
48 // else
49 // const value_type&
50 inline friend typename boost::mpl::if_<
51 boost::mpl::not_< boost::is_reference<reference> >,
52 value_type,
53 typename boost::mpl::if_<
54 boost::is_const<reference>,
55 reference,
56 const value_type&
57 >::type
58 >::type
59 get(const compose_property_map &m, const key_type &k) {
60 return get(m.f, get(m.g, k));
63 inline friend void
64 put(const compose_property_map &m, const key_type &k, const value_type &v) {
65 put(m.f, get(m.g, k), v);
68 private:
69 FPMap f;
70 GPMap g;
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);
79 } // namespace boost
81 #endif // BOOST_PROPERTY_MAP_COMPOSE_PROPERTY_MAP_HPP