williamr@2: /* boost random/detail/ptr_helper.hpp header file
williamr@2:  *
williamr@2:  * Copyright Jens Maurer 2002
williamr@2:  * Distributed under the Boost Software License, Version 1.0. (See
williamr@2:  * accompanying file LICENSE_1_0.txt or copy at
williamr@2:  * http://www.boost.org/LICENSE_1_0.txt)
williamr@2:  *
williamr@2:  * See http://www.boost.org for most recent version including documentation.
williamr@2:  *
williamr@2:  * $Id: ptr_helper.hpp,v 1.3 2004/07/27 03:43:32 dgregor Exp $
williamr@2:  *
williamr@2:  */
williamr@2: 
williamr@2: #ifndef BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
williamr@2: #define BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
williamr@2: 
williamr@2: #include <boost/config.hpp>
williamr@2: 
williamr@2: 
williamr@2: namespace boost {
williamr@2: namespace random {
williamr@2: namespace detail {
williamr@2: 
williamr@2: // type_traits could help here, but I don't want to depend on type_traits.
williamr@2: template<class T>
williamr@2: struct ptr_helper
williamr@2: {
williamr@2:   typedef T value_type;
williamr@2:   typedef T& reference_type;
williamr@2:   typedef const T& rvalue_type;
williamr@2:   static reference_type ref(T& r) { return r; }
williamr@2:   static const T& ref(const T& r) { return r; }
williamr@2: };
williamr@2: 
williamr@2: #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
williamr@2: template<class T>
williamr@2: struct ptr_helper<T&>
williamr@2: {
williamr@2:   typedef T value_type;
williamr@2:   typedef T& reference_type;
williamr@2:   typedef T& rvalue_type;
williamr@2:   static reference_type ref(T& r) { return r; }
williamr@2:   static const T& ref(const T& r) { return r; }
williamr@2: };
williamr@2: 
williamr@2: template<class T>
williamr@2: struct ptr_helper<T*>
williamr@2: {
williamr@2:   typedef T value_type;
williamr@2:   typedef T& reference_type;
williamr@2:   typedef T* rvalue_type;
williamr@2:   static reference_type ref(T * p) { return *p; }
williamr@2:   static const T& ref(const T * p) { return *p; }
williamr@2: };
williamr@2: #endif
williamr@2: 
williamr@2: } // namespace detail
williamr@2: } // namespace random
williamr@2: } // namespace boost
williamr@2: 
williamr@2: //
williamr@2: // BOOST_RANDOM_PTR_HELPER_SPEC --
williamr@2: //
williamr@2: //  Helper macro for broken compilers defines specializations of
williamr@2: //  ptr_helper.
williamr@2: //
williamr@2: #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
williamr@2: # define BOOST_RANDOM_PTR_HELPER_SPEC(T)                \
williamr@2: namespace boost { namespace random { namespace detail { \
williamr@2: template<>                                              \
williamr@2: struct ptr_helper<T&>                                   \
williamr@2: {                                                       \
williamr@2:   typedef T value_type;                                 \
williamr@2:   typedef T& reference_type;                            \
williamr@2:   typedef T& rvalue_type;                               \
williamr@2:   static reference_type ref(T& r) { return r; }         \
williamr@2:   static const T& ref(const T& r) { return r; }         \
williamr@2: };                                                      \
williamr@2:                                                         \
williamr@2: template<>                                              \
williamr@2: struct ptr_helper<T*>                                   \
williamr@2: {                                                       \
williamr@2:   typedef T value_type;                                 \
williamr@2:   typedef T& reference_type;                            \
williamr@2:   typedef T* rvalue_type;                               \
williamr@2:   static reference_type ref(T * p) { return *p; }       \
williamr@2:   static const T& ref(const T * p) { return *p; }       \
williamr@2: };                                                      \
williamr@2: }}}
williamr@2: #else
williamr@2: # define BOOST_RANDOM_PTR_HELPER_SPEC(T)
williamr@2: #endif 
williamr@2: 
williamr@2: #endif // BOOST_RANDOM_DETAIL_PTR_HELPER_HPP