1 | // Boost.Range library |
---|
2 | // |
---|
3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and |
---|
4 | // distribution is subject to the Boost Software License, Version |
---|
5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
---|
6 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
7 | // |
---|
8 | // For more information, see http://www.boost.org/libs/range/ |
---|
9 | // |
---|
10 | |
---|
11 | |
---|
12 | #ifndef BOOST_RANGE_DETAIL_VC6_SIZE_HPP |
---|
13 | #define BOOST_RANGE_DETAIL_VC6_SIZE_HPP |
---|
14 | |
---|
15 | #include <boost/range/detail/implementation_help.hpp> |
---|
16 | #include <boost/range/detail/size_type.hpp> |
---|
17 | #include <boost/range/detail/common.hpp> |
---|
18 | #include <boost/range/detail/remove_extent.hpp> |
---|
19 | #include <iterator> |
---|
20 | |
---|
21 | namespace boost |
---|
22 | { |
---|
23 | namespace range_detail |
---|
24 | { |
---|
25 | template< typename T > |
---|
26 | struct range_size_; |
---|
27 | |
---|
28 | ////////////////////////////////////////////////////////////////////// |
---|
29 | // default |
---|
30 | ////////////////////////////////////////////////////////////////////// |
---|
31 | |
---|
32 | template<> |
---|
33 | struct range_size_<std_container_> |
---|
34 | { |
---|
35 | template< typename C > |
---|
36 | struct inner { |
---|
37 | static BOOST_RANGE_DEDUCED_TYPENAME C::size_type fun( const C& c ) |
---|
38 | { |
---|
39 | return c.size(); |
---|
40 | }; |
---|
41 | }; |
---|
42 | }; |
---|
43 | |
---|
44 | ////////////////////////////////////////////////////////////////////// |
---|
45 | // pair |
---|
46 | ////////////////////////////////////////////////////////////////////// |
---|
47 | |
---|
48 | template<> |
---|
49 | struct range_size_<std_pair_> |
---|
50 | { |
---|
51 | template< typename P > |
---|
52 | struct inner { |
---|
53 | static BOOST_RANGE_DEDUCED_TYPENAME range_size<P>::type |
---|
54 | fun( const P& p ) |
---|
55 | { |
---|
56 | return std::distance( p.first, p.second ); |
---|
57 | } |
---|
58 | }; |
---|
59 | }; |
---|
60 | |
---|
61 | ////////////////////////////////////////////////////////////////////// |
---|
62 | // array |
---|
63 | ////////////////////////////////////////////////////////////////////// |
---|
64 | |
---|
65 | template<> |
---|
66 | struct range_size_<array_> |
---|
67 | { |
---|
68 | template<typename T> |
---|
69 | struct inner { |
---|
70 | static std::size_t fun(T& t) |
---|
71 | { |
---|
72 | return remove_extent<T>::size; |
---|
73 | } |
---|
74 | }; |
---|
75 | }; |
---|
76 | |
---|
77 | template<> |
---|
78 | struct range_size_<char_array_> |
---|
79 | { |
---|
80 | template<typename T> |
---|
81 | struct inner { |
---|
82 | static std::size_t fun(T& t) |
---|
83 | { |
---|
84 | return sizeof(T) / sizeof(T[0]); |
---|
85 | } |
---|
86 | }; |
---|
87 | }; |
---|
88 | |
---|
89 | template<> |
---|
90 | struct range_size_<wchar_t_array_> |
---|
91 | { |
---|
92 | template<typename T> |
---|
93 | struct inner { |
---|
94 | static std::size_t fun(T& t) |
---|
95 | { |
---|
96 | return sizeof(T) / sizeof(T[0]); |
---|
97 | } |
---|
98 | }; |
---|
99 | }; |
---|
100 | |
---|
101 | ////////////////////////////////////////////////////////////////////// |
---|
102 | // string |
---|
103 | ////////////////////////////////////////////////////////////////////// |
---|
104 | |
---|
105 | template<> |
---|
106 | struct range_size_<char_ptr_> |
---|
107 | { |
---|
108 | template<typename T> |
---|
109 | struct inner { |
---|
110 | static std::size_t fun( const char* s ) |
---|
111 | { |
---|
112 | return boost::range_detail::str_size( s ); |
---|
113 | } |
---|
114 | }; |
---|
115 | }; |
---|
116 | |
---|
117 | template<> |
---|
118 | struct range_size_<const_char_ptr_> |
---|
119 | { |
---|
120 | template<typename T> |
---|
121 | struct inner { |
---|
122 | static std::size_t fun( const char* s ) |
---|
123 | { |
---|
124 | return boost::range_detail::str_size( s ); |
---|
125 | } |
---|
126 | }; |
---|
127 | }; |
---|
128 | |
---|
129 | template<> |
---|
130 | struct range_size_<wchar_t_ptr_> |
---|
131 | { |
---|
132 | template<typename T> |
---|
133 | struct inner { |
---|
134 | static std::size_t fun( const wchar_t* s ) |
---|
135 | { |
---|
136 | return boost::range_detail::str_size( s ); |
---|
137 | } |
---|
138 | }; |
---|
139 | }; |
---|
140 | |
---|
141 | template<> |
---|
142 | struct range_size_<const_wchar_t_ptr_> |
---|
143 | { |
---|
144 | template<typename T> |
---|
145 | struct inner { |
---|
146 | static std::size_t fun( const wchar_t* s ) |
---|
147 | { |
---|
148 | return boost::range_detail::str_size( s ); |
---|
149 | } |
---|
150 | }; |
---|
151 | }; |
---|
152 | |
---|
153 | } // namespace 'range_detail' |
---|
154 | |
---|
155 | |
---|
156 | template< typename C > |
---|
157 | BOOST_RANGE_DEDUCED_TYPENAME range_size<C>::type |
---|
158 | size( const C& c ) |
---|
159 | { |
---|
160 | return range_detail::range_size_<range_detail::range<C>::type>::inner<C>::fun( c ); |
---|
161 | } |
---|
162 | |
---|
163 | } // namespace 'boost' |
---|
164 | |
---|
165 | |
---|
166 | #endif |
---|