|
Boost : |
From: Shunsuke Sogame (mb2act_at_[hidden])
Date: 2006-07-06 01:47:33
Joel de Guzman wrote:
> Shunsuke Sogame wrote:
>> Joel de Guzman wrote:
>>> Jeff Garland wrote:
>>>
>>>> Don't get me wrong, I think the new range interface is a major usability
>>>> advance -- well at least for unix programmers. He actually threw me off a bit
>>>> with this example:
>>>>
>>>> std::string dst(...)
>>>> range_copy(rng|to_upper|to_lower|to_upper, dst);
>>>>
>>>> which didn't make sense (apparently it was a joke). Still, I'm pretty sure in
>>>> a code reading contest more programmers would understand this:
>>>>
>>>> dst.to_upper().to_lower().to_upper();
>>>>
>>>> as obviously ridiculous code.
>>> Me, I prefer the immutable and functional approach:
>>>
>>> to_upper(to_lower(to_upper(rng)))
>>>
>>> Yeah, for the record, I never liked the use of the |. With the
>>> plain functional syntax, the joke is very clear.
>> How about the following with plain syntax? :-)
>>
>> some_algorithm(
>> file_range<boost::uint8_t>(name) | // file_iterator range
>> utf8_decoded | // u8_to_u32_iterator range
>> transformed(::newline_cvter()) | // transform_iterator range
>> tab_expanded(::tabsize<>::value) | // my buggy iterator
>> to_upper |
>> memoized // multi_pass iterator range
>> );
>
> Hmmm... lemme see... I'm not sure if I understand your code
> precisely, but, maybe something like:
>
> pipeline<
> utf8_decoded
> , transformed<::newline_cvter>
> , tab_expanded<::tabsize<>::value>
> , to_upper
> , memoized>
> f;
>
> file_range<boost::uint8_t> rng(name);
> some_algorithm(transform(rng, f));
That's not so complicated.
(In fact, it is the actual code snippets.)
It is the same as the following:
some_algorithm(
make_memoize_iterator_range(
make_to_upper_iterator_range(
make_tab_expand_iterator_range(
make_transform_iterator_range(
make_u8_to_u32_iterator_range(
file_range<>(name)
),
::newline_cvter()
),
::tabsize<>::value
)
)
)
);
For example, 'make_transform_iterator_range' returns
the pair of 'boost::transform_iterator'.
You mean the type re-construction for optimization?
If it is possible, it must be exciting!
Anyway, the Range proposal seems to provide the plain syntax together.
Users have the choice.
-- Shunsuke Sogame
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk