|
Boost : |
From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2003-03-27 15:00:25
On Thu, 27 Mar 2003 14:01:12 -0500, scleary_at_[hidden] wrote:
>> -----Original Message-----
>> From: Jan Langer [mailto:jan_at_[hidden]]
>
>Just one other thing - instead of:
> enum result { minus, zero, plus };
>I would do:
> enum result { minus = -1, zero, plus };
>just for the sake of code readability and ease of understanding. It doesn't
>change the logic at all.
Well, if we are really going to discuss such quibbles, I would also
change "zero" to "equiv" because that's the usual "term" used for
strict weak ordering. And I would avoid constructs like
template <typename T>
compare (T const &a, T const &b)
: v_ (compare () (a, b).v_) // <--
{}
by doing, for instance,
class compare
{
enum result { minus, equiv, plus };
result v_;
template <typename T>
static result do_compare(const T& a, const T& b) {
if (a < b) return minus;
else if (b < a) return plus;
return equiv;
}
public:
compare () : v_ (equiv) {}
template <typename T>
compare (T const &a, T const &b)
: v_ (do_compare(a, b))
{}
....
template <typename T>
compare &operator () (T const &a, T const &b)
{
if (v_ == equiv)
do_compare(a, b);
return *this;
}
....
};
But there are more important points I think; first of all this: if all
I can see "from the outside" is whether v_== minus [note: this is
'plus' in the original code] why keeping three states internally?
Genny.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk