Opened 7 years ago

Last modified 7 years ago

#12087 new Bugs

transform_iterator is not assignable in VS2015

Reported by: bswerts@… Owned by: jeffrey.hellrung
Milestone: To Be Determined Component: iterator
Version: Boost 1.60.0 Severity: Problem
Keywords: Cc:

Description

The following code does not compile in Visual Studio 2015 because the assignment operator of transform_iterator seems to be deleted:

#include "boost/iterator/transform_iterator.hpp" #include <vector> int main() {

auto v = std::vector<int>{}; auto it = boost::make_transform_iterator(std::begin(v), [](int) { return 1; });

it = it;

return 0;

}

The line 'it = it' is the culprit, giving error C2280: 'boost::iterators::transform_iterator<main::<lambda_245a5d22fdccfa4a35ac6bb4a4dc8307>,std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>,boost::iterators::use_default,boost::iterators::use_default> &boost::iterators::transform_iterator<main::<lambda_245a5d22fdccfa4a35ac6bb4a4dc8307>,std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>,boost::iterators::use_default,boost::iterators::use_default>::operator =(const boost::iterators::transform_iterator<main::<lambda_245a5d22fdccfa4a35ac6bb4a4dc8307>,std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>,boost::iterators::use_default,boost::iterators::use_default> &)': attempting to reference a deleted function boost\iterator\transform_iterator.hpp(127): note: compiler has generated 'boost::iterators::transform_iterator<main::<lambda_245a5d22fdccfa4a35ac6bb4a4dc8307>,std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>,boost::iterators::use_default,boost::iterators::use_default>::operator =' here

I assume iterators need to be assignable. Furthermore I see no reason why the compiler wouldn't generate the standard member functions. Everything compiles OK in VS2013.

Thanks in advance for having a look. Regards, Ben

Change History (2)

comment:1 by Steven Watanabe, 7 years ago

The problem is that assignment of transform_iterator requires the function object to be assignable.

"The closure type associated with a lambda-expression has a deleted (8.4.3) default constructor and a deleted copy assignment operator." [expr.prim.lambda]

comment:2 by bswerts@…, 7 years ago

Thanks for the quick and precise answer, Steven. VS2015 is indeed adhering better to the standard. I know now how to fix my code. This issue can be closed. Sorry for the noise.

Note: See TracTickets for help on using tickets.