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

PrevUpHomeNext

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

PrevUpHomeNext