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