-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto_stream_helper.hpp
49 lines (38 loc) · 1.36 KB
/
to_stream_helper.hpp
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
/// Provides thin wrapper for Utils::Manip::to_stream and LOG_VAR() macro to simplify log output
// Copyright Dmitriy Maksimov 2009 - 2013.
// 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)
#ifndef TO_STREAM_HELPER_HPP
#define TO_STREAM_HELPER_HPP
#include "to_stream.hpp"
namespace Utils
{
namespace Manip
{
namespace details
{
template <typename T>
struct ToStreamWrapper
{
const T& data;
ToStreamWrapper(const T& var)
: data(var)
{
}
};
template <typename T>
const ToStreamWrapper<T> ToStreamHelper(const T& var)
{
return ToStreamWrapper<T>(var);
}
template <typename CharT, typename Traits, typename T>
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits> &strm, const ToStreamWrapper<T>& ts)
{
return ::Utils::Manip::to_stream(strm, ts.data);
}
} // namespace details
} // namespace Manip
} // namespace Utils
#define LOG_VAR(VAR) #VAR "<" << ::Utils::Manip::details::ToStreamHelper(VAR) << "> "
#endif // TO_STREAM_HELPER_HPP