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) Lumiera.org
5  2016, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
53 #ifndef LIB_FORMAT_COUT_H
54 #define LIB_FORMAT_COUT_H
55 
56 #include "lib/format-obj.hpp"
57 
58 #include <string>
59 #include <iostream>
60 
61 // make those generally visible
62 using std::cout;
63 using std::cerr;
64 using std::endl;
65 
66 
67 
68 
69 namespace std {
70 
71  namespace { // toggle for the following generic overloads of operator<<
72 
73  template<typename X>
75  }
76 
77 
79  template<typename _CharT, typename _Traits, typename X, typename = enable_StringConversion<X>>
80  inline basic_ostream<_CharT, _Traits>&
81  operator<< (basic_ostream<_CharT, _Traits>& os, X const& obj)
82  {
83  return os << util::StringConv<X>::invoke (obj);
84  }
85 
86 
91  template<typename _CharT, typename _Traits, typename X, typename = enable_StringConversion<X>>
92  inline basic_ostream<_CharT, _Traits>&
93  operator<< (basic_ostream<_CharT, _Traits>& os, X const* ptr)
94  {
95  if (ptr)
96  return util::showAddr(os, ptr) << " ↗" << util::StringConv<X>::invoke (*ptr);
97  else
98  return os << "⟂ «" << lib::meta::typeStr<X>() << "»";
99  }
100 
101 
102 
103 } // namespace std
104 #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:92
Simple functions to represent objects, for debugging and diagnostics.
failsafe invocation of custom string conversion.
Definition: meta/util.hpp:399