Lumiera  0.pre.03
»edit your freedom«
format-cout.hpp File Reference

Go to the source code of this file.

Description

Automatically use custom string conversion in C++ stream output.

This diagnostics facility allows just to dump any object into cout or cerr. Pointers will be detected, checked for NULL and printed as address, followed by the representation of the pointee. When the displayed entity defines an operator string(), this custom string conversion will be used (suppressing any exceptions, of course). As fallback, a simplified type string is printed.

policy
What shall be expected from a generic toString conversion? It should be minimal, it should be transparent and it should always work and deliver a string, irrespective of the circumstances. By extension, this means that we do not want to differentiate much between values, references and pointers, which also means, we do not want to indicate pointers explicitly (just signal NULL, when encountered). The situation is slightly different for the ostream inserter; in a modern GUI application, there isn't much use for STDOUT and STDERR, beyond error messages and unit testing. Thus, we can strive at building a more convenient flavour here, which does indeed even show the address of pointers.
See also
FormatCOUT_test
FormatHelper_test
generic string conversion helper
frontend for boost::format, printf-style

Definition in file format-cout.hpp.

#include "lib/format-obj.hpp"
#include <string>
#include <iostream>

Typedefs

template<typename X >
using enable_StringConversion = lib::meta::enable_if< lib::meta::use_StringConversion4Stream< X > >
 

Functions

template<typename _CharT , typename _Traits , typename X , typename = enable_StringConversion<X>>
basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &os, X const &obj)
 generic overload to use custom string conversions in output
 
template<typename _CharT , typename _Traits , typename X , typename = enable_StringConversion<X>>
basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &os, X const *ptr)
 generic overload to pretty-print any pointer in output More...
 

Namespaces

Function Documentation

◆ operator<<()

basic_ostream<_CharT, _Traits>& std::operator<< ( basic_ostream< _CharT, _Traits > &  os,
X const *  ptr 
)
inline

generic overload to pretty-print any pointer in output

Note
possibly also invokes custom string conversion, in case the pointee defines one

Definition at line 93 of file format-cout.hpp.