[Boost-bugs] [Boost C++ Libraries] #13094: boost::adaptors::transform fails to preserve bidirectional behavior of range

Subject: [Boost-bugs] [Boost C++ Libraries] #13094: boost::adaptors::transform fails to preserve bidirectional behavior of range
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-06-23 23:58:32


#13094: boost::adaptors::transform fails to preserve bidirectional behavior of
range
--------------------------------------+------------------------
 Reporter: Jake Cobb <jake.cobb@…> | Owner: neilgroves
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: range
  Version: Boost 1.64.0 | Severity: Problem
 Keywords: range adaptors transform |
--------------------------------------+------------------------
 The documentation of `boost::adaptors::transform` states the returned
 range type is the same as the argument range type. However, when wrapping
 `std::vector`, the iterators returned are not bidirectional as the
 `std::vector` iterators are. `std::advance` with a negative integer
 leaves them unchanged and `std::prev` fails to compile with them. They do
 work as expected with `operator-`.

 {{{#!c++
 #include <iostream>
 #include <vector>
 #include <iterator>
 #include <boost/range/adaptor/transformed.hpp>

 int main() {
     std::vector<int> data{1,2,3};
     auto transformed = boost::adaptors::transform(data, [](int x) { return
 x; });
     auto iter = transformed.begin();
     // auto iter = data.begin(); // swap to compare
     std::cout << "begin: " << *iter << std::endl; // prints 1 both cases
     std::advance(iter, 1);
     std::cout << "begin+1: " << *iter << std::endl; // prints 2 both cases
     std::advance(iter, -1);
     // prints 2 for boost adaptor, 1 for std::vector
     std::cout << "begin+1-1: " << *iter << std::endl;
     std::cout << "begin+1-1 (v2): " << *(iter - 1) << std::endl; // prints
 1 both cases
     // std::prev(iter); // boost fails bidirectional test, won't compile
     return 0;
 }
 }}}

--
Ticket URL: <https://svn.boost.org/trac10/boost/ticket/13094>
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-06-24 00:02:01 UTC