]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/bimap/include/boost/bimap/views/unordered_map_view.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / bimap / include / boost / bimap / views / unordered_map_view.hpp
1 // Boost.Bimap
2 //
3 // Copyright (c) 2006-2007 Matias Capeletto
4 //
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8
9 /// \file views/unordered_map_view.hpp
10 /// \brief View of a side of a bimap that is signature compatible with tr1::unordered_map.
11
12 #ifndef BOOST_BIMAP_VIEWS_UNOREDERED_MAP_VIEW_HPP
13 #define BOOST_BIMAP_VIEWS_UNOREDERED_MAP_VIEW_HPP
14
15 #if defined(_MSC_VER)
16 #pragma once
17 #endif
18
19 #include <boost/config.hpp>
20
21 #include <utility>
22
23 #include <boost/bimap/container_adaptor/unordered_map_adaptor.hpp>
24 #include <boost/bimap/detail/map_view_base.hpp>
25
26 namespace boost {
27 namespace bimaps {
28 namespace views {
29
30 /// \brief Map View of a bimap, signature compatible with tr1::unordered_map.
31 /**
32
33 This class uses container_adaptor and iterator_adaptor to wrapped a index of the
34 multi_index bimap core so it can be used as a tr1::unordered_map.
35
36 See also const_unordered_map_view.
37 **/
38
39
40 template< class Tag, class BimapType >
41 class unordered_map_view
42 :
43 public BOOST_BIMAP_MAP_VIEW_CONTAINER_ADAPTOR(
44 unordered_map_adaptor,
45 Tag,BimapType,
46 local_map_view_iterator,const_local_map_view_iterator
47 ),
48
49 public ::boost::bimaps::detail::map_view_base<
50 unordered_map_view<Tag,BimapType>,Tag,BimapType >,
51 public ::boost::bimaps::detail::
52 unique_map_view_access<
53 unordered_map_view<Tag,BimapType>, Tag, BimapType>::type
54
55 {
56 typedef BOOST_BIMAP_MAP_VIEW_CONTAINER_ADAPTOR(
57 unordered_map_adaptor,
58 Tag,BimapType,
59 local_map_view_iterator,const_local_map_view_iterator
60
61 ) base_;
62
63 BOOST_BIMAP_MAP_VIEW_BASE_FRIEND(unordered_map_view,Tag,BimapType)
64
65 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::detail::
66 unique_map_view_access<
67 unordered_map_view<Tag,BimapType>, Tag, BimapType
68
69 >::type unique_map_view_access_;
70
71 public:
72
73 typedef std::pair<
74 BOOST_DEDUCED_TYPENAME base_::iterator,
75 BOOST_DEDUCED_TYPENAME base_::iterator
76 > range_type;
77
78 typedef std::pair<
79 BOOST_DEDUCED_TYPENAME base_::const_iterator,
80 BOOST_DEDUCED_TYPENAME base_::const_iterator
81 > const_range_type;
82
83 typedef BOOST_DEDUCED_TYPENAME base_::value_type::info_type info_type;
84
85 unordered_map_view(BOOST_DEDUCED_TYPENAME base_::base_type & c)
86 : base_(c) {}
87
88 using unique_map_view_access_::at;
89 using unique_map_view_access_::operator[];
90
91 unordered_map_view & operator=(const unordered_map_view & v)
92 {
93 this->base() = v.base();
94 return *this;
95 }
96
97 // It can be used enable_if here but the error message when there
98 // is no info is very clear like this
99
100 template< class CompatibleKey >
101 const info_type & info_at(const CompatibleKey& k) const
102 {
103 BOOST_DEDUCED_TYPENAME base_::const_iterator iter = this->find(k);
104 if( iter == this->end() )
105 {
106 ::boost::throw_exception(
107 std::out_of_range("bimap<>: invalid key")
108 );
109 }
110 return iter->info;
111 }
112
113 template< class CompatibleKey >
114 info_type & info_at(const CompatibleKey& k)
115 {
116 BOOST_DEDUCED_TYPENAME base_::iterator iter = this->find(k);
117 if( iter == this->end() )
118 {
119 ::boost::throw_exception(
120 std::out_of_range("bimap<>: invalid key")
121 );
122 }
123 return iter->info;
124 }
125 };
126
127
128 } // namespace views
129
130 /*===========================================================================*/
131 #define BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,TYPENAME) \
132 typedef BOOST_DEDUCED_TYPENAME MAP_VIEW::TYPENAME \
133 BOOST_PP_CAT(SIDE,BOOST_PP_CAT(_,TYPENAME));
134 /*===========================================================================*/
135
136 /*===========================================================================*/
137 #define BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(MAP_VIEW,SIDE) \
138 BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,local_iterator) \
139 BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,const_local_iterator) \
140 BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,range_type) \
141 BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,const_range_type) \
142 BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,hasher) \
143 BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,key_equal)
144 /*===========================================================================*/
145
146 namespace detail {
147
148 template< class Tag, class BimapType >
149 struct left_map_view_extra_typedefs< ::boost::bimaps::views::unordered_map_view<Tag,BimapType> >
150 {
151 private: typedef ::boost::bimaps::views::unordered_map_view<Tag,BimapType> map_view_;
152 public : BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(map_view_,left)
153 };
154
155 template< class Tag, class BimapType >
156 struct right_map_view_extra_typedefs< ::boost::bimaps::views::unordered_map_view<Tag,BimapType> >
157 {
158 private: typedef ::boost::bimaps::views::unordered_map_view<Tag,BimapType> map_view_;
159 public : BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(map_view_,right)
160 };
161
162 } // namespace detail
163
164 /*===========================================================================*/
165 #undef BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF
166 #undef BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY
167 /*===========================================================================*/
168
169 } // namespace bimaps
170 } // namespace boost
171
172 #endif // BOOST_BIMAP_VIEWS_UNOREDERED_MAP_VIEW_HPP
173
174