Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::ptr_vector::sort with c++11 lambdas
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2011-11-11 08:45:53


Den 11-11-2011 13:52, qplace skrev:
> I am trying to figure out if c++11 lambda can be used instead of the straight
> preducates.
>
> say, I have
> class A : public boost::noncopyable
> {
> ...
> }
>
> and
>
> boost::ptr_vector<A> lst;
>
> I'd like to use something like:
>
> lst.sort([&] (const A& v1, const A& v2) ->bool {return v1< v2;});
>
> Tutorial for ptr_vector says that predicates are wrapped in indirect_fun. May
> be this is the reason the sort fails to compile?

Could be. What does the error message say?

I'm thinking that the lambda function is not properly converted to a
pointer to a function.

An escape route may be to use std::sort() with a lambda taking two void*.

-Thorsten


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