Re: New compose and format API



On 8/14/07, Daniel Elstner <daniel kitta googlemail com> wrote:
> Interestingly, boost introduces a group() function to avoid the
> ambiguity that arises when I/O manipulators are used.  group() is
> actually very similar to ustring::format(), except that it can be
> omitted if no grouping is necessary.  So it seems there are now three
> API variations to choose from:
>
>   // 1) status quo
>   s1 = ustring::compose("%1 is lower than %2.",
>                         ustring::format(12),
>                         ustring::format(std::setprecision(1), 34.5))
>
>   // 2) boost-ish
>   s2 = ustring::format("%1 is lower than %2.")
>                        % 12 % group(std::setprecision(1), 34.5)
>
>   // 3) half-breed
>   s3 = ustring::format("%1 is lower than %2.",
>                        12, group(std::setprecision(1), 34.5))
>
> Hm, now that I think of it I actually like options 2) and 3) better than
> my original proposal.  Implementing 3) should be fairly straightforward
> but 2) might require some additional bloat.  I'll have to give it a try
> to be sure though.
>
> Have your say: Which would you prefer?

I already gave my opinion to Daniel on IRC, but I thought I'd post
here as well in case others want to weigh in.  My preference is
currently for option 3.  I think the desire to make the interface
similar to boost is laudable, but I personally find the 'function
argument' syntax much more readable than the operator% overloading.
But I do agree that for the common case of passing a plain string or
number (i.e. without any manipulators), it would be nice to drop the
extra ustring::format() call.

-- 
jonner



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