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