print.hpp
3.74 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef BOOST_LEAF_DETAIL_PRINT_HPP_INCLUDED
#define BOOST_LEAF_DETAIL_PRINT_HPP_INCLUDED
// Copyright 2018-2022 Emil Dotchevski and Reverge Studios, Inc.
// 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 <boost/leaf/config.hpp>
#include <boost/leaf/detail/demangle.hpp>
#if BOOST_LEAF_CFG_DIAGNOSTICS
#include <type_traits>
#include <exception>
#include <iosfwd>
#include <cstring>
namespace boost { namespace leaf {
namespace leaf_detail
{
template <class T, class E = void>
struct is_printable: std::false_type
{
};
template <class T>
struct is_printable<T, decltype(std::declval<std::ostream&>()<<std::declval<T const &>(), void())>: std::true_type
{
};
////////////////////////////////////////
template <class T, class E = void>
struct has_printable_member_value: std::false_type
{
};
template <class T>
struct has_printable_member_value<T, decltype(std::declval<std::ostream&>()<<std::declval<T const &>().value, void())>: std::true_type
{
};
////////////////////////////////////////
template <
class Wrapper,
bool WrapperPrintable = is_printable<Wrapper>::value,
bool ValuePrintable = has_printable_member_value<Wrapper>::value,
bool IsException = std::is_base_of<std::exception,Wrapper>::value,
bool IsEnum = std::is_enum<Wrapper>::value>
struct diagnostic;
template <class Wrapper, bool ValuePrintable, bool IsException, bool IsEnum>
struct diagnostic<Wrapper, true, ValuePrintable, IsException, IsEnum>
{
static constexpr bool is_invisible = false;
template <class CharT, class Traits>
static void print( std::basic_ostream<CharT, Traits> & os, Wrapper const & x )
{
os << x;
}
};
template <class Wrapper, bool IsException, bool IsEnum>
struct diagnostic<Wrapper, false, true, IsException, IsEnum>
{
static constexpr bool is_invisible = false;
template <class CharT, class Traits>
static void print( std::basic_ostream<CharT, Traits> & os, Wrapper const & x )
{
os << type<Wrapper>() << ": " << x.value;
}
};
template <class Wrapper, bool IsEnum>
struct diagnostic<Wrapper, false, false, true, IsEnum>
{
static constexpr bool is_invisible = false;
template <class CharT, class Traits>
static void print( std::basic_ostream<CharT, Traits> & os, Wrapper const & ex )
{
os << type<Wrapper>() << ": std::exception::what(): " << ex.what();
}
};
template <class Wrapper>
struct diagnostic<Wrapper, false, false, false, false>
{
static constexpr bool is_invisible = false;
template <class CharT, class Traits>
static void print( std::basic_ostream<CharT, Traits> & os, Wrapper const & )
{
os << type<Wrapper>() << ": {Non-Printable}";
}
};
template <class Wrapper>
struct diagnostic<Wrapper, false, false, false, true>
{
static constexpr bool is_invisible = false;
template <class CharT, class Traits>
static void print( std::basic_ostream<CharT, Traits> & os, Wrapper const & w )
{
os << type<Wrapper>() << ": " << static_cast<typename std::underlying_type<Wrapper>::type>(w);
}
};
template <>
struct diagnostic<std::exception_ptr, false, false, false>
{
static constexpr bool is_invisible = true;
template <class CharT, class Traits>
BOOST_LEAF_CONSTEXPR static void print( std::basic_ostream<CharT, Traits> &, std::exception_ptr const & )
{
}
};
}
} }
#endif
#endif