4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief IteratorTraits public header */
26 #ifndef HH_IteratorTraits_
27 #define HH_IteratorTraits_ 1
30 #include <boost/type_traits/integral_constant.hpp>
34 //#include "IteratorTraits.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
39 // The following is *not* standard mandated but it *is* mandated by TR1 and I know of no
40 // implementation for which this is not correct
42 /** \brief Check for contiguous mutable storage
44 This type trait returns \c true, if \a RandomAccessIterator is an iterator into a contiguous
45 storage area which may be written to. If this is the case, some algorithms may be optimized
46 by directly modifying the underlying storage instead of relying on the STL interface.
50 template <class Iterator>
51 void do(Iterator i, boost::false_type)
53 // Access the iterator 'i' via the standard STL interface
56 template<class Iterator>
57 void do(Iterator i, boost::true_type)
59 typename Iterator::pointer p (senf::storage_iterator(i));
60 // Manipulate the container by manipulating the data pointed at via 'p'
63 template <class Iterator>
67 do( i, senf::contiguous_storage_iterator<Iterator>() );
72 Thie \ref senf::storage_iterator helper function will convert an iterator to a pointer to
73 the same element the iterator is referencing.
75 This trait will return \c true for pointers. Additonally it should be configured to return
76 true for all standard containers which obey above implementation restrictions. This
77 typically includes \c std::vector and \c std::basic_string.
79 To do so, the template must be specialized for those containers \c iterator type. If
80 compiling with g++, this is implemented in \ref IteratorTraits.ih. This file should be
81 extended for further compilers or STL implementations if needed.
83 template <class RandomAccessIterator>
84 struct contiguous_storage_iterator
85 : public boost::false_type
88 /** \brief Check for contiguous mutable storage. Pointer specialization
90 See \ref contiguous_storage_iterator.
93 struct contiguous_storage_iterator<T *>
94 : public boost::true_type
97 /** \brief Convert contiguous storage iterator to pointer
99 storage_iterator will convert a contiguous storage iterator into a pointer to the same
100 element in the container. This allows to directly access the containers storage.
102 \warning This conversion is only safe if \ref contiguous_storage_iterator<Iterator>::value
103 is \c true for the given iterator type !
105 template <class Iterator>
106 typename std::iterator_traits<Iterator>::pointer storage_iterator(Iterator i);
110 ///////////////////////////////hh.e////////////////////////////////////////
111 //#include "IteratorTraits.cci"
112 //#include "IteratorTraits.ct"
113 #include "IteratorTraits.cti"
114 #include "IteratorTraits.ih"
121 // c-file-style: "senf"
122 // indent-tabs-mode: nil
123 // ispell-local-dictionary: "american"
124 // compile-command: "scons -u test"
125 // comment-column: 40