3 // Copyright (c) 2006-2007 Matias Capeletto
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)
9 /// \file views/unordered_map_view.hpp
10 /// \brief View of a side of a bimap that is signature compatible with tr1::unordered_map.
12 #ifndef BOOST_BIMAP_VIEWS_UNOREDERED_MAP_VIEW_HPP
13 #define BOOST_BIMAP_VIEWS_UNOREDERED_MAP_VIEW_HPP
15 #if defined(_MSC_VER) && (_MSC_VER>=1200)
19 #include <boost/config.hpp>
23 #include <boost/bimap/container_adaptor/unordered_map_adaptor.hpp>
24 #include <boost/bimap/detail/map_view_base.hpp>
30 /// \brief Map View of a bimap, signature compatible with tr1::unordered_map.
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.
36 See also const_unordered_map_view.
40 template< class Tag, class BimapType >
41 class unordered_map_view
43 public BOOST_BIMAP_MAP_VIEW_CONTAINER_ADAPTOR(
44 unordered_map_adaptor,
46 local_iterator_type_by,const_local_iterator_type_by
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
56 typedef BOOST_BIMAP_MAP_VIEW_CONTAINER_ADAPTOR(
57 unordered_map_adaptor,
59 local_iterator_type_by,const_local_iterator_type_by
63 BOOST_BIMAP_MAP_VIEW_BASE_FRIEND(unordered_map_view,Tag,BimapType)
65 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::detail::
66 unique_map_view_access<
67 unordered_map_view<Tag,BimapType>, Tag, BimapType
69 >::type unique_map_view_access_;
74 BOOST_DEDUCED_TYPENAME base_::iterator,
75 BOOST_DEDUCED_TYPENAME base_::iterator
79 BOOST_DEDUCED_TYPENAME base_::const_iterator,
80 BOOST_DEDUCED_TYPENAME base_::const_iterator
83 typedef BOOST_DEDUCED_TYPENAME base_::value_type::info_type info_type;
85 unordered_map_view(BOOST_DEDUCED_TYPENAME base_::base_type & c)
88 using unique_map_view_access_::at;
89 using unique_map_view_access_::operator[];
91 unordered_map_view & operator=(const unordered_map_view & v)
93 this->base() = v.base();
97 // It can be used enable_if here but the error message when there
98 // is no info is very clear like this
100 template< class CompatibleKey >
101 const info_type & info_at(const CompatibleKey& k) const
103 BOOST_DEDUCED_TYPENAME base_::const_iterator iter = this->find(k);
104 if( iter == this->end() )
106 ::boost::throw_exception(
107 std::out_of_range("bimap<>: invalid key")
113 template< class CompatibleKey >
114 info_type & info_at(const CompatibleKey& k)
116 BOOST_DEDUCED_TYPENAME base_::iterator iter = this->find(k);
117 if( iter == this->end() )
119 ::boost::throw_exception(
120 std::out_of_range("bimap<>: invalid key")
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 /*===========================================================================*/
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 /*===========================================================================*/
148 template< class Tag, class BimapType >
149 struct left_map_view_extra_typedefs< ::boost::bimaps::views::unordered_map_view<Tag,BimapType> >
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)
155 template< class Tag, class BimapType >
156 struct right_map_view_extra_typedefs< ::boost::bimaps::views::unordered_map_view<Tag,BimapType> >
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)
162 } // namespace detail
164 /*===========================================================================*/
165 #undef BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF
166 #undef BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY
167 /*===========================================================================*/
169 } // namespace bimaps
172 #endif // BOOST_BIMAP_VIEWS_UNOREDERED_MAP_VIEW_HPP