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 vector_of.hpp 10 /// \brief Include support for vector constrains for the bimap container 11 12 #ifndef BOOST_BIMAP_VECTOR_OF_HPP 13 #define BOOST_BIMAP_VECTOR_OF_HPP 14 15 #if defined(_MSC_VER) 16 #pragma once 17 #endif 18 19 #include <boost/config.hpp> 20 21 #include <boost/bimap/detail/user_interface_config.hpp> 22 23 #include <boost/mpl/bool.hpp> 24 25 #include <boost/concept_check.hpp> 26 27 #include <boost/bimap/detail/concept_tags.hpp> 28 29 #include <boost/bimap/tags/support/value_type_of.hpp> 30 31 #include <boost/bimap/detail/generate_index_binder.hpp> 32 #include <boost/bimap/detail/generate_view_binder.hpp> 33 #include <boost/bimap/detail/generate_relation_binder.hpp> 34 35 #include <boost/multi_index/random_access_index.hpp> 36 37 #include <boost/bimap/views/vector_map_view.hpp> 38 #include <boost/bimap/views/vector_set_view.hpp> 39 40 namespace boost { 41 namespace bimaps { 42 43 44 /// \brief Set Type Specification 45 /** 46 This struct is used to specify a set specification. 47 It is not a container, it is just a metaprogramming facility to 48 express the type of a set. Generally, this specification will 49 be used in other place to create a container. 50 It has the same syntax that an std::vector instantiation, except 51 that the allocator cannot be specified. The rationale behind 52 this difference is that the allocator is not part of the set 53 type specification, rather it is a container configuration 54 parameter. 55 The first parameter is the type of the objects in the set, and 56 the second one is a Functor that compares them. 57 Bimap binding metafunctions can be used with this class in 58 the following way: 59 60 \code 61 using namespace support; 62 63 BOOST_STATIC_ASSERT( is_set_type_of< vector_of<Type> >::value ) 64 65 BOOST_STATIC_ASSERT 66 ( 67 is_same 68 < 69 vector_of<Type>::index_bind 70 < 71 KeyExtractor, 72 Tag 73 74 >::type, 75 76 random_access< tag<Tag>, KeyExtractor > 77 78 >::value 79 ) 80 81 typedef bimap 82 < 83 vector_of<Type>, RightKeyType 84 85 > bimap_with_left_type_as_vector; 86 87 BOOST_STATIC_ASSERT 88 ( 89 is_same 90 < 91 vector_of<Type>::map_view_bind 92 < 93 member_at::left, 94 bimap_with_left_type_as_vector 95 96 >::type, 97 98 vector_map_view< member_at::left, bimap_with_left_type_as_vector > 99 100 >::value 101 ) 102 103 \endcode 104 105 See also vector_of_relation. 106 **/ 107 108 template< class Type > 109 struct vector_of : public ::boost::bimaps::detail::set_type_of_tag 110 { 111 /// User type, can be tagged 112 typedef Type user_type; 113 114 /// Type of the object that will be stored in the vector 115 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::tags::support:: 116 value_type_of<user_type>::type value_type; 117 118 119 struct lazy_concept_checked 120 { 121 BOOST_CLASS_REQUIRE ( value_type, 122 boost, AssignableConcept ); 123 124 typedef vector_of type; 125 }; 126 127 BOOST_BIMAP_GENERATE_INDEX_BINDER_0CP_NO_EXTRACTOR( 128 129 // binds to 130 multi_index::random_access 131 ) 132 133 BOOST_BIMAP_GENERATE_MAP_VIEW_BINDER( 134 135 // binds to 136 views::vector_map_view 137 ) 138 139 BOOST_BIMAP_GENERATE_SET_VIEW_BINDER( 140 141 // binds to 142 views::vector_set_view 143 ) 144 145 typedef mpl::bool_<true> mutable_key; 146 }; 147 148 149 /// \brief Set Of Relation Specification 150 /** 151 This struct is similar to vector_of but it is bind logically to a 152 relation. It is used in the bimap instantiation to specify the 153 desired type of the main view. This struct implements internally 154 a metafunction named bind_to that manages the quite complicated 155 task of finding the right type of the set for the relation. 156 157 \code 158 template<class Relation> 159 struct bind_to 160 { 161 typedef -unspecified- type; 162 }; 163 \endcode 164 165 See also vector_of, is_set_type_of_relation. 166 **/ 167 168 struct vector_of_relation : public ::boost::bimaps::detail::set_type_of_relation_tag 169 { 170 BOOST_BIMAP_GENERATE_RELATION_BINDER_0CP( 171 172 // binds to 173 vector_of 174 ) 175 176 typedef mpl::bool_<true> left_mutable_key; 177 typedef mpl::bool_<true> right_mutable_key; 178 }; 179 180 181 } // namespace bimaps 182 } // namespace boost 183 184 185 #endif // BOOST_BIMAP_VECTOR_OF_HPP 186 187