Boost logo

Boost Users :

Subject: Re: [Boost-users] [lambda]How to use the member of placeholder in std algorithm?
From: Roman Perepelitsa (roman.perepelitsa_at_[hidden])
Date: 2009-02-27 03:08:17


2009/2/27 Ç®ÏþÃ÷ <kyleqian_at_[hidden]>

> I have a struct:
> struct Coordinate {
> double x, y, z;
> };
> There is no any operator definition for it.
>
> I want to sort a array of this struct with 3 elements by comparing the Z
> value, so:
> Coordinate coords[3];
> .......
> std::sort(coords, coords+3, _1 < _2);
> What should I write to replace "_1 < _2" here? How can I reference the Z
> member of _1 and _2?
> I hope I can sort this array without defining any new function.
>
>

bind(&Coordinate::z, _1) < bind(&Coordinate::z, _2)

Roman Perepelitsa.



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