Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
format-cout.hpp
Go to the documentation of this file.
1/*
2 FORMAT-COUT.hpp - use custom string conversions in stream output
3
4 Copyright (C)
5 2016, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12*/
13
14
44#ifndef LIB_FORMAT_COUT_H
45#define LIB_FORMAT_COUT_H
46
47#include "lib/format-obj.hpp"
48
49#include <string>
50#include <iostream>
51
52// make those generally visible
53using std::cout;
54using std::cerr;
55using std::endl;
56
57
58
59
60namespace std {
61
62 namespace { // toggle for the following generic overloads of operator<<
63
64 template<typename X>
66 }
67
68
70 template<typename _CharT, typename _Traits, typename X, typename = enable_StringConversion<X>>
71 inline basic_ostream<_CharT, _Traits>&
72 operator<< (basic_ostream<_CharT, _Traits>& os, X const& obj)
73 {
74 return os << util::StringConv<X>::invoke (obj);
75 }
76
77
82 template<typename _CharT, typename _Traits, typename X, typename = enable_StringConversion<X>>
83 inline basic_ostream<_CharT, _Traits>&
84 operator<< (basic_ostream<_CharT, _Traits>& os, X const* ptr)
85 {
86 if (ptr)
87 return util::showAdr(os, ptr) << " ↗" << util::StringConv<X>::invoke (*ptr);
88 else
89 return os << "⟂ «" << lib::meta::typeStr<X>() << "»";
90 }
91
92
93
94} // namespace std
95#endif /*LIB_FORMAT_COUT_H*/
Simple functions to represent objects, for debugging and diagnostics.
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
lib::meta::enable_if< lib::meta::use_StringConversion4Stream< X > > enable_StringConversion
STL namespace.
basic_ostream< _CharT, _Traits > & operator<<(basic_ostream< _CharT, _Traits > &os, X const &obj)
generic overload to use custom string conversions in output
ostream & showAdr(ostream &stream, void const *addr)
preconfigured format for pretty-printing of addresses
static std::string invoke(X const &x) noexcept