I am trying to call lower_bound on transformed iterators of a vector<unique_ptr>>. Similar questions had been asked previously on SO. This one is slightly more complex that solutions to other problems are not readily applicable.
The problem is the same. The std implementation calls unique_ptr operator= when it assigns __first to __middle during the search. In this example, a list of transformed objects (int->double) are searched to locate the element equal to or greater than the input (double).
int main ()
{
vector<unique_ptr<int>>v {
std::make_unique<int>(0),
std::make_unique<int>(1),
std::make_unique<int>(2),
std::make_unique<int>(3),
std::make_unique<int>(4),
};
auto transFunc = [](const unique_ptr<int>& m) -> double {
return (*m) * 2.;
};
auto first = boost::make_transform_iterator(begin(v), transFunc);
auto last = boost::make_transform_iterator(end(v), transFunc);
auto i = lower_bound(first, last, 5.);
return 0;
}
I also tried using move_iterator's.
auto transFunc = [](unique_ptr<int>&& m) -> double {
return (*m) * 2.;
};
auto first = boost::make_transform_iterator(
make_move_iterator(begin(v)), transFunc);
auto last = boost::make_transform_iterator(
make_move_iterator(end(v)), transFunc);
It seems like boost didn't carry the right-valueness forward in the transformed iterators.
The code used to work in VS2013 but doesn't work in VS2015 or GNU.
Aucun commentaire:
Enregistrer un commentaire