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_SIZE_HPP |
---|
13 | #define BOOST_RANGE_DETAIL_SIZE_HPP |
---|
14 | |
---|
15 | #include <boost/config.hpp> // BOOST_MSVC |
---|
16 | #include <boost/detail/workaround.hpp> |
---|
17 | #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) |
---|
18 | # include <boost/range/detail/vc6/size.hpp> |
---|
19 | #else |
---|
20 | # include <boost/range/detail/implementation_help.hpp> |
---|
21 | # include <boost/range/detail/size_type.hpp> |
---|
22 | # include <boost/range/detail/common.hpp> |
---|
23 | # if BOOST_WORKAROUND(BOOST_MSVC, == 1300) |
---|
24 | # include <boost/range/detail/remove_extent.hpp> |
---|
25 | # endif |
---|
26 | # include <iterator> |
---|
27 | |
---|
28 | namespace boost |
---|
29 | { |
---|
30 | namespace range_detail |
---|
31 | { |
---|
32 | template< typename T > |
---|
33 | struct range_size_; |
---|
34 | |
---|
35 | ////////////////////////////////////////////////////////////////////// |
---|
36 | // default |
---|
37 | ////////////////////////////////////////////////////////////////////// |
---|
38 | |
---|
39 | template<> |
---|
40 | struct range_size_<std_container_> |
---|
41 | { |
---|
42 | template< typename C > |
---|
43 | static BOOST_RANGE_DEDUCED_TYPENAME C::size_type fun( const C& c ) |
---|
44 | { |
---|
45 | return c.size(); |
---|
46 | }; |
---|
47 | }; |
---|
48 | |
---|
49 | ////////////////////////////////////////////////////////////////////// |
---|
50 | // pair |
---|
51 | ////////////////////////////////////////////////////////////////////// |
---|
52 | |
---|
53 | template<> |
---|
54 | struct range_size_<std_pair_> |
---|
55 | { |
---|
56 | template< typename P > |
---|
57 | static BOOST_RANGE_DEDUCED_TYPENAME range_size<P>::type |
---|
58 | fun( const P& p ) |
---|
59 | { |
---|
60 | return std::distance( p.first, p.second ); |
---|
61 | } |
---|
62 | }; |
---|
63 | |
---|
64 | ////////////////////////////////////////////////////////////////////// |
---|
65 | // array |
---|
66 | ////////////////////////////////////////////////////////////////////// |
---|
67 | |
---|
68 | template<> |
---|
69 | struct range_size_<array_> |
---|
70 | { |
---|
71 | #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) |
---|
72 | template< typename T, std::size_t sz > |
---|
73 | static std::size_t fun( T BOOST_RANGE_ARRAY_REF()[sz] ) |
---|
74 | { |
---|
75 | return sz; |
---|
76 | } |
---|
77 | #else |
---|
78 | template<typename T> |
---|
79 | static std::size_t fun(T& t) |
---|
80 | { |
---|
81 | return remove_extent<T>::size; |
---|
82 | } |
---|
83 | #endif |
---|
84 | }; |
---|
85 | |
---|
86 | template<> |
---|
87 | struct range_size_<char_array_> |
---|
88 | { |
---|
89 | template< typename T, std::size_t sz > |
---|
90 | static std::size_t fun( T BOOST_RANGE_ARRAY_REF()[sz] ) |
---|
91 | { |
---|
92 | return boost::range_detail::array_size( boost_range_array ); |
---|
93 | } |
---|
94 | }; |
---|
95 | |
---|
96 | template<> |
---|
97 | struct range_size_<wchar_t_array_> |
---|
98 | { |
---|
99 | template< typename T, std::size_t sz > |
---|
100 | static std::size_t fun( T BOOST_RANGE_ARRAY_REF()[sz] ) |
---|
101 | { |
---|
102 | return boost::range_detail::array_size( boost_range_array ); |
---|
103 | } |
---|
104 | }; |
---|
105 | |
---|
106 | ////////////////////////////////////////////////////////////////////// |
---|
107 | // string |
---|
108 | ////////////////////////////////////////////////////////////////////// |
---|
109 | |
---|
110 | template<> |
---|
111 | struct range_size_<char_ptr_> |
---|
112 | { |
---|
113 | static std::size_t fun( const char* s ) |
---|
114 | { |
---|
115 | return boost::range_detail::str_size( s ); |
---|
116 | } |
---|
117 | }; |
---|
118 | |
---|
119 | template<> |
---|
120 | struct range_size_<const_char_ptr_> |
---|
121 | { |
---|
122 | static std::size_t fun( const char* s ) |
---|
123 | { |
---|
124 | return boost::range_detail::str_size( s ); |
---|
125 | } |
---|
126 | }; |
---|
127 | |
---|
128 | template<> |
---|
129 | struct range_size_<wchar_t_ptr_> |
---|
130 | { |
---|
131 | static std::size_t fun( const wchar_t* s ) |
---|
132 | { |
---|
133 | return boost::range_detail::str_size( s ); |
---|
134 | } |
---|
135 | }; |
---|
136 | |
---|
137 | template<> |
---|
138 | struct range_size_<const_wchar_t_ptr_> |
---|
139 | { |
---|
140 | static std::size_t fun( const wchar_t* s ) |
---|
141 | { |
---|
142 | return boost::range_detail::str_size( s ); |
---|
143 | } |
---|
144 | }; |
---|
145 | |
---|
146 | } // namespace 'range_detail' |
---|
147 | |
---|
148 | |
---|
149 | template< typename C > |
---|
150 | BOOST_RANGE_DEDUCED_TYPENAME range_size<C>::type |
---|
151 | size( const C& c ) |
---|
152 | { |
---|
153 | return range_detail::range_size_< BOOST_RANGE_DEDUCED_TYPENAME range_detail::range<C>::type >::fun( c ); |
---|
154 | } |
---|
155 | |
---|
156 | } // namespace 'boost' |
---|
157 | |
---|
158 | # endif |
---|
159 | #endif |
---|