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

PrevUpHomeNext

identity_converters.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 container_adaptor/detail/identity_converters.hpp
00010 /// \brief Value and iterators identity converters.
00011 
00012 #ifndef BOOST_BIMAP_CONTAINER_ADAPTOR_DETAIL_IDENTITY_CONVERTERS_HPP
00013 #define BOOST_BIMAP_CONTAINER_ADAPTOR_DETAIL_IDENTITY_CONVERTERS_HPP
00014 
00015 #if defined(_MSC_VER) && (_MSC_VER>=1200)
00016 #pragma once
00017 #endif
00018 
00019 #include <boost/config.hpp>
00020 
00021 namespace boost {
00022 namespace bimaps {
00023 namespace container_adaptor {
00024 
00025 /// \brief Details of the container adaptor toolbox
00026 
00027 namespace detail {
00028 
00029 /// \brief Iterator identity converter used by default in container adaptors.
00030 /**
00031 If Iterator and ConstIterator are of the same type one of the convert function is not
00032 included.
00033                                                                                     **/
00034 
00035 template
00036 <
00037     class BaseIterator              , class Iterator,
00038     class BaseConstIterator         , class ConstIterator
00039 >
00040 struct iterator_to_base_identity
00041 {
00042     BaseIterator operator()(Iterator iter) const
00043     {
00044         return BaseIterator(iter);
00045     }
00046 
00047     BaseConstIterator operator()(ConstIterator iter) const
00048     {
00049         return BaseConstIterator(iter);
00050     }
00051 };
00052 
00053 #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
00054 
00055 template< class BaseIterator, class Iterator >
00056 struct iterator_to_base_identity<BaseIterator,Iterator,BaseIterator,Iterator>
00057 {
00058     BaseIterator operator()(Iterator iter) const
00059     {
00060         return BaseIterator(iter);
00061     }
00062 };
00063 
00064 #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
00065 
00066 /// \brief Iterator from base identity converter used by default in container adaptors.
00067 /**
00068 If Iterator and ConstIterator are of the same type one of the convert function is not
00069 included.
00070                                                                                     **/
00071 
00072 template
00073 <
00074     class BaseIterator              , class Iterator,
00075     class BaseConstIterator         , class ConstIterator
00076 >
00077 struct iterator_from_base_identity
00078 {
00079     Iterator operator()(BaseIterator iter) const
00080     {
00081         return Iterator(iter);
00082     }
00083     ConstIterator operator()(BaseConstIterator iter) const
00084     {
00085         return ConstIterator(iter);
00086     }
00087 };
00088 
00089 #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
00090 
00091 template< class BaseIterator, class Iterator, class ConstIterator >
00092 struct iterator_from_base_identity<BaseIterator,Iterator,BaseIterator,ConstIterator>
00093 {
00094     Iterator operator()(BaseIterator iter) const
00095     {
00096         return Iterator(iter);
00097     }
00098 };
00099 
00100 #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
00101 
00102 /// \brief Value to base identity converter used by default in container adaptors.
00103 
00104 template< class BaseValue, class Value >
00105 struct value_to_base_identity
00106 {
00107     BaseValue operator()(const Value & val) const
00108     {
00109         return BaseValue(val);
00110     }
00111 };
00112 
00113 #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
00114 
00115 template< class Value >
00116 struct value_to_base_identity< Value, Value >
00117 {
00118     const Value & operator()(const Value & val) const
00119     {
00120         return val;
00121     }
00122 };
00123 
00124 #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
00125 
00126 /// \brief Value from base identity converter used by default in container adaptors.
00127 
00128 template< class BaseValue, class Value >
00129 struct value_from_base_identity
00130 {
00131     Value operator()(const BaseValue & val) const
00132     {
00133         return Value(val);
00134     }
00135 };
00136 
00137 #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
00138 
00139 template< class Value >
00140 struct value_from_base_identity<Value,Value>
00141 {
00142     Value & operator()(Value & val) const
00143     {
00144         return val;
00145     }
00146 
00147     const Value & operator()(const Value & val) const
00148     {
00149         return val;
00150     }
00151 };
00152 
00153 #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
00154 
00155 /// \brief Key to base identity converter used by default in container adaptors.
00156 
00157 template< class BaseKey, class Key >
00158 struct key_to_base_identity
00159 {
00160     BaseKey operator()(const Key & k) const
00161     {
00162         return BaseKey(k);
00163     }
00164 };
00165 
00166 #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
00167 
00168 template< class Key >
00169 struct key_to_base_identity< Key, Key >
00170 {
00171     // As default accept any type as key in order to allow container
00172     // adaptors to work with compatible key types
00173 
00174     template< class CompatibleKey >
00175     const CompatibleKey & operator()(const CompatibleKey & k) const
00176     {
00177         return k;
00178     }
00179 };
00180 
00181 #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
00182 
00183 } // namespace detail
00184 } // namespace container_adaptor
00185 } // namespace bimaps
00186 } // namespace boost
00187 
00188 
00189 #endif // BOOST_BIMAP_CONTAINER_ADAPTOR_DETAIL_IDENTITY_CONVERTERS_HPP
00190 
00191 
Copyright 2006 Matias Capeletto

PrevUpHomeNext