Jeff Thompson | 86b6d64 | 2013-10-17 15:01:56 -0700 | [diff] [blame] | 1 | /* boost random/detail/ptr_helper.hpp header file |
| 2 | * |
| 3 | * Copyright Jens Maurer 2002 |
| 4 | * Distributed under the Boost Software License, Version 1.0. (See |
| 5 | * accompanying file LICENSE_1_0.txt or copy at |
| 6 | * http://www.boost.org/LICENSE_1_0.txt) |
| 7 | * |
| 8 | * See http://www.boost.org for most recent version including documentation. |
| 9 | * |
| 10 | * $Id: ptr_helper.hpp 24096 2004-07-27 03:43:34Z dgregor $ |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #ifndef NDNBOOST_RANDOM_DETAIL_PTR_HELPER_HPP |
| 15 | #define NDNBOOST_RANDOM_DETAIL_PTR_HELPER_HPP |
| 16 | |
| 17 | #include <ndnboost/config.hpp> |
| 18 | |
| 19 | |
| 20 | namespace ndnboost { |
| 21 | namespace random { |
| 22 | namespace detail { |
| 23 | |
| 24 | // type_traits could help here, but I don't want to depend on type_traits. |
| 25 | template<class T> |
| 26 | struct ptr_helper |
| 27 | { |
| 28 | typedef T value_type; |
| 29 | typedef T& reference_type; |
| 30 | typedef const T& rvalue_type; |
| 31 | static reference_type ref(T& r) { return r; } |
| 32 | static const T& ref(const T& r) { return r; } |
| 33 | }; |
| 34 | |
| 35 | #ifndef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
| 36 | template<class T> |
| 37 | struct ptr_helper<T&> |
| 38 | { |
| 39 | typedef T value_type; |
| 40 | typedef T& reference_type; |
| 41 | typedef T& rvalue_type; |
| 42 | static reference_type ref(T& r) { return r; } |
| 43 | static const T& ref(const T& r) { return r; } |
| 44 | }; |
| 45 | |
| 46 | template<class T> |
| 47 | struct ptr_helper<T*> |
| 48 | { |
| 49 | typedef T value_type; |
| 50 | typedef T& reference_type; |
| 51 | typedef T* rvalue_type; |
| 52 | static reference_type ref(T * p) { return *p; } |
| 53 | static const T& ref(const T * p) { return *p; } |
| 54 | }; |
| 55 | #endif |
| 56 | |
| 57 | } // namespace detail |
| 58 | } // namespace random |
| 59 | } // namespace ndnboost |
| 60 | |
| 61 | // |
| 62 | // NDNBOOST_RANDOM_PTR_HELPER_SPEC -- |
| 63 | // |
| 64 | // Helper macro for broken compilers defines specializations of |
| 65 | // ptr_helper. |
| 66 | // |
| 67 | #ifdef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
| 68 | # define NDNBOOST_RANDOM_PTR_HELPER_SPEC(T) \ |
| 69 | namespace ndnboost { namespace random { namespace detail { \ |
| 70 | template<> \ |
| 71 | struct ptr_helper<T&> \ |
| 72 | { \ |
| 73 | typedef T value_type; \ |
| 74 | typedef T& reference_type; \ |
| 75 | typedef T& rvalue_type; \ |
| 76 | static reference_type ref(T& r) { return r; } \ |
| 77 | static const T& ref(const T& r) { return r; } \ |
| 78 | }; \ |
| 79 | \ |
| 80 | template<> \ |
| 81 | struct ptr_helper<T*> \ |
| 82 | { \ |
| 83 | typedef T value_type; \ |
| 84 | typedef T& reference_type; \ |
| 85 | typedef T* rvalue_type; \ |
| 86 | static reference_type ref(T * p) { return *p; } \ |
| 87 | static const T& ref(const T * p) { return *p; } \ |
| 88 | }; \ |
| 89 | }}} |
| 90 | #else |
| 91 | # define NDNBOOST_RANDOM_PTR_HELPER_SPEC(T) |
| 92 | #endif |
| 93 | |
| 94 | #endif // NDNBOOST_RANDOM_DETAIL_PTR_HELPER_HPP |