set_of.hpp 4.8 KB

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