Lumiera  0.pre.03
»edit your freedom«
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
53 using std::cout;
54 using std::cerr;
55 using std::endl;
56 
57 
58 
59 
60 namespace 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*/
STL namespace.
typename enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition: meta/util.hpp:83
Simple functions to represent objects, for debugging and diagnostics.
failsafe invocation of custom string conversion.
Definition: meta/util.hpp:390