Lumiera  0.pre.03
»edityourfreedom«
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
util::toString( "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>

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 More...
 
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...