Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-09-21 05:01:41


Reece Dunn wrote:

>> > std::cout << io::object
>> > (
>> > std::make_pair( 'a', 5 ),
>> > "{ " + fmt::pair()/" == " + " }"
>> > ) << '\n'; // output: { a == 5 }
>>
>>Great. I wonder what others think? Personally, I really like the /
>>operator.
>>Probably that's because I've borrowed the idea from one parser generator
>>which allows to write:
>>
>> (literal / "," )
>>
>>to mean a list of literals separated by ",".
>
> Sure. Another alternative would be:
>
> fmt::pair()[ " = " ]
>
> but this may be confusing WRT the standard behaviour of the [] operator.

Yes, a bit confusing.

>>The opening and closing braces look less clear for me now. Maybe, we can
>>use
>>
>> fmt::pair("{", "}")/" == "
>
> The problem with this is deducing that the parameters passed to fmt::pair
> or others are format objects (for formatting first and second data
> members) or delimiter strings or other arguments (e.g. DelimiterType or
> array length). This could possibly be done using MPL, but would further
> complicate the implementation.

I agree, this would cause too much difficulties.

>> fmt::braces("{", "}") + fmt::pair()/" == "
>>
>>But I'm really really not sure.
>
> Suggestions are always welcome.
>
> fmt::braces is openclose_formatter in the review implementation
> (wrapper_decorators in the version I am currently working on). The problem
> with defining operator + for <open_close> + <open_close_separator> value
> holders is: how do you inherit values, for example:
>
> fmt::braces( "<< ", " >>" ) + fmt::pair( "{ ", " }" )/" == "
>
> is this: << a == b >>
> or: { a == b }

We need to see the full expression ;-) If that's

   cout << io::object(v,
        fmt::braces( "<< ", " >>" ) + fmt::pair( "{ ", " }" )/" == ")

then clearly "{ a == b }".

> This would be "<< a == b >>" in this instance, because fmt::pair will set
> the values and fmt::brace will cause them to be overrided.

Why? You can defined operator+ any way you like, and the second operand can
override values from the first.

> This is similar
> to this situation:
>
> "<< " + fmt::pair().decorate( "{ ", " }" )/" == " + " >>"

This case is harder. The only reasonable behaviour is "<< a == b >>". But
then, why would anyone write this? And if you use some formatter object,
writing

  "<< + my_fmt + ">>"

would have the reasonable effect of overriding separators.

I recalled one more thing. In docs, you talk about FormatObject template
parameter. But there is a class named "openclose_formatter_t". Note
"formatter", not format_object. At one moment, I started to wonder what's
the difference between "format object" and "formatter". I suggest that you
use only one term everywhere.

And also, template parameter for arrayfmt_t is called FormatObject. I think
it would be clearer to call it "NestedFormatObject" or "NestedFormatter".

- Volodya


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk