identity_converters.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 container_adaptor/detail/identity_converters.hpp
  9. /// \brief Value and iterators identity converters.
  10. #ifndef BOOST_BIMAP_CONTAINER_ADAPTOR_DETAIL_IDENTITY_CONVERTERS_HPP
  11. #define BOOST_BIMAP_CONTAINER_ADAPTOR_DETAIL_IDENTITY_CONVERTERS_HPP
  12. #if defined(_MSC_VER)
  13. #pragma once
  14. #endif
  15. #include <boost/config.hpp>
  16. namespace boost {
  17. namespace bimaps {
  18. namespace container_adaptor {
  19. /// \brief Details of the container adaptor toolbox
  20. namespace detail {
  21. /// \brief Iterator identity converter used by default in container adaptors.
  22. /**
  23. If Iterator and ConstIterator are of the same type one of the convert function is not
  24. included.
  25. **/
  26. template
  27. <
  28. class BaseIterator , class Iterator,
  29. class BaseConstIterator , class ConstIterator
  30. >
  31. struct iterator_to_base_identity
  32. {
  33. BaseIterator operator()(Iterator iter) const
  34. {
  35. return BaseIterator(iter);
  36. }
  37. BaseConstIterator operator()(ConstIterator iter) const
  38. {
  39. return BaseConstIterator(iter);
  40. }
  41. };
  42. #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
  43. template< class BaseIterator, class Iterator >
  44. struct iterator_to_base_identity<BaseIterator,Iterator,BaseIterator,Iterator>
  45. {
  46. BaseIterator operator()(Iterator iter) const
  47. {
  48. return BaseIterator(iter);
  49. }
  50. };
  51. #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
  52. /// \brief Iterator from base identity converter used by default in container adaptors.
  53. /**
  54. If Iterator and ConstIterator are of the same type one of the convert function is not
  55. included.
  56. **/
  57. template
  58. <
  59. class BaseIterator , class Iterator,
  60. class BaseConstIterator , class ConstIterator
  61. >
  62. struct iterator_from_base_identity
  63. {
  64. Iterator operator()(BaseIterator iter) const
  65. {
  66. return Iterator(iter);
  67. }
  68. ConstIterator operator()(BaseConstIterator iter) const
  69. {
  70. return ConstIterator(iter);
  71. }
  72. };
  73. #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
  74. template< class BaseIterator, class Iterator, class ConstIterator >
  75. struct iterator_from_base_identity<BaseIterator,Iterator,BaseIterator,ConstIterator>
  76. {
  77. Iterator operator()(BaseIterator iter) const
  78. {
  79. return Iterator(iter);
  80. }
  81. };
  82. #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
  83. /// \brief Value to base identity converter used by default in container adaptors.
  84. template< class BaseValue, class Value >
  85. struct value_to_base_identity
  86. {
  87. BaseValue operator()(const Value & val) const
  88. {
  89. return BaseValue(val);
  90. }
  91. };
  92. #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
  93. template< class Value >
  94. struct value_to_base_identity< Value, Value >
  95. {
  96. const Value & operator()(const Value & val) const
  97. {
  98. return val;
  99. }
  100. };
  101. #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
  102. /// \brief Value from base identity converter used by default in container adaptors.
  103. template< class BaseValue, class Value >
  104. struct value_from_base_identity
  105. {
  106. Value operator()(const BaseValue & val) const
  107. {
  108. return Value(val);
  109. }
  110. };
  111. #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
  112. template< class Value >
  113. struct value_from_base_identity<Value,Value>
  114. {
  115. Value & operator()(Value & val) const
  116. {
  117. return val;
  118. }
  119. const Value & operator()(const Value & val) const
  120. {
  121. return val;
  122. }
  123. };
  124. #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
  125. /// \brief Key to base identity converter used by default in container adaptors.
  126. template< class BaseKey, class Key >
  127. struct key_to_base_identity
  128. {
  129. BaseKey operator()(const Key & k) const
  130. {
  131. return BaseKey(k);
  132. }
  133. };
  134. #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
  135. template< class Key >
  136. struct key_to_base_identity< Key, Key >
  137. {
  138. // As default accept any type as key in order to allow container
  139. // adaptors to work with compatible key types
  140. template< class CompatibleKey >
  141. const CompatibleKey & operator()(const CompatibleKey & k) const
  142. {
  143. return k;
  144. }
  145. };
  146. #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
  147. } // namespace detail
  148. } // namespace container_adaptor
  149. } // namespace bimaps
  150. } // namespace boost
  151. #endif // BOOST_BIMAP_CONTAINER_ADAPTOR_DETAIL_IDENTITY_CONVERTERS_HPP