Subject: Re: [boost] review request: addition to type_traits library of is_less_comparable<T, U> and others
From: Zachary Turner (divisortheory_at_[hidden])
Date: 2009-12-06 13:08:49
On Sun, Dec 6, 2009 at 11:19 AM, Patrick Horgan <phorgan1_at_[hidden]> wrote:
> Frédéric Bron wrote:
>> I a in favor of implementing type traits to detect comparison and
>> arithmetic operators. What for logical and bitwise operations?
> I have no particular use cases in mind, but my prediction is that if you
> only do the comparison and arithmetic operators, later someone will be
> saying, "Why didn't he do that logical and bitwise operators? Now I have to
> implement them myself!"
A use case I came up with recently that might warrant the need for virtually
all operators was implementing a scripting system with a limited number of
types. script variables were represented by a boost::variant<> templatized
on the set of all possible c++ types that mapped to the script types. Some
of these types had various operations possible between them (int+float,
string+string, etc) and some combinations didn't (string+int, double-string,
etc). I wanted to use the static_visitor pattern and have it throw an
exception if the operation did not exist between the two. So I wrote
functors such as add_variables() and divide_variables() that used
enable_if<> and disable_if<> on the operator() to select the appropriate
overload for the visitor to invoke. Since this is a scripting language,
there were many more operations possible, not just arithmetic.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk