Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 11 | #ifndef NDNBOOST_RANGE_SIZE_TYPE_HPP |
| 12 | #define NDNBOOST_RANGE_SIZE_TYPE_HPP |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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> |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 20 | #ifdef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
| 30 | namespace 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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 46 | static yes_type test(NDNBOOST_DEDUCED_TYPENAME C::size_type x); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 58 | typedef NDNBOOST_DEDUCED_TYPENAME make_unsigned< |
| 59 | NDNBOOST_DEDUCED_TYPENAME range_difference<C>::type |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 60 | >::type type; |
| 61 | }; |
| 62 | |
| 63 | template<typename C> |
| 64 | struct range_size< |
| 65 | C, |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 66 | NDNBOOST_DEDUCED_TYPENAME enable_if<has_size_type<C>, void>::type |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 67 | > |
| 68 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 69 | typedef NDNBOOST_DEDUCED_TYPENAME C::size_type type; |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 86 | #endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 87 | |
| 88 | |
| 89 | #endif |