The Battle for Wesnoth  1.19.5+dev
Public Member Functions | Private Attributes | List of all members
formatter Class Reference

std::ostringstream wrapper. More...

#include <formatter.hpp>

Public Member Functions

 formatter ()
 
template<typename T >
formatteroperator<< (const T &o) &
 
template<typename T >
formatter && operator<< (const T &o) &&
 
std::string str () const
 
 operator std::string () const &&
 
formatteroperator<< (std::ostream &(*fn)(std::ostream &)) &
 
formatter && operator<< (std::ostream &(*fn)(std::ostream &)) &&
 
formatteroperator<< (std::ios_base &(*fn)(std::ios_base &)) &
 
formatter && operator<< (std::ios_base &(*fn)(std::ios_base &)) &&
 

Private Attributes

std::ostringstream stream_
 

Detailed Description

std::ostringstream wrapper.

ostringstream's operator<< doesn't return a ostringstream&. It returns an ostream& instead. This is unfortunate, because it means that you can't do something like this: (ostringstream() << n).str() to convert an integer to a string, all in one line instead you have to use this far more tedious approach: ostringstream s; s << n; s.str(); This class corrects this shortcoming, allowing something like this: string result = (formatter() << "blah " << n << x << " blah").str();

Actually, due to the ref qualified versions below, you can get away with this

string result = formatter() << "blah " << n << x << " blah";

Definition at line 39 of file formatter.hpp.

Constructor & Destructor Documentation

◆ formatter()

formatter::formatter ( )
inline

Definition at line 42 of file formatter.hpp.

Member Function Documentation

◆ operator std::string()

formatter::operator std::string ( ) const &&
inline

Definition at line 67 of file formatter.hpp.

References stream_.

◆ operator<<() [1/6]

template<typename T >
formatter& formatter::operator<< ( const T &  o) &
inline

Definition at line 48 of file formatter.hpp.

References stream_.

◆ operator<<() [2/6]

template<typename T >
formatter&& formatter::operator<< ( const T &  o) &&
inline

Definition at line 55 of file formatter.hpp.

References stream_.

◆ operator<<() [3/6]

formatter& formatter::operator<< ( std::ios_base &(*)(std::ios_base &)  fn) &
inline

Definition at line 85 of file formatter.hpp.

References stream_.

◆ operator<<() [4/6]

formatter&& formatter::operator<< ( std::ios_base &(*)(std::ios_base &)  fn) &&
inline

Definition at line 91 of file formatter.hpp.

References stream_.

◆ operator<<() [5/6]

formatter& formatter::operator<< ( std::ostream &(*)(std::ostream &)  fn) &
inline

Definition at line 73 of file formatter.hpp.

References stream_.

◆ operator<<() [6/6]

formatter&& formatter::operator<< ( std::ostream &(*)(std::ostream &)  fn) &&
inline

Definition at line 79 of file formatter.hpp.

References stream_.

◆ str()

std::string formatter::str ( ) const
inline

Definition at line 61 of file formatter.hpp.

References stream_.

Member Data Documentation

◆ stream_

std::ostringstream formatter::stream_
private

Definition at line 98 of file formatter.hpp.

Referenced by operator std::string(), operator<<(), and str().


The documentation for this class was generated from the following file: