![]() |
Blitz Support : |
From: Derrick Bass (derrick_at_[hidden])
Date: 2004-02-03 22:39:08
STL algorithms actually use templates, less<T> and equal_to<T> to do
comparisons. (Those templates default to using < and ==, as you saw
when tracing your error). See, e.g.
<http://www.sgi.com/tech/stl/less.html>. So you can override those
templates with your own functions for Blitz data types. E.g.
If you want a subtler approach, the constructors for STL containers can
take a functor as an argument. The functor should be to a routine that
does the comparison. See <http://www.sgi.com/tech/stl/Map.html> for
sample code.
Derrick Bass
On Feb 3, 2004, at 6:38 PM, William Gallafent wrote:
> On Wednesday 04 February 2004 02:02, William Gallafent wrote:
>
>> I'm probably being stupid (it's getting late)
>
> I was being.
>
>> but I can't see why the following (and anything similar,
>> e.g. using a __gnu_cxx::hash_map, in which case it's
>> operator== which is in question, rather than operator< as
>> here) shouldn't compile:
>
> Immediately after sending that message, I realise that of
> course there are different ways in which a vector type could
> be considered to be "less than" or "equal to" an other one.
>
> So, I should rephrase my question!
>
> How do I go about writing an expression which will fit into
> the Blitz++ machinery which will allow me to write e.g. an
> elementwise operator==, or a lexicographical comparison
> function, or a modulous comparison function, etc.
>
> In other words, how can I get a generic operator which
> overrides that in the blitz headers for vector types and is
> able to return a bool to satisfy the comparable requirements
> of the STL?
>
> Apologies if this has been discussed before - I'm coming
> back to Blitz after a while away.
>
> --
> Bill Gallafent.
>
>
> _______________________________________________
> Blitz-support mailing list
> Blitz-support_at_[hidden]
> http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support