ptr_helper.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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$
  11. *
  12. */
  13. #ifndef BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
  14. #define BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
  15. #include <boost/config.hpp>
  16. namespace boost {
  17. namespace random {
  18. namespace detail {
  19. // type_traits could help here, but I don't want to depend on type_traits.
  20. template<class T>
  21. struct ptr_helper
  22. {
  23. typedef T value_type;
  24. typedef T& reference_type;
  25. typedef const T& rvalue_type;
  26. static reference_type ref(T& r) { return r; }
  27. static const T& ref(const T& r) { return r; }
  28. };
  29. template<class T>
  30. struct ptr_helper<T&>
  31. {
  32. typedef T value_type;
  33. typedef T& reference_type;
  34. typedef T& rvalue_type;
  35. static reference_type ref(T& r) { return r; }
  36. static const T& ref(const T& r) { return r; }
  37. };
  38. template<class T>
  39. struct ptr_helper<T*>
  40. {
  41. typedef T value_type;
  42. typedef T& reference_type;
  43. typedef T* rvalue_type;
  44. static reference_type ref(T * p) { return *p; }
  45. static const T& ref(const T * p) { return *p; }
  46. };
  47. } // namespace detail
  48. } // namespace random
  49. } // namespace boost
  50. //
  51. // BOOST_RANDOM_PTR_HELPER_SPEC --
  52. //
  53. // Helper macro for broken compilers defines specializations of
  54. // ptr_helper.
  55. //
  56. # define BOOST_RANDOM_PTR_HELPER_SPEC(T)
  57. #endif // BOOST_RANDOM_DETAIL_PTR_HELPER_HPP