]> git.donarmstrong.com Git - rsem.git/blob - boost/range/size_type.hpp
Updated boost to v1.55.0
[rsem.git] / boost / range / size_type.hpp
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) && (_MSC_VER >= 1020)
15 # pragma once
16 #endif
17
18 #include <boost/range/config.hpp>
19 #include <boost/range/difference_type.hpp>
20 #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
21 #include <boost/range/detail/size_type.hpp>
22 #else
23
24 #include <boost/utility/enable_if.hpp>
25 #include <boost/type_traits/make_unsigned.hpp>
26 #include <boost/type_traits/remove_const.hpp>
27 #include <cstddef>
28 #include <utility>
29
30 namespace boost
31 {
32     namespace detail
33     {
34
35         //////////////////////////////////////////////////////////////////////////
36         // default
37         //////////////////////////////////////////////////////////////////////////
38
39         template<typename T>
40         class has_size_type
41         {
42             typedef char no_type;
43             struct yes_type { char dummy[2]; };
44
45             template<typename C>
46             static yes_type test(BOOST_DEDUCED_TYPENAME C::size_type x);
47
48             template<typename C, typename Arg>
49             static no_type test(Arg x);
50
51         public:
52             static const bool value = sizeof(test<T>(0)) == sizeof(yes_type);
53         };
54
55         template<typename C, typename Enabler=void>
56         struct range_size
57         {
58             typedef BOOST_DEDUCED_TYPENAME make_unsigned<
59                 BOOST_DEDUCED_TYPENAME range_difference<C>::type
60             >::type type;
61         };
62
63         template<typename C>
64         struct range_size<
65             C,
66             BOOST_DEDUCED_TYPENAME enable_if<has_size_type<C>, void>::type
67         >
68         {
69             typedef BOOST_DEDUCED_TYPENAME C::size_type type;
70         };
71
72     }
73
74     template< class T >
75     struct range_size :
76         detail::range_size<T>
77     { };
78
79     template< class T >
80     struct range_size<const T >
81         : detail::range_size<T>
82     { };
83
84 } // namespace boost
85
86 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
87
88
89 #endif