source: NonGTP/Boost/boost/random/detail/ptr_helper.hpp @ 857

Revision 857, 3.0 KB checked in by igarcia, 19 years ago (diff)
Line 
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,v 1.3 2004/07/27 03:43:32 dgregor Exp $
11 *
12 */
13
14#ifndef BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
15#define BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
16
17#include <boost/config.hpp>
18
19
20namespace boost {
21namespace random {
22namespace detail {
23
24// type_traits could help here, but I don't want to depend on type_traits.
25template<class T>
26struct 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 BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
36template<class T>
37struct 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
46template<class T>
47struct 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 boost
60
61//
62// BOOST_RANDOM_PTR_HELPER_SPEC --
63//
64//  Helper macro for broken compilers defines specializations of
65//  ptr_helper.
66//
67#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
68# define BOOST_RANDOM_PTR_HELPER_SPEC(T)                \
69namespace boost { namespace random { namespace detail { \
70template<>                                              \
71struct 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                                                        \
80template<>                                              \
81struct 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 BOOST_RANDOM_PTR_HELPER_SPEC(T)
92#endif
93
94#endif // BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
Note: See TracBrowser for help on using the repository browser.