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

Go to the source code of this file.

Description

Collection of small helpers and convenience shortcuts for diagnostics & formatting.

  • util::str() performs a failsafe to-String conversion, thereby preferring a built-in conversion operator, falling back to just a mangled type string.
  • util::join() generates an enumerating string from elements of an arbitrary sequence or iterable. Elements will be passed through our generic string conversion
See also
FormatHelper_test
frontend for boost::format, printf-style

Definition in file format-util.hpp.

#include "lib/meta/trait.hpp"
#include "lib/format-obj.hpp"
#include "lib/itertools.hpp"
#include "lib/symbol.hpp"
#include "lib/util.hpp"
#include <string>
#include <vector>
#include <sstream>
#include <utility>
#include <typeinfo>

Classes

struct  _RangeIter< CON, TOGGLE >
 
struct  _RangeIter< IT, lib::meta::enable_if< can_IterForEach< IT > > >
 
struct  SeqContainer< CON, ELMS >
 
struct  SeqContainer< vector< X >, ELMS... >
 

Functions

template<class CON , typename... ELMS>
CON collectStr (ELMS const &...elms)
 convert a sequence of elements to string More...
 
template<class CON >
void do_stringify (CON &)
 
template<class CON , typename X , typename... ELMS>
void do_stringify (CON &container, X const &elm, ELMS const &...args)
 
template<class CON >
string join (CON &&coll, string const &delim=", ")
 enumerate a collection's contents, separated by delimiter. More...
 
template<class X >
string join (std::initializer_list< X > const &&ili, string const &delim=", ")
 
template<typename... ARGS>
string joinArgList (ARGS const &...args)
 shortcut: List in parentheses, separated by comma, using temporary vector
 
template<typename... ARGS>
string joinDash (ARGS const &...args)
 shortcut: join directly with dashes
 
template<typename... ARGS>
string joinDot (ARGS const &...args)
 shortcut: join directly with dashes
 
template<typename... ELMS>
vector< string > stringify (ELMS const &...elms)
 standard setup: convert to string into a vector
 
template<class IT >
auto stringify (IT &&src)
 convert to string as transforming step in a pipeline More...
 

Namespaces

Function Documentation

◆ collectStr()

CON util::collectStr ( ELMS const &...  elms)
inline

convert a sequence of elements to string

Parameters
elmssequence of arbitrary elements
Template Parameters
CONthe container type to collect the results
Returns
a collection of type CON, initialised by the string representation of the given elements

Definition at line 120 of file format-util.hpp.

References util::collectStr().

Referenced by util::collectStr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stringify()

auto util::stringify ( IT &&  src)
inline

convert to string as transforming step in a pipeline

Parameters
srca "Lumiera Forward Iterator" with arbitrary result type
Returns
a "Lumiera Forward Iterator" with string elements
See also
FormatHelper_test::checkStringify()

Definition at line 142 of file format-util.hpp.

References util::stringify(), and lib::transformIterator().

+ Here is the call graph for this function:

◆ join()

string util::join ( CON &&  coll,
string const &  delim = ", " 
)
inline

enumerate a collection's contents, separated by delimiter.

Parameters
collsomething that is standard-iterable
Returns
all contents converted to string and joined into a single string, with separators interspersed.
Remarks
based ostringstream; additionally, we use our failsafe string conversion, which in turn invokes custom string conversion, or lexical_cast as appropriate.
alternatively, the boost::join library function could be used, which works on arbitrary sequences, which incurs some additional weight (both in terms of header include and debug code size). And failures on template substitution tend to be hard to understand, since this generic sequence concept is just so danm absolutely generic (In fact that was the reason why I gave up and just rolled our own join utility)

Definition at line 200 of file format-util.hpp.

Referenced by FormatHelper_test::checkStringJoin().

+ Here is the caller graph for this function: