|
Boost Users : |
Subject: Re: [Boost-users] boost range question
From: Neil Groves (neil_at_[hidden])
Date: 2012-07-12 05:20:03
On 12/07/12 09:15, tolik levchik wrote:
> Why min_element give me errors
> without BOOST_RANGE_ENABLE_CONCEPT_ASSERT defined 0? Is it uses only
> for makeerror messages more readable? Is it safe to define it to 0?
Firstly, it is definitely safe to consistently define
BOOST_RANGE_ENABLE_CONCEPT_ASSERT as 0. This will disable concept
checking within Boost.Range. The intent of the concept checking is
two-fold. It will detect usage errors at compile-time that in some cases
may become run-time errors without the checks. It also provides better
error messages close to the location of the error.
> #include <vector>
> //#define BOOST_RANGE_ENABLE_CONCEPT_ASSERT 0
> #include <boost/range.hpp>
> #include <boost/range/adaptors.hpp>
> #include <boost/range/algorithm.hpp>
> #include <boost/range/numeric.hpp>
> #include <boost/bind.hpp>
>
> struct foo{
> int x;
> };
>
> int main()
> {
> using namespace boost::adaptors; using boost::bind;
>
> std::vector<foo> vec;
> auto rng = vec | transformed(bind(&foo::x, _1));
> boost::accumulate(rng, 0); // ok
> boost::min_element(rng); // error
> }
I suspect that the underlying transform_iterator alters the return type
of the dereference operator that technically demotes the iterator category.
If this is the case then this is a defect in the Boost.Range library
that I shall need to address. I should have used the Boost iterator
traversal categories.
I shall look into this. Thank you for the report.
Regards,
Neil Groves
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