Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:16

0001 //
0002 //=======================================================================
0003 // Author: Philipp Moeller
0004 //
0005 // Copyright 2012, Philipp Moeller
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See
0008 // accompanying file LICENSE_1_0.txt or copy at
0009 // http://www.boost.org/LICENSE_1_0.txt)
0010 //=======================================================================
0011 //
0012 
0013 #ifndef BOOST_PROPERTY_MAP_FUNCTION_PROPERTY_MAP_HPP
0014 #define BOOST_PROPERTY_MAP_FUNCTION_PROPERTY_MAP_HPP
0015 
0016 #include <boost/config.hpp>
0017 #include <boost/property_map/property_map.hpp>
0018 #include <boost/type_traits.hpp>
0019 #include <boost/utility/result_of.hpp>
0020 #include <boost/mpl/and.hpp>
0021 #include <boost/mpl/not.hpp>
0022 #include <utility>
0023 
0024 namespace boost {
0025 
0026 template<typename Func, typename Key, typename Ret = typename boost::result_of<const Func(const Key&)>::type>
0027 class function_property_map: public put_get_helper<Ret, function_property_map<Func, Key, Ret> > {
0028   public:
0029   typedef Key key_type;
0030   typedef Ret reference;
0031   typedef typename boost::remove_cv<typename boost::remove_reference<Ret>::type>::type value_type;
0032 
0033   typedef typename boost::mpl::if_<
0034                      boost::mpl::and_<
0035                        boost::is_reference<Ret>,
0036                        boost::mpl::not_<boost::is_const<Ret> >
0037                      >,
0038                      boost::lvalue_property_map_tag,
0039                      boost::readable_property_map_tag>::type
0040     category;
0041 
0042   function_property_map(Func f = Func()) : f(f) {}
0043 
0044   reference operator[](const Key& k) const {
0045     return f(k);
0046   }
0047 
0048   private:
0049   Func f;
0050 };
0051 
0052 template<typename Key, typename Func>
0053 function_property_map<Func, Key>
0054 make_function_property_map(const Func& f) {
0055   return function_property_map<Func, Key>(f);
0056 }
0057 
0058 template<typename Key, typename Ret, typename Func>
0059 function_property_map<Func, Key, Ret>
0060 make_function_property_map(const Func& f) {
0061   return function_property_map<Func, Key, Ret>(f);
0062 }
0063 
0064 } // boost
0065 
0066 #endif /* BOOST_PROPERTY_MAP_FUNCTION_PROPERTY_MAP_HPP */