operators.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* boost random/detail/operators.hpp header file
  2. *
  3. * Copyright Steven Watanabe 2010-2011
  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. #ifndef BOOST_RANDOM_DETAIL_OPERATORS_HPP
  13. #define BOOST_RANDOM_DETAIL_OPERATORS_HPP
  14. #include <boost/random/detail/config.hpp>
  15. #include <boost/detail/workaround.hpp>
  16. #if BOOST_WORKAROUND(BOOST_MSVC, <= 1310) \
  17. || BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100))
  18. #define BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, T, t) \
  19. template<class CharT, class Traits> \
  20. friend std::basic_ostream<CharT,Traits>& \
  21. operator<<(std::basic_ostream<CharT,Traits>& os, const T& t) { \
  22. t.print(os, t); \
  23. return os; \
  24. } \
  25. template<class CharT, class Traits> \
  26. static std::basic_ostream<CharT,Traits>& \
  27. print(std::basic_ostream<CharT,Traits>& os, const T& t)
  28. #define BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, T, t) \
  29. template<class CharT, class Traits> \
  30. friend std::basic_istream<CharT,Traits>& \
  31. operator>>(std::basic_istream<CharT,Traits>& is, T& t) { \
  32. t.read(is, t); \
  33. return is; \
  34. } \
  35. template<class CharT, class Traits> \
  36. static std::basic_istream<CharT,Traits>& \
  37. read(std::basic_istream<CharT,Traits>& is, T& t)
  38. #endif
  39. #if defined(__BORLANDC__)
  40. #define BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(T, lhs, rhs) \
  41. bool operator==(const T& rhs) const \
  42. { return T::is_equal(*this, rhs); } \
  43. static bool is_equal(const T& lhs, const T& rhs)
  44. #define BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(T) \
  45. bool operator!=(const T& rhs) const \
  46. { return !T::is_equal(*this, rhs); }
  47. #endif
  48. #ifndef BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR
  49. #define BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, T, t) \
  50. template<class CharT, class Traits> \
  51. friend std::basic_ostream<CharT,Traits>& \
  52. operator<<(std::basic_ostream<CharT,Traits>& os, const T& t)
  53. #endif
  54. #ifndef BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR
  55. #define BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, T, t) \
  56. template<class CharT, class Traits> \
  57. friend std::basic_istream<CharT,Traits>& \
  58. operator>>(std::basic_istream<CharT,Traits>& is, T& t)
  59. #endif
  60. #ifndef BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR
  61. #define BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(T, lhs, rhs) \
  62. friend bool operator==(const T& lhs, const T& rhs)
  63. #endif
  64. #ifndef BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR
  65. #define BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(T) \
  66. friend bool operator!=(const T& lhs, const T& rhs) \
  67. { return !(lhs == rhs); }
  68. #endif
  69. #endif