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

Functions

template<typename Str , typename... Args>
std::string format (const Str &fmt, 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 used by C++20 std::format 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.

Function Documentation

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

Definition at line 121 of file strutil.h.