summaryrefslogtreecommitdiff
path: root/boost/safe_numerics/range_value.hpp
blob: ceef19e8985833138811ac063804c9581c21074e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef BOOST_RANGE_VALUE_HPP
#define BOOST_RANGE_VALUE_HPP

//  Copyright (c) 2015 Robert Ramey
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <iosfwd>

// print range and value to a standard stream
// make a simple wrapper
template<typename T>
struct range_value {
    // type requirement - a numeric type
    const T & m_t;

    constexpr range_value(const T & t)
    :   m_t(t)
    {}

};

template<typename T>
constexpr range_value<T> make_range_value(const T & t){
    return range_value<T>(t);
}

#include "interval.hpp"

template<
    class CharT,
    class Traits,
    class T
>
std::basic_ostream<CharT, Traits> & operator<<(
    std::basic_ostream<CharT, Traits> & os,
    const range_value<T> & t
){
    return os
        << boost::safe_numerics::make_interval<T>()
        << t.m_t;
}

template<typename T>
struct result_display {
    const T & m_t;
    result_display(const T & t) :
        m_t(t)
    {}
};

template<typename T>
result_display<T> make_result_display(const T & t){
    return result_display<T>(t);
}

template<typename CharT, typename Traits, typename T>
inline std::basic_ostream<CharT, Traits> &
operator<<(
    std::basic_ostream<CharT, Traits> & os,
    const result_display<T> & r
){
    return os
        << std::hex
        << make_range_value(r.m_t)
        << "(" << std::dec << r.m_t << ")";
}

#endif  // BOOST_RANGE_VALUE_HPP