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