]> git.lyx.org Git - lyx.git/blob - boost/boost/array_traits.hpp
Jrgen's "Tooltips for the reference dialog" patch. I've tried to incorporate
[lyx.git] / boost / boost / array_traits.hpp
1 // -*-C++-*- array_traits.hpp
2 // <!!----------------------------------------------------------------------> 
3 // <!! Copyright (C) 1998 Dietmar Kuehl, Claas Solutions GmbH > 
4 // <!!> 
5 // <!! Permission to use, copy, modify, distribute and sell this > 
6 // <!! software for any purpose is hereby granted without fee, provided > 
7 // <!! that the above copyright notice appears in all copies and that > 
8 // <!! both that copyright notice and this permission notice appear in > 
9 // <!! supporting documentation. Dietmar Kuehl and Claas Solutions make no > 
10 // <!! representations about the suitability of this software for any > 
11 // <!! purpose. It is provided "as is" without express or implied warranty. > 
12 // <!!----------------------------------------------------------------------> 
13
14 // Author: Dietmar Kuehl dietmar.kuehl@claas-solutions.de 
15 // Title:  STL container support, including support for built-in arrays
16 // Version: $Id: array_traits.hpp,v 1.2 2002/05/24 12:19:51 larsbj Exp $
17
18 // Dec 4, 2000  Added some more typedefs to array_traits including
19 //              an iterator type to supersede iter_type. -J.Siek
20
21 // -------------------------------------------------------------------------- 
22
23 #if !defined(BOOST_ARRAY_TRAITS_HPP)
24 #define BOOST_ARRAY_TRAITS_HPP 1
25
26 // -------------------------------------------------------------------------- 
27
28 #include <cstddef>
29 #include <boost/config.hpp>
30
31 // -------------------------------------------------------------------------- 
32
33 namespace boost
34 {
35
36   // --- a general version of container traits ------------------------------ 
37
38   template <typename Cont>
39     struct array_traits
40     {
41       typedef typename Cont::iterator  iterator;
42       typedef iterator iter_type; // just for backward compatibility
43       typedef typename Cont::size_type size_type;
44       typedef typename Cont::value_type value_type;
45       typedef typename Cont::reference reference;
46       typedef typename Cont::pointer pointer;
47       static iterator begin(Cont &cont) { return cont.begin(); }
48       static iterator end(Cont &cont) { return cont.end(); }
49       static size_type size(Cont &cont) { return cont.size(); }
50     };
51
52   // --- a version of container traits for constant constainer --------------
53
54   template <typename Cont>
55     struct array_traits<Cont const>
56     {
57       typedef typename Cont::const_iterator iterator;
58       typedef iterator iter_type; // just for backward compatibility
59       typedef typename Cont::size_type size_type;
60       typedef typename Cont::value_type value_type;
61       typedef typename Cont::const_reference reference;
62       typedef typename Cont::const_pointer pointer;
63       static iterator begin(Cont const &cont) { return cont.begin(); }
64       static iterator end(Cont const &cont) { return cont.end(); }
65       static size_type size(Cont const &cont) { return cont.size(); }
66     };
67
68   // --- a special version for non-const built-in arrays -------------------- 
69
70   template <typename T, std::size_t sz>
71     struct array_traits<T[sz]>
72     {
73       typedef T* iterator;
74       typedef iterator iter_type; // just for backward compatibility
75       typedef T value_type;
76       typedef value_type& reference;
77       typedef std::size_t size_type;
78       static iterator begin(T (&array)[sz]) { return array; }
79       static iterator end(T (&array)[sz]) { return array + sz; }
80       static size_type size(T (&)[sz]) { return sz; }
81     };
82
83   // --- a special version for const built-in arrays ------------------------ 
84
85   template <typename T, std::size_t sz>
86     struct array_traits<T const[sz]>
87     {
88       typedef T const* iterator;
89       typedef iterator iter_type; // just for backward compatibility
90       typedef std::size_t size_type;
91       typedef T const value_type;
92       typedef value_type& reference;
93       typedef value_type* pointer;
94       static iterator begin(T const (&array)[sz]) { return array; }
95       static iterator end(T const (&array)[sz]) { return array + sz; }
96       static size_type size(T const (&)[sz]) { return sz; }
97     };
98
99   template <typename T, int sz>
100   inline char (&sizer(T (&)[sz]))[sz];
101   
102   // --- general version of the global accessor functions --------------------- 
103
104   template <typename Cont>
105     inline typename array_traits<Cont>::iterator
106     begin(Cont &cont) { return array_traits<Cont>::begin(cont); }
107
108   template <typename Cont>
109     inline typename array_traits<Cont>::iterator
110     end(Cont &cont) { return array_traits<Cont>::end(cont); }
111
112   template <typename Cont>
113     inline typename array_traits<Cont>::size_type
114     size(Cont &cont) { return array_traits<Cont>::size(cont); }
115
116   // --- Actually the above should be sufficient but compilers seem -----------
117   // --- to welcome some help. So here we go:
118
119   template <typename T, std::size_t sz>
120     inline typename array_traits<T[sz]>::iterator
121     begin(T (&a)[sz]) { return array_traits<T[sz]>::begin(a); }
122   
123   template <typename T, std::size_t sz>
124     inline typename array_traits<T[sz]>::iterator
125     end(T (&a)[sz]) { return array_traits<T[sz]>::end(a); }
126   
127   template <typename T, std::size_t sz>
128     inline typename array_traits<T[sz]>::size_type
129     size(T (&a)[sz]) { return array_traits<T[sz]>::size(a); }
130   
131   // --- Apparently the compilers also need some specific help, ---------------
132
133   // --- EDG-2.39 wants to pass around pointers in some contexts --------------
134 #ifdef __EDG__
135   template <typename T>
136     struct array_traits<T*>
137     {
138       typedef T*     iterator;
139       typedef iterator iter_type; // just for backward compatibility
140       typedef std::size_t size_type;
141     };
142 #endif
143
144   // --- egcs-1998-11-22 apparently likes an extra const version: -------------
145 #ifdef __GNUG__
146   template <typename T, std::size_t sz>
147     inline typename array_traits<T const[sz]>::iterator
148     begin(T const(&a)[sz]) { return array_traits<T const[sz]>::begin(a); }
149   
150   template <typename T, std::size_t sz>
151     inline typename array_traits<T const[sz]>::iterator
152     end(T const(&a)[sz]) { return array_traits<T const[sz]>::end(a); }
153   
154   template <typename T, std::size_t sz>
155     inline typename array_traits<T const[sz]>::size_type
156     size(T const (&a)[sz]) { return array_traits<T const[sz]>::size(a); }
157 #endif
158   
159 }
160
161 // -----------------------------------------------------------------------------
162
163 #endif /* BOOST_ARRAY_TRAITS_HPP */