identity_converters.hpp 4.7 KB

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