Chris@16: // Copyright (C) 2013 Eurodecision Chris@16: // Authors: Guillaume Pinot Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // See http://www.boost.org/libs/property_map for documentation. Chris@16: Chris@16: #ifndef BOOST_PROPERTY_MAP_COMPOSE_PROPERTY_MAP_HPP Chris@16: #define BOOST_PROPERTY_MAP_COMPOSE_PROPERTY_MAP_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: // A compose property map: make_compose_property_map(f, g)[x] == f[g[x]] Chris@16: // Chris@16: // g must be a readable property map. Chris@16: // The category of compose_property_map(f, g) is the category of f. Chris@16: Chris@16: template Chris@16: class compose_property_map Chris@16: { Chris@16: public: Chris@16: typedef typename boost::property_traits::category category; Chris@16: typedef typename boost::property_traits::key_type key_type; Chris@16: typedef typename boost::property_traits::value_type value_type; Chris@16: typedef typename boost::property_traits::reference reference; Chris@16: Chris@16: inline compose_property_map(const FPMap &f_p, const GPMap &g_p): Chris@16: f(f_p), g(g_p) Chris@16: {} Chris@16: Chris@16: inline compose_property_map() {} Chris@16: Chris@16: inline reference Chris@16: operator[](const key_type &v) const { Chris@16: return f[get(g, v)]; Chris@16: } Chris@16: Chris@16: // return type of get(): Chris@16: // if (reference is not a ref) Chris@16: // value_type Chris@16: // else if (reference is const) Chris@16: // reference Chris@16: // else Chris@16: // const value_type& Chris@16: inline friend typename boost::mpl::if_< Chris@16: boost::mpl::not_< boost::is_reference >, Chris@16: value_type, Chris@16: typename boost::mpl::if_< Chris@16: boost::is_const, Chris@16: reference, Chris@16: const value_type& Chris@16: >::type Chris@16: >::type Chris@16: get(const compose_property_map &m, const key_type &k) { Chris@16: return get(m.f, get(m.g, k)); Chris@16: } Chris@16: Chris@16: inline friend void Chris@16: put(const compose_property_map &m, const key_type &k, const value_type &v) { Chris@16: put(m.f, get(m.g, k), v); Chris@16: } Chris@16: Chris@16: private: Chris@16: FPMap f; Chris@16: GPMap g; Chris@16: }; Chris@16: Chris@16: template Chris@16: inline compose_property_map Chris@16: make_compose_property_map(const FPMap &f, const GPMap &g) { Chris@16: return compose_property_map(f, g); Chris@16: } Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_PROPERTY_MAP_COMPOSE_PROPERTY_MAP_HPP