lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Aug 19, 2013 at 12:48 AM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> On Mon, Aug 19, 2013 at 9:37 AM, Coda Highland <chighland@gmail.com> wrote:
>> C++'s << is nice, but doesn't address reordering parameters for localization.
>
> <c++>
>
> printF(cout,L("Hello {0}, ({1})\n"),Strings() << name << age);
>
> (exercise for the reader. Strings is a type with a templated <<
> operator which uses ostream<< to make up a list of appropriate
> strings, printF then should be pretty easy.  L() just matches a string
> in a suitable localization file)
>
> Or even (with implicit L() and a suitable wrapper type PrintF)
>
> PrintF(cout, "Hello {0}, ({1})\n") << name << age;
>
> </c++>
>

Well sure, I mean, Qt does it more or less that way -- tr("Hello %0,
(%1)\n").arg(name).arg(age) not only provides the format string but
also hooks the localization system. But when you said "C++" I assumed
you meant standard C++, not something you could build on top of it.

But if we're taking C++11 into account, you could write a full-blown
type-aware printf replacement with printf-styled syntax thanks to
variadic templates.

/s/ Adam