Opened 15 years ago
Closed 10 years ago
#1821 closed Bugs (fixed)
lambda and transform_iterator
Reported by: | Owned by: | Dave Abrahams | |
---|---|---|---|
Milestone: | Boost 1.36.0 | Component: | iterator |
Version: | Boost 1.35.0 | Severity: | Problem |
Keywords: | Cc: |
Description
This code doesn't compile.
#include <utility> #include <list> #include <boost\iterator\transform_iterator.hpp> #include <boost\lambda\lambda.hpp> #include <boost\lambda\bind.hpp> #include <boost\function.hpp> int main(int argc, char* argv[]) { using namespace std; using namespace boost; using namespace boost::lambda; typedef list<pair<int, double> > Tlist; make_transform_iterator ( Tlist().begin(), bind(&Tlist::value_type::first, _1) ); return 0; }
But this does:
#include <utility> #include <list> #include <boost\iterator\transform_iterator.hpp> #include <boost\lambda\lambda.hpp> #include <boost\lambda\bind.hpp> #include <boost\function.hpp> int main(int argc, char* argv[]) { using namespace std; using namespace boost; using namespace boost::lambda; typedef list<pair<int, double> > Tlist; make_transform_iterator ( Tlist().begin(), function<int(Tlist::value_type)> ( bind(&Tlist::value_type::first, _1) ) ); return 0; }
Change History (5)
comment:1 by , 15 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
follow-up: 3 comment:2 by , 10 years ago
now that we have decltype, should transform_iterator be adapated to take lambda expressions?
comment:3 by , 10 years ago
Supporting lambdas would be of great benefit. I was quite surprised to find they weren't supported.
comment:4 by , 10 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
comment:5 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Already fixed in Boost 1.47.
This ticket is a composite of
- #864: Make lambda support result<>
- #1427: transform_iterator should use boost/result_of to determine functor result type
which were fixed in Boost 1.44 and 1.47, respectively.
P.S.
This ticket is about Boost.Lambda and NOT about C++11 lambdas.
For C++11 lambdas, you should use decltype-based result_of.
Please read result_of doc (especially about BOOST_RESULT_OF_USE_DECLTYPE
macro).
Note:
See TracTickets
for help on using tickets.
The type of your bind expression does not satisfy the requirements of
transform_iterator
as described in http://boost.org/doc/libs/1_35_0/libs/iterator/doc/transform_iterator.html#transform-iterator-requirementsIn particular, the expression
result_of<UnaryFunction(iterator_traits<Iterator>::reference)>::type
is not valid. This will all get better in C++0x when we have decltype, but in the meantime, it can't be considered a bug in Boost.Iterator.