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

PrevUpHomeNext

unordered_set_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_set_of.hpp
00010 /// \brief Include support for unordered_set constrains for the bimap container
00011 
00012 #ifndef BOOST_BIMAP_UNORDERED_SET_OF_HPP
00013 #define BOOST_BIMAP_UNORDERED_SET_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_map_view.hpp>
00036 #include <boost/bimap/views/unordered_set_view.hpp>
00037 
00038 namespace boost {
00039 namespace bimaps {
00040 
00041 /// \brief Set Type Specification
00042 /**
00043 This struct is used to specify an unordered_set specification.
00044 It is not a container, it is just a metaprogramming facility to
00045 express the type of a set. Generally, this specification will
00046 be used in other place to create a container.
00047 It has the same syntax that an tr1::unordered_set instantiation,
00048 except that the allocator cannot be specified. The rationale behind
00049 this difference is that the allocator is not part of the
00050 unordered_set type specification, rather it is a container
00051 configuration parameter.
00052 The first parameter is the type of the objects in the set, the
00053 second one is a Hash Functor that takes objects of this type, and
00054 the third one is a Functor that compares them for equality.
00055 Bimap binding metafunctions can be used with this class in
00056 the following way:
00057 
00058 \code
00059 using namespace support;
00060 
00061 BOOST_STATIC_ASSERT( is_set_type_of< unordered_set_of<Type> >::value );
00062 
00063 BOOST_STATIC_ASSERT
00064 (
00065      is_same
00066      <
00067         unordered_set_of<Type,HashFunctor,EqualKey>::index_bind
00068         <
00069             KeyExtractor,
00070             Tag
00071 
00072         >::type,
00073 
00074         hashed_unique< tag<Tag>, KeyExtractor, HashFunctor, EqualKey >
00075 
00076     >::value
00077 );
00078 
00079 typedef bimap
00080 <
00081     unordered_set_of<Type>, RightKeyType
00082 
00083 > bimap_with_left_type_as_unordered_set;
00084 
00085 BOOST_STATIC_ASSERT
00086 (
00087     is_same
00088     <
00089         unordered_set_of<Type>::map_view_bind
00090         <
00091             member_at::left,
00092             bimap_with_left_type_as_unordered_set
00093 
00094         >::type,
00095 
00096         unordered_map_view
00097         <
00098             member_at::left,
00099             bimap_with_left_type_as_unordered_set
00100         >
00101 
00102     >::value
00103 );
00104 
00105 \endcode
00106 
00107 See also unordered_set_of_relation.
00108                                                                         **/
00109 
00110 template
00111 <
00112     class KeyType,
00113     class HashFunctor   = hash< KeyType >,
00114     class EqualKey      = std::equal_to< KeyType >
00115 >
00116 struct unordered_set_of : public ::boost::bimaps::detail::set_type_of_tag
00117 {
00118     /// The type that will be stored in the container
00119     typedef KeyType         value_type;
00120 
00121     /// Hash Functor that takes value_type objects
00122     typedef HashFunctor     hasher;
00123 
00124     /// Functor that compare two value_type objects for equality
00125     typedef EqualKey        key_equal;
00126 
00127 
00128     BOOST_BIMAP_GENERATE_INDEX_BINDER_2CP(
00129 
00130         // binds to
00131         multi_index::hashed_unique,
00132 
00133         // with
00134         hasher,
00135         key_equal
00136     );
00137 
00138     BOOST_BIMAP_GENERATE_MAP_VIEW_BINDER(
00139 
00140         // binds to
00141         views::unordered_map_view
00142     );
00143 
00144     BOOST_BIMAP_GENERATE_SET_VIEW_BINDER(
00145 
00146         // binds to
00147         views::unordered_set_view
00148     );
00149 
00150     typedef mpl::bool_<false> mutable_key;
00151 };
00152 
00153 
00154 /// \brief Set Of Relation Specification
00155 /**
00156 This struct is similar to unordered_set_of but it is bind logically to
00157 a relation. It is used in the bimap instantiation to specify the
00158 desired type of the main view. This struct implements internally
00159 a metafunction named bind_to that manages the quite complicated
00160 task of finding the right type of the set for the relation.
00161 
00162 \code
00163 template<class Relation>
00164 struct bind_to
00165 {
00166     typedef -unspecified- type;
00167 };
00168 \endcode
00169 
00170 See also unordered_set_of, is_set_type_of_relation.
00171                                                                 **/
00172 
00173 template
00174 <
00175     class HashFunctor   = hash< _relation >,
00176     class EqualKey      = std::equal_to< _relation >
00177 >
00178 struct unordered_set_of_relation : public ::boost::bimaps::detail::set_type_of_relation_tag
00179 {
00180     /// Hash Functor that takes value_type objects
00181     typedef HashFunctor     hasher;
00182 
00183     /// Functor that compare two value_type objects for equality
00184     typedef EqualKey        key_equal;
00185 
00186 
00187     BOOST_BIMAP_GENERATE_RELATION_BINDER_2CP(
00188 
00189         // binds to
00190         unordered_set_of,
00191 
00192         // with
00193         hasher,
00194         key_equal
00195     );
00196 
00197     typedef mpl::bool_<false>  left_mutable_key;
00198     typedef mpl::bool_<false> right_mutable_key;
00199 };
00200 
00201 
00202 } // namespace bimaps
00203 } // namespace boost
00204 
00205 
00206 #endif // BOOST_BIMAP_UNORDERED_SET_OF_HPP
00207 
Copyright 2006 Matias Capeletto

PrevUpHomeNext