blob: 0ae8a877ff78f0bf19f238a95a48b471647f5c80 [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// 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 <ndnboost/range/config.hpp>
19#include <ndnboost/range/difference_type.hpp>
20#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
21#include <ndnboost/range/detail/size_type.hpp>
22#else
23
24#include <ndnboost/utility/enable_if.hpp>
25#include <ndnboost/type_traits/make_unsigned.hpp>
26#include <ndnboost/type_traits/remove_const.hpp>
27#include <cstddef>
28#include <utility>
29
30namespace ndnboost
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 ndnboost
85
86#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
87
88
89#endif