Boost logo

Boost Users :

Subject: Re: [Boost-users] [Range] Predicate type checking.
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2012-05-02 14:04:52


> I'm pretty sure I'm have a 'Doh!' moment here, but why does this compile?
>
> Surely the last line of main is gibberish; the value type of m is pair,
> not S, so int_from_S
> is not a valid function?
>
> #include <boost/range.hpp>
> #include <boost/range/adaptor/transformed.hpp>
> #include <map>
>
> struct S
> {
> S( ) { }
> int i;
> };
>
> int int_from_S( S s ) { return s.i; }
>
> int main( )
> {
> std::map<unsigned, S> m;
> m[0]=S();
> m | boost::adaptors::transformed(int_from_S);
> }
>
> Thx,
>
> - Rob.

Off the top of my head, I would guess that the function(s) that need the value
type of the range to be convertible to the argument type of the function don't
get instantiated until you actually try to do something with the transformed
range.

Try

std::vector<int> v;
boost::push_back(v, m | boost::adaptors::transformed(int_from_S));

and you should see the compiler errors.

Regards,
Nate
                                               


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net