Boost logo

Boost :

From: shunsuke (pstade.mb_at_[hidden])
Date: 2008-04-06 14:55:02


vicente.botet wrote:
> Could you tell me if the following is equivalent to what appears in the
> quick start. I'm not very confortable with
> foreach.
>
> </code>
> template<class Range, class Predicate>
> struct mono_make_filtered
> {
> typedef
> boost::filter_iterator<
> typename boost::remove_cv<Predicate>::type,
> typename boost::range_result_iterator<Range>::type
> >
> iter_t;
>
> typedef
> boost::iterator_range<iter_t>
> result_type;
>
> result_type operator()(Range &rng, Predicate &pred) const
> {
> return result_type(
> iter_t(pred, boost::begin(rng), boost::end(rng)),
> iter_t(pred, boost::end(rng), boost::end(rng))
> );
> }
> };
>
> bool is_not_X(char ch) { return ch != 'X'; }
> bool is_not_Y(char ch) { return ch != 'Y'; }
> bool is_lower(char ch) { return std::islower(ch, std::locale()); }
>
> void quick_start_make_filtered()
> {
> std::string src("abXcYdXefXgYhY");
>
> mono_make_filtered::result_type lowers = make_filtered(src, &is_lower);
>
> foreach (char ch, lowers) {
> std::cout << ch;
> }
>
> foreach (char ch, make_filtered(make_filtered(src, &is_not_X),
> &is_not_Y)) {
> std::cout << ch;
> }
> }
> </code>
>
> If this is the case could you show which is really the advantage to use Egg.
> I 'm sure there are a lot of, but I think the example do not show them.

No, it's not equivalent.
mono_make_filtered<std::string, bool(*)(char)>::result_type lowers = ...
is equivalent, though.
A problem of this form is that
users of `make_filtered` have to remember the usage of `mono_make_filtered`
instead of the standardized metafunction `result_of`.

Regards,

-- 
Shunsuke Sogame

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