Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:40

0001 // Boost.Bimap
0002 //
0003 // Copyright (c) 2006-2007 Matias Capeletto
0004 //
0005 // Distributed under the Boost Software License, Version 1.0.
0006 // (See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 /// \file unordered_set_of.hpp
0010 /// \brief Include support for unordered_set constrains for the bimap container
0011 
0012 #ifndef BOOST_BIMAP_UNORDERED_SET_OF_HPP
0013 #define BOOST_BIMAP_UNORDERED_SET_OF_HPP
0014 
0015 #if defined(_MSC_VER)
0016 #pragma once
0017 #endif
0018 
0019 #include <boost/config.hpp>
0020 
0021 #include <boost/bimap/detail/user_interface_config.hpp>
0022 
0023 #include <functional>
0024 #include <boost/functional/hash.hpp>
0025 #include <boost/mpl/bool.hpp>
0026 
0027 #include <boost/concept_check.hpp>
0028 
0029 #include <boost/bimap/detail/concept_tags.hpp>
0030 
0031 #include <boost/bimap/tags/support/value_type_of.hpp>
0032 
0033 #include <boost/bimap/detail/generate_index_binder.hpp>
0034 #include <boost/bimap/detail/generate_view_binder.hpp>
0035 #include <boost/bimap/detail/generate_relation_binder.hpp>
0036 
0037 #include <boost/multi_index/hashed_index.hpp>
0038 
0039 #include <boost/bimap/views/unordered_map_view.hpp>
0040 #include <boost/bimap/views/unordered_set_view.hpp>
0041 
0042 namespace boost {
0043 namespace bimaps {
0044 
0045 /// \brief Set Type Specification
0046 /**
0047 This struct is used to specify an unordered_set specification.
0048 It is not a container, it is just a metaprogramming facility to
0049 express the type of a set. Generally, this specification will
0050 be used in other place to create a container.
0051 It has the same syntax that an tr1::unordered_set instantiation,
0052 except that the allocator cannot be specified. The rationale behind
0053 this difference is that the allocator is not part of the
0054 unordered_set type specification, rather it is a container
0055 configuration parameter.
0056 The first parameter is the type of the objects in the set, the
0057 second one is a Hash Functor that takes objects of this type, and
0058 the third one is a Functor that compares them for equality.
0059 Bimap binding metafunctions can be used with this class in
0060 the following way:
0061 
0062 \code
0063 using namespace support;
0064 
0065 BOOST_STATIC_ASSERT( is_set_type_of< unordered_set_of<Type> >::value )
0066 
0067 BOOST_STATIC_ASSERT
0068 (
0069      is_same
0070      <
0071         unordered_set_of<Type,HashFunctor,EqualKey>::index_bind
0072         <
0073             KeyExtractor,
0074             Tag
0075 
0076         >::type,
0077 
0078         hashed_unique< tag<Tag>, KeyExtractor, HashFunctor, EqualKey >
0079 
0080     >::value
0081 )
0082 
0083 typedef bimap
0084 <
0085     unordered_set_of<Type>, RightKeyType
0086 
0087 > bimap_with_left_type_as_unordered_set;
0088 
0089 BOOST_STATIC_ASSERT
0090 (
0091     is_same
0092     <
0093         unordered_set_of<Type>::map_view_bind
0094         <
0095             member_at::left,
0096             bimap_with_left_type_as_unordered_set
0097 
0098         >::type,
0099 
0100         unordered_map_view
0101         <
0102             member_at::left,
0103             bimap_with_left_type_as_unordered_set
0104         >
0105 
0106     >::value
0107 )
0108 
0109 \endcode
0110 
0111 See also unordered_set_of_relation.
0112                                                                         **/
0113 
0114 template
0115 <
0116     class KeyType,
0117     class HashFunctor   = hash< BOOST_DEDUCED_TYPENAME 
0118         ::boost::bimaps::tags::support::value_type_of<KeyType>::type >,
0119     class EqualKey      = std::equal_to< BOOST_DEDUCED_TYPENAME 
0120         ::boost::bimaps::tags::support::value_type_of<KeyType>::type >
0121 >
0122 struct unordered_set_of : public ::boost::bimaps::detail::set_type_of_tag
0123 {
0124     /// User type, can be tagged
0125     typedef KeyType user_type;
0126 
0127     /// Type of the object that will be stored in the container
0128     typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::tags::support::
0129         value_type_of<user_type>::type value_type;
0130 
0131     /// Hash Functor that takes value_type objects
0132     typedef HashFunctor     hasher;
0133 
0134     /// Functor that compare two value_type objects for equality
0135     typedef EqualKey        key_equal;
0136 
0137     struct lazy_concept_checked
0138     {
0139         BOOST_CLASS_REQUIRE ( value_type,
0140                               boost, AssignableConcept );
0141 
0142         BOOST_CLASS_REQUIRE3( hasher, std::size_t, value_type,
0143                               boost, UnaryFunctionConcept );
0144 
0145         BOOST_CLASS_REQUIRE4( key_equal, bool, value_type, value_type,
0146                               boost, BinaryFunctionConcept );
0147 
0148         typedef unordered_set_of type; 
0149     };
0150 
0151     BOOST_BIMAP_GENERATE_INDEX_BINDER_2CP(
0152 
0153         // binds to
0154         multi_index::hashed_unique,
0155 
0156         // with
0157         hasher,
0158         key_equal
0159     )
0160 
0161     BOOST_BIMAP_GENERATE_MAP_VIEW_BINDER(
0162 
0163         // binds to
0164         views::unordered_map_view
0165     )
0166 
0167     BOOST_BIMAP_GENERATE_SET_VIEW_BINDER(
0168 
0169         // binds to
0170         views::unordered_set_view
0171     )
0172 
0173     typedef mpl::bool_<false> mutable_key;
0174 };
0175 
0176 
0177 /// \brief Set Of Relation Specification
0178 /**
0179 This struct is similar to unordered_set_of but it is bind logically to
0180 a relation. It is used in the bimap instantiation to specify the
0181 desired type of the main view. This struct implements internally
0182 a metafunction named bind_to that manages the quite complicated
0183 task of finding the right type of the set for the relation.
0184 
0185 \code
0186 template<class Relation>
0187 struct bind_to
0188 {
0189     typedef -unspecified- type;
0190 };
0191 \endcode
0192 
0193 See also unordered_set_of, is_set_type_of_relation.
0194                                                                 **/
0195 
0196 template
0197 <
0198     class HashFunctor   = hash< _relation >,
0199     class EqualKey      = std::equal_to< _relation >
0200 >
0201 struct unordered_set_of_relation : public ::boost::bimaps::detail::set_type_of_relation_tag
0202 {
0203     /// Hash Functor that takes value_type objects
0204     typedef HashFunctor     hasher;
0205 
0206     /// Functor that compare two value_type objects for equality
0207     typedef EqualKey        key_equal;
0208 
0209 
0210     BOOST_BIMAP_GENERATE_RELATION_BINDER_2CP(
0211 
0212         // binds to
0213         unordered_set_of,
0214 
0215         // with
0216         hasher,
0217         key_equal
0218     )
0219 
0220     typedef mpl::bool_<false>  left_mutable_key;
0221     typedef mpl::bool_<false> right_mutable_key;
0222 };
0223 
0224 
0225 } // namespace bimaps
0226 } // namespace boost
0227 
0228 
0229 #endif // BOOST_BIMAP_UNORDERED_SET_OF_HPP
0230