@@ -11,6 +11,24 @@ namespace plog
11
11
{
12
12
namespace detail
13
13
{
14
+ namespace meta
15
+ {
16
+ template <class T >
17
+ inline T& declval ()
18
+ {
19
+ #ifdef __INTEL_COMPILER
20
+ # pragma warning(suppress: 327) // NULL reference is not allowed
21
+ #endif
22
+ return *reinterpret_cast <T*>(0 );
23
+ }
24
+
25
+ template <bool B, class T = void >
26
+ struct enableIf {};
27
+
28
+ template <class T >
29
+ struct enableIf <true , T> { typedef T type; };
30
+ }
31
+
14
32
// ////////////////////////////////////////////////////////////////////////
15
33
// Stream output operators as free functions
16
34
@@ -27,11 +45,22 @@ namespace plog
27
45
#endif
28
46
}
29
47
48
+ inline void operator <<(util::nostringstream& stream, char * data)
49
+ {
50
+ plog::detail::operator <<(stream, const_cast <const char *>(data));
51
+ }
52
+
30
53
inline void operator <<(util::nostringstream& stream, const std::string& data)
31
54
{
32
55
plog::detail::operator <<(stream, data.c_str ());
33
56
}
34
57
58
+ template <typename T>
59
+ inline typename meta::enableIf<sizeof (static_cast <std::basic_string<util::nchar> >(meta::declval<T>())), void >::type operator <<(util::nostringstream& stream, const T& data)
60
+ {
61
+ plog::detail::operator <<(stream, static_cast <std::basic_string<util::nchar> >(data));
62
+ }
63
+
35
64
#if PLOG_ENABLE_WCHAR_INPUT
36
65
inline void operator <<(util::nostringstream& stream, const wchar_t * data)
37
66
{
@@ -44,6 +73,11 @@ namespace plog
44
73
# endif
45
74
}
46
75
76
+ inline void operator <<(util::nostringstream& stream, wchar_t * data)
77
+ {
78
+ plog::detail::operator <<(stream, const_cast <const wchar_t *>(data));
79
+ }
80
+
47
81
inline void operator <<(util::nostringstream& stream, const std::wstring& data)
48
82
{
49
83
plog::detail::operator <<(stream, data.c_str ());
@@ -67,10 +101,7 @@ namespace plog
67
101
template <class T , class Stream >
68
102
struct isStreamable
69
103
{
70
- #ifdef __INTEL_COMPILER
71
- # pragma warning(suppress: 327) // NULL reference is not allowed
72
- #endif
73
- enum { value = sizeof (operator <<(*reinterpret_cast <Stream*>(0 ), *reinterpret_cast <const T*>(0 ))) != sizeof (char ) };
104
+ enum { value = sizeof (operator <<(meta::declval<Stream>(), meta::declval<const T>())) != sizeof (char ) };
74
105
};
75
106
76
107
template <class Stream >
@@ -90,12 +121,6 @@ namespace plog
90
121
{
91
122
enum { value = false };
92
123
};
93
-
94
- template <bool B, class T = void >
95
- struct enableIf {};
96
-
97
- template <class T >
98
- struct enableIf <true , T> { typedef T type; };
99
124
}
100
125
101
126
template <class T >
0 commit comments