Boost C++ Libraries Boost.Bimap Home Libraries People FAQ More

PrevUpHomeNext

unordered_multiset_of.hpp

Go to the documentation of this file.
00001 // Boost.Bimap
00002 //
00003 // Copyright (c) 2006-2007 Matias Capeletto
00004 //
00005 // Distributed under the Boost Software License, Version 1.0.
00006 // (See accompanying file LICENSE_1_0.txt or copy at
00007 // http://www.boost.org/LICENSE_1_0.txt)
00008 
00009 /// \file unordered_multiset_of.hpp
00010 /// \brief Include support for unordered_multiset constrains for the bimap container
00011 
00012 #ifndef BOOST_BIMAP_UNORDERED_MULTISET_OF_HPP
00013 #define BOOST_BIMAP_UNORDERED_MULTISET_OF_HPP
00014 
00015 #if defined(_MSC_VER) && (_MSC_VER>=1200)
00016 #pragma once
00017 #endif
00018 
00019 #include <boost/config.hpp>
00020 
00021 #include <boost/bimap/detail/user_interface_config.hpp>
00022 
00023 #include <functional>
00024 #include <boost/functional/hash.hpp>
00025 #include <boost/mpl/bool.hpp>
00026 
00027 #include <boost/bimap/detail/concept_tags.hpp>
00028 
00029 #include <boost/bimap/detail/generate_index_binder.hpp>
00030 #include <boost/bimap/detail/generate_view_binder.hpp>
00031 #include <boost/bimap/detail/generate_relation_binder.hpp>
00032 
00033 #include <boost/multi_index/hashed_index.hpp>
00034 
00035 #include <boost/bimap/views/unordered_multimap_view.hpp>
00036 #include <boost/bimap/views/unordered_multiset_view.hpp>
00037 
00038 namespace boost {
00039 namespace bimaps {
00040 
00041 
00042 /// \brief Set Type Specification
00043 /**
00044 This struct is used to specify an unordered_multiset specification.
00045 It is not a container, it is just a metaprogramming facility to
00046 express the type of a set. Generally, this specification will
00047 be used in other place to create a container.
00048 It has the same syntax that an tr1::unordered_multiset instantiation,
00049 except that the allocator cannot be specified. The rationale behind
00050 this difference is that the allocator is not part of the
00051 unordered_multiset type specification, rather it is a container
00052 configuration parameter.
00053 The first parameter is the type of the objects in the set, the
00054 second one is a Hash Functor that takes objects of this type, and
00055 the third one is a Functor that compares them for equality.
00056 Bimap binding metafunctions can be used with this class in
00057 the following way:
00058 
00059 \code
00060 using namespace support;
00061 
00062 BOOST_STATIC_ASSERT( is_set_type_of< unordered_multiset_of<Type> >::value );
00063 
00064 BOOST_STATIC_ASSERT
00065 (
00066      is_same
00067      <
00068         compute_index_type
00069         <
00070             unordered_multiset_of<Type,HashFunctor,EqualKey>,
00071             KeyExtractor,
00072             Tag
00073 
00074         >::type
00075         ,
00076         hashed_nonunique< tag<Tag>, KeyExtractor, HashFunctor, EqualKey >
00077 
00078     >::value
00079 );
00080 
00081 typedef bimap
00082 <
00083     unordered_multiset_of<Type>, RightKeyType
00084 
00085 > bimap_with_left_type_as_unordered_multiset;
00086 
00087 BOOST_STATIC_ASSERT
00088 (
00089     is_same
00090     <
00091         compute_map_view_type
00092         <
00093             member_at::left,
00094             bimap_with_left_type_as_unordered_multiset
00095 
00096         >::type,
00097 
00098         unordered_multimap_view
00099         <
00100             member_at::left,
00101             bimap_with_left_type_as_unordered_multiset
00102         >
00103 
00104     >::value
00105 );
00106 
00107 \endcode
00108 
00109 See also unordered_multiset_of_relation.
00110                                                                         **/
00111 
00112 template
00113 <
00114     class KeyType,
00115     class HashFunctor   = hash< KeyType >,
00116     class EqualKey      = std::equal_to< KeyType >
00117 >
00118 struct unordered_multiset_of : public ::boost::bimaps::detail::set_type_of_tag
00119 {
00120     /// The type that will be stored in the container
00121     typedef KeyType         value_type;
00122 
00123     /// Hash Functor that takes value_type objects
00124     typedef HashFunctor     hasher;
00125 
00126     /// Functor that compare two value_type objects for equality
00127     typedef EqualKey        key_equal;
00128 
00129 
00130     BOOST_BIMAP_GENERATE_INDEX_BINDER_2CP(
00131 
00132         // binds to
00133         multi_index::hashed_non_unique,
00134 
00135         // with
00136         hasher,
00137         key_equal
00138     );
00139 
00140     BOOST_BIMAP_GENERATE_MAP_VIEW_BINDER(
00141 
00142         // binds to
00143         views::unordered_multimap_view
00144     );
00145 
00146     BOOST_BIMAP_GENERATE_SET_VIEW_BINDER(
00147 
00148         // binds to
00149         views::unordered_multiset_view
00150     );
00151 
00152     typedef mpl::bool_<false> mutable_key;
00153 };
00154 
00155 
00156 /// \brief Set Of Relation Specification
00157 /**
00158 This struct is similar to unordered_multiset_of but it is bind logically
00159 to a relation. It is used in the bimap instantiation to specify the
00160 desired type of the main view. This struct implements internally
00161 a metafunction named bind_to that manages the quite complicated
00162 task of finding the right type of the set for the relation.
00163 
00164 \code
00165 template<class Relation>
00166 struct bind_to
00167 {
00168     typedef -unspecified- type;
00169 };
00170 \endcode
00171 
00172 See also unordered_multiset_of, is_set_type_of_relation.
00173                                                                 **/
00174 
00175 template
00176 <
00177     class HashFunctor   = hash< _relation >,
00178     class EqualKey      = std::equal_to< _relation >
00179 >
00180 struct unordered_multiset_of_relation : public ::boost::bimaps::detail::set_type_of_relation_tag
00181 {
00182     /// Hash Functor that takes value_type objects
00183     typedef HashFunctor     hasher;
00184 
00185     /// Functor that compare two value_type objects for equality
00186     typedef EqualKey        key_equal;
00187 
00188 
00189     BOOST_BIMAP_GENERATE_RELATION_BINDER_2CP(
00190 
00191         // binds to
00192         unordered_multiset_of,
00193 
00194         // with
00195         hasher,
00196         key_equal
00197     );
00198 
00199     typedef mpl::bool_<false>  left_mutable_key;
00200     typedef mpl::bool_<false> right_mutable_key;
00201 };
00202 
00203 
00204 } // namespace bimaps
00205 } // namespace boost
00206 
00207 
00208 #endif // BOOST_BIMAP_UNORDERED_MULTISET_OF_HPP
00209 
Copyright 2006 Matias Capeletto

PrevUpHomeNext