ebf2855bbfa4c27336c599fb574f07015646bff9
[senf.git] / Utils / IteratorTraits.hh
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 //     Stefan Bund <g0dil@berlios.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 /** \file
22     \brief IteratorTraits public header */
23
24 #ifndef HH_IteratorTraits_
25 #define HH_IteratorTraits_ 1
26
27 // Custom includes
28 #include <boost/type_traits/integral_constant.hpp>
29 #include <vector>
30 #include <string>
31
32 //#include "IteratorTraits.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
34
35 namespace senf {
36
37 // The following is *not* standard mandated but it *is* mandated by TR1 and I know of no
38 // implementation for which this is not correct
39
40     /** \brief Check for contiguous mutable storage
41
42         This type trait returns \c true, if \a RandomAccessIterator is an iterator into a contiguous
43         storage area which may be written to. If this is the case, some algorithms may be optimized
44         by directly modifying the underlying storage instead of relying on the STL interface.
45         
46         This trait will return \c true for pointers. Additonally it should be configured to return
47         true for all standard containers which obey above implementation restrictions. This
48         typically includes \c std::vector and \c std::basic_string.
49
50         To do so, the template must be specialized for those containers \c iterator type. If
51         compiling with g++, this is implemented in \ref IteratorTraits.ih. This file should be
52         extended for further compilers if necessary.
53      */
54     template <class RandomAccessIterator>
55     struct contiguous_storage_iterator
56         : public boost::false_type
57     {};
58
59     template <class T>
60     struct contiguous_storage_iterator<T *>
61         : public boost::true_type
62     {};
63
64     /** \brief Convert contiguous storage iterator to pointer
65         
66         storage_iterator will convert a contiguous storage iterator into a pointer to the same
67         element in the container. This allows to directly access the containers storage.
68      */
69     template <class Iterator>
70     typename std::iterator_traits<Iterator>::pointer storage_iterator(Iterator i);
71     
72 }
73
74 ///////////////////////////////hh.e////////////////////////////////////////
75 //#include "IteratorTraits.cci"
76 //#include "IteratorTraits.ct"
77 #include "IteratorTraits.cti"
78 #include "IteratorTraits.ih"
79 #endif
80
81 \f
82 // Local Variables:
83 // mode: c++
84 // fill-column: 100
85 // c-file-style: "senf"
86 // indent-tabs-mode: nil
87 // ispell-local-dictionary: "american"
88 // End: