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