expression templates

bearophile bearophileHUGS at lycos.com
Tue Mar 29 12:47:16 PDT 2011


dsimcha:

>Can you please give an example of where <=, >, etc. are useful for representing set operations?  My naive opinion (i.e. without understanding your use case) is that using comparison operators to represent anything besides partial or total ordering is a severe abuse of operator overloading.<

recent Python versions have a built-in set type, I use them very often, so in the dlibs1 I have implemented a set struct with the same API, you see it spread here:
http://docs.python.org/library/stdtypes.html#set

Most set operations are doable both with an operator and a with method with an English name (the main difference is that the methods accept a generic iterable too beside a set, while operators require both operators to be set).

If you try to implement the issubset/isSubset, opCmp is not enough, because as you say a full opCmp can't be defined on sets, in D we can't overload <= >= among sets.

This is not terrible, because for those two operations I define only the method with English name, but this is a small limit of opCmp. In expression templates you are able to use the same solution.

Is this usage for the set API operator overloading abuse? I am not sure. I think it's acceptablre.

Bye,
bearophile


More information about the Digitalmars-d mailing list