range_value.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef BOOST_RANGE_VALUE_HPP
  2. #define BOOST_RANGE_VALUE_HPP
  3. // Copyright (c) 2015 Robert Ramey
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #include <iosfwd>
  9. // print range and value to a standard stream
  10. // make a simple wrapper
  11. template<typename T>
  12. struct range_value {
  13. // type requirement - a numeric type
  14. const T & m_t;
  15. constexpr range_value(const T & t)
  16. : m_t(t)
  17. {}
  18. };
  19. template<typename T>
  20. constexpr range_value<T> make_range_value(const T & t){
  21. return range_value<T>(t);
  22. }
  23. #include "interval.hpp"
  24. template<
  25. class CharT,
  26. class Traits,
  27. class T
  28. >
  29. std::basic_ostream<CharT, Traits> & operator<<(
  30. std::basic_ostream<CharT, Traits> & os,
  31. const range_value<T> & t
  32. ){
  33. return os
  34. << boost::safe_numerics::make_interval<T>()
  35. << t.m_t;
  36. }
  37. template<typename T>
  38. struct result_display {
  39. const T & m_t;
  40. result_display(const T & t) :
  41. m_t(t)
  42. {}
  43. };
  44. template<typename T>
  45. inline result_display<T> make_result_display(const T & t){
  46. return result_display<T>(t);
  47. }
  48. template<typename CharT, typename Traits, typename T>
  49. inline std::basic_ostream<CharT, Traits> &
  50. operator<<(
  51. std::basic_ostream<CharT, Traits> & os,
  52. const result_display<T> & r
  53. ){
  54. return os
  55. << std::hex
  56. << make_range_value(r.m_t)
  57. << "(" << std::dec << r.m_t << ")";
  58. }
  59. #endif // BOOST_RANGE_VALUE_HPP