OK, I am convinced.
Anybody else have any comments? Any good reason why we shouldn't fold the tfm
header into OIIO and use it to replace the current implementation of
Strutil::format and ustring::format?
Again, Chris, this is really elegant, awesome work. Are you comfortable with
my telling other people about it (not on this mail list)?
-- lg
On Jul 28, 2011, at 3:57 PM, Chris Foster wrote:
> On Fri, Jul 29, 2011 at 3:42 AM, Larry Gritz <[email protected]> wrote:
>> Upon reflection, I think I'm totally comfortable for the no-variadic-template
>> problem to be solved by just explicitly defining the templates for the 1-arg,
>> 2-arg, ..., n-arg cases? I bet n == 10, as you have it, is plenty for any
>> use within OIIO.
>
> Right.
>
>> If we ever go over that, it would only be slightly, and easy to amend by
>> hand
>> without even needing to worry about running Python scripts to auto-generate.
>
> I'm confused by why this is really a problem. The python script is
> super easy to run, (just download cog.py and run "cog.py -r
> tinyformat.h") and since the generated code is included with the source,
> that only needs to be done by *one single developer*, a single time when
> they go over the n==10 limit. They commit the result of re-running the
> generator, and that is that.
>
> If you need a very large number of format specifiers in a string it's
> also possible to split them up over a few calls, as follows:
>
> std::ostringstream msg;
> tfm::format(msg, "blah blah %this %that ...", ...);
> tfm::format(msg, "next thing %this %that ...", ...);
> tfm::format(msg, "final bit %this %that ...", ...);
> // now do something with msg.str();
>
> this will also be a handy trick if some of the formatting needs to be
> conditional.
>
>> The biggest trick is just defining the macro that correctly detects which
>> compilers support variadic templates.
>
> Even g++ won't use variadic templates by default, you need to be
> compiling in --std=c++0x mode. tinyformat already has a macro near the
> top that autodetects whether g++ is running in the correct mode, and
> uses the variadic templates support if possible.
>
> ~Chris
--
Larry Gritz
[email protected]
_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org