Using OvenToBoost 'taken'.
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
Hi Robert,
2013/1/7 Robert Jones
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
#include #include #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 ); }
`filtered` adaptor (boost::filter_iterator) is over call predicate for skip element. This is boost::filter_iterator's specification. see: http://www.boost.org/doc/libs/1_52_0/libs/iterator/doc/filter_iterator.html Thanks, Akira
On Mon, Jan 7, 2013 at 11:56 AM, Akira Takahashi
Hi Robert,
2013/1/7 Robert Jones
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
#include #include #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 ); }
`filtered` adaptor (boost::filter_iterator) is over call predicate for skip element. This is boost::filter_iterator's specification. see: http://www.boost.org/doc/libs/1_52_0/libs/iterator/doc/filter_iterator.html
So it does... ok thx for that!
- Rob.
participants (2)
-
Akira Takahashi
-
Robert Jones