HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Strutil::fmt Namespace Reference

Functions

template<typename... Args>
std::string format (const char *fmt, const Args &...args)
 

Detailed Description

format() constructs formatted strings. Note that this is in transition!

Strutil::old::format() uses printf conventions and matches format() used in OIIO 1.x. It is equivalent to Strutil::sprintf().

std::string s = Strutil::old::sprintf ("blah %d %g", (int)foo, (float)bar);

Strutil::fmt::format() uses "Python" conventions, in the style of string formatting being planned for C++20 and implemented today in the {fmt} package (https://github.com/fmtlib/fmt). For example:

std::string s = Strutil::format ("blah {} {}", (int)foo, (float)bar);

Straight-up Strutil::format is today aliased to old::format for the sake of back-compatibility, but will someday be switched to fmt::format.

Recommended strategy for users:

  • If you want printf conventions, switch to Strutil::sprintf().
  • If you want to use the python conventions prior to the big switch, use Strutil::fmt::format() explicitly (but see the caveat below).
  • Use of unspecified Strutil::format() is, for back compatibility, currently equivalent to sprintf, but beware that some point it will switch to the future-standard formatting rules.

Caveat: BEWARE using fmt::format on floating point values if there is any chance you could be running with a global non-C locale, because fmt does not yet correctly produce locale-independent output! We will upgrade as soon as they get that fixed.

Function Documentation

template<typename... Args>
std::string Strutil::fmt::format ( const char *  fmt,
const Args &...  args 
)
inline

Definition at line 182 of file strutil.h.