[Boost-bugs] [Boost C++ Libraries] #1842: boost::sub_rage::front error

Subject: [Boost-bugs] [Boost C++ Libraries] #1842: boost::sub_rage::front error
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-04-18 20:35:33


#1842: boost::sub_rage::front error
--------------------------------------------+-------------------------------
 Reporter: ka3a4ok <bismuth_at_[hidden]> | Owner: nesotto
     Type: Bugs | Status: new
Milestone: Boost 1.36.0 | Component: range
  Version: Boost 1.35.0 | Severity: Problem
 Keywords: sub_range front back reference |
--------------------------------------------+-------------------------------
 I think, there is an error in ''sub_range::front const'' method. It use
 ''const value_type&'' instead of ''const reference''.

 For example, here is a well compiled code, that fails on last assert, but
 should not:

 {{{
 #include <list>

 #include <boost/assign.hpp>
 #include <boost/assert.hpp>
 #include <boost/range/sub_range.hpp>
 #include <boost/iterator/transform_iterator.hpp>

 //------------------------------------------------------------------------------
 struct Trans:
         public std::unary_function<int, int>
 {
         int operator()(const int& a)const
         {
                 return a*2;
         }
 };
 //------------------------------------------------------------------------------
 int main(int argc, char* argv[])
 {
         using namespace boost::assign;

         const std::list<int> a=list_of(10);
         const std::list<int> b=list_of(20);

         BOOST_ASSERT(!a.empty() && !b.empty());
         BOOST_ASSERT(a.front()!=b.front());
         BOOST_ASSERT(Trans()(a.front())!=Trans()(b.front()));

         typedef
                 boost::transform_iterator<Trans,
 std::list<int>::const_iterator>
                 my_iter_t;

         typedef
                 std::pair
                 < my_iter_t,
                         my_iter_t
>
                 my_pair_t;

         const boost::sub_range<my_pair_t> ar
         ( boost::make_transform_iterator(boost::const_begin(a),
 Trans()),
                 boost::make_transform_iterator(boost::const_end(a),
 Trans())
         );

         const boost::sub_range<my_pair_t> br
         ( boost::make_transform_iterator(boost::const_begin(b),
 Trans()),
                 boost::make_transform_iterator(boost::const_end(b),
 Trans())
         );

         BOOST_ASSERT(ar.front()!=br.front()); // <---- fail

         return 0;
 }
 }}}

--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1842>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.


This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:57 UTC