Boost logo

Boost Users :

Subject: [Boost-users] Using OvenToBoost 'taken'.
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2013-01-07 06:19:56


Hi Folks

This question is about using the OvenToBoost port, not currently part of
Boost, but likely to be soon, I understand.

The code below evaluates the predicate for the first and second elements of
the array. The evaluation of the
second element seems to me to be unnecessary and wrong, since the 'taken'
adaptor knows the range is
ended after the first element is taken.

Thoughts?

Thx, Rob.

#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/taken.hpp>
#include <boost/range/algorithm/for_each.hpp>
#include <iostream>

bool predicate( int i )
{
    std::cout << "predicate(" << i << ")" << std::endl;
    return true;
}

void doNothing( int ) { }

int main( )
{
    int array[ ] = { 0, 1, 2, 3, 4, 5 };

    for_each( array | boost::adaptors::filtered( predicate ) |
boost::adaptors::taken( 1 ), doNothing );
}



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net