TooN Algorithm Library - tag
0.2
|
Macros | |
#define | Printf(A,...) vPrintf(A, (tag::Fmt,## __VA_ARGS__)) |
#define | fPrintf(A, B,...) vfPrintf(A,B, (tag::Fmt,## __VA_ARGS__)) |
#define | sPrintf(A,...) vsPrintf(A, (tag::Fmt,## __VA_ARGS__)) |
Functions | |
template<class A , class B , class C , class D > | |
void | tag::vfPrintf (std::basic_ostream< A, B > &o, const std::string fmt, const T_list< C, D > &l) |
template<class C , class D > | |
void | tag::vPrintf (const std::string fmt, const T_list< C, D > &l) |
template<class C , class D > | |
std::string | tag::vsPrintf (const std::string &fmt, const T_list< C, D > &l) |
Variables | |
static const T_ListEnd | tag::Fmt =TupleHead |
This group provides a reimplementation of the C standard library printf family of functions in a typesafe manner, using the tag::T_list tuple type.
#define fPrintf | ( | A, | |
B, | |||
... | |||
) | vfPrintf(A,B, (tag::Fmt,## __VA_ARGS__)) |
This is the equivalent to the C-style fprintf: it provides a variadic interface and prints to give ostream. See vfPrintf for details.
A | the ostream to write to |
B | the format string |
... | the arguments |
#define Printf | ( | A, | |
... | |||
) | vPrintf(A, (tag::Fmt,## __VA_ARGS__)) |
This is the equivalent to the C-style printf: it provides a variadic interface and prints to cout. See vfPrintf for details.
A | the format string |
... | the arguments |
#define sPrintf | ( | A, | |
... | |||
) | vsPrintf(A, (tag::Fmt,## __VA_ARGS__)) |
This is the equivalent to the C-style sprintf: it provides a variadic interface returns the string. See vfPrintf for details.
A | the format string |
... | the arguments |
void tag::vfPrintf | ( | std::basic_ostream< A, B > & | o, |
const std::string | fmt, | ||
const T_list< C, D > & | l | ||
) |
This function provides the mose generic implementation, where a typelist and an ostream can be provided.
o | ostream to print to |
fmt | format string |
l | typelist of arguments |
The format specifiers work much like the standard printf ones, but with some notable differences. The format is:
Flags contains zero or more of:
# | Alternate form: Include trailing zeros for float, use 0x or 0 prefix for hex and octal ints |
0 | Zero pad everything, including (oddly) strings. |
' ' | Space. Does nothing, I haven't figured out how to do this one. |
- | Left justify. Overrides 0 |
+ | Always show sign for numbers |
The width is optional and must start with a non-zero digit. It seems to work even with overloaded operator<<
This can mean one of two things:
This is a single alphabetic character. This is the largets departure from the C style printf. This flag affects the "type" of the datum being formatted. Type safety still applies. Uppercase and lowercase conversions behave in exactly the same way, except uppercase ones cause uppercased output (where applicable). If a float looks like 1E6 intead of 1e6
x | Make ints come out in hexadecimal |
o | Make ints come out in octal |
f | Make floats come out as fixed |
g | Make floats come out in the general format |
e | Make floats come out in exponential (scientific) format |
b | Make bools coma out as "true" or "false" |
s | Treat next output as string: precision means max width. |
k | Kill (ignore) the data |
Unlike C, the C++ sytle printf can output values of any type for which operator<< is defined. Further, printf itself will not cause any undefined behaviour. Access beyond the end of the vargs list produces <Missing value>
in the output, instead of a segfault. A malformed format string causes <Malformed format>
to appear in the output followed by the remaining string including the malformed part. No further conversions are attempted after a malformed format.
Note: length modifiers are not supported.
See also other members of the Printf family:
References tag::print.
Referenced by tag::vPrintf(), and tag::vsPrintf().
void tag::vPrintf | ( | const std::string | fmt, |
const T_list< C, D > & | l | ||
) |
This prints to cout. See vfPrintf for details.
fmt | format string |
l | typelist of arguments |
References tag::vfPrintf().
std::string tag::vsPrintf | ( | const std::string & | fmt, |
const T_list< C, D > & | l | ||
) |
This prints to a string. See vfPrintf for details.
fmt | format string |
l | typelist of arguments |
References tag::vfPrintf().