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 | #ifndef BOOST_RANGE_SIZE_TYPE_HPP |
12 | #define BOOST_RANGE_SIZE_TYPE_HPP |
13 | |
14 | #if defined(_MSC_VER) |
15 | # pragma once |
16 | #endif |
17 | |
18 | #include <boost/range/config.hpp> |
19 | #include <boost/range/difference_type.hpp> |
20 | #include <boost/range/concepts.hpp> |
21 | |
22 | #include <boost/utility/enable_if.hpp> |
23 | #include <boost/type_traits/make_unsigned.hpp> |
24 | #include <boost/type_traits/remove_const.hpp> |
25 | #include <cstddef> |
26 | #include <utility> |
27 | |
28 | namespace boost |
29 | { |
30 | namespace detail |
31 | { |
32 | |
33 | ////////////////////////////////////////////////////////////////////////// |
34 | // default |
35 | ////////////////////////////////////////////////////////////////////////// |
36 | |
37 | template<typename T> |
38 | class has_size_type |
39 | { |
40 | typedef char no_type; |
41 | struct yes_type { char dummy[2]; }; |
42 | |
43 | template<typename C> |
44 | static yes_type test(BOOST_DEDUCED_TYPENAME C::size_type x); |
45 | |
46 | template<typename C> |
47 | static no_type test(...); |
48 | |
49 | public: |
50 | static const bool value = sizeof(test<T>(0)) == sizeof(yes_type); |
51 | }; |
52 | |
53 | template<typename C, typename Enabler=void> |
54 | struct range_size |
55 | { |
56 | typedef BOOST_DEDUCED_TYPENAME make_unsigned< |
57 | BOOST_DEDUCED_TYPENAME range_difference<C>::type |
58 | >::type type; |
59 | }; |
60 | |
61 | template<typename C> |
62 | struct range_size< |
63 | C, |
64 | BOOST_DEDUCED_TYPENAME ::boost::enable_if<has_size_type<C>, void>::type |
65 | > |
66 | { |
67 | typedef BOOST_DEDUCED_TYPENAME C::size_type type; |
68 | }; |
69 | |
70 | } |
71 | |
72 | template< class T > |
73 | struct range_size : |
74 | detail::range_size<T> |
75 | { |
76 | // Very strange things happen on some compilers that have the range concept |
77 | // asserts disabled. This preprocessor condition is clearly redundant on a |
78 | // working compiler but is vital for at least some compilers such as clang 4.2 |
79 | // but only on the Mac! |
80 | #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT == 1 |
81 | BOOST_RANGE_CONCEPT_ASSERT((boost::SinglePassRangeConcept<T>)); |
82 | #endif |
83 | }; |
84 | |
85 | template< class T > |
86 | struct range_size<const T > |
87 | : detail::range_size<T> |
88 | { |
89 | #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT == 1 |
90 | BOOST_RANGE_CONCEPT_ASSERT((boost::SinglePassRangeConcept<T>)); |
91 | #endif |
92 | }; |
93 | |
94 | } // namespace boost |
95 | |
96 | |
97 | |
98 | #endif |
99 |