blob: ce48639e53d08a83a0e617225563b0654d52b972 [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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070011#ifndef NDNBOOST_RANGE_SIZE_TYPE_HPP
12#define NDNBOOST_RANGE_SIZE_TYPE_HPP
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070013
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>
Jeff Thompson3d613fd2013-10-15 15:39:04 -070020#ifdef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070021#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>
Jeff Thompson3d613fd2013-10-15 15:39:04 -070046 static yes_type test(NDNBOOST_DEDUCED_TYPENAME C::size_type x);
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070047
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 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -070058 typedef NDNBOOST_DEDUCED_TYPENAME make_unsigned<
59 NDNBOOST_DEDUCED_TYPENAME range_difference<C>::type
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070060 >::type type;
61 };
62
63 template<typename C>
64 struct range_size<
65 C,
Jeff Thompson3d613fd2013-10-15 15:39:04 -070066 NDNBOOST_DEDUCED_TYPENAME enable_if<has_size_type<C>, void>::type
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070067 >
68 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -070069 typedef NDNBOOST_DEDUCED_TYPENAME C::size_type type;
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070070 };
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070086#endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070087
88
89#endif