Afficher un message
Vieux 16/10/2007, 05h40   #3
red floyd
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: using std::find on a std::vector<double>

Kai-Uwe Bux wrote:
> Anonymous wrote:
>
>> I ahve a vector of doubles taht I need to extract values from. I was
>> just about to use the STL find() algo, but I have a couple of questions:
>>
>> first: can you specify the tolerance threshold to match on doubles?
>> second: if yes, how may this be done (i.e. how many one specify the
>> tolerance threshold for comparing doubles?)

>
> Note that find() has two signatures: one that takes a value to be found and
> one that takes a unary predicate instead. Use the later and provide a
> functor:


Isn't the second form find_if(), not find()?
>
> class is_approximately {
>
> double x;
>
> public:
>
> is_approximately ( double what )
> : x ( what )
> {}
>
> bool operator() ( double y ) const {
> // return true if y is near x.
> }
>
> };
>
> Now you can do:
>
> find( whatever.begin(), whatever.end(), is_approximately( 0.5 ) );
>
>
>
> Best
>
> Kai-Uwe Bux

  Réponse avec citation
 
Page generated in 0,04680 seconds with 9 queries