From -1082922665650684024
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,bc82bd0900b8b4ac
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2000-12-23 05:12:07 PST
Path: supernews.google.com!sn-xit-02!supernews.com!newsfeed.online.be!diablo.netcom.net.uk!netcom.net.uk!dispose.news.demon.net!demon!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: remove.haberg@matematik.su.se (Hans Aberg)
Newsgroups: comp.std.c++
Subject: Re: Feature Request: Fast "find" for sorted random access containers
Date: Sat, 23 Dec 2000 13:11:45 GMT
Organization: Mathematics
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <remove.haberg-2212002022530001@du144-226.ppp.su-anst.tninet.se>
References: <remove.haberg-2112001922450001@du158-226.ppp.su-anst.tninet.se> <memo.20001222103314.5813B@a.btinternet.com>
X-Trace: mail2news.demon.co.uk 977577120 mail2news:29960 mail2news mail2news.demon.co.uk
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
NNTP-Posting-Date: 22 Dec 2000 19:22:53 GMT
Lines: 50
Xref: supernews.google.com comp.std.c++:3094

In article <memo.20001222103314.5813B@a.btinternet.com>,
brangdon@cix.compulink.co.uk wrote:
>> Who has said that a type "ordering" should be implemented as an enum? 
>> -- I didn't. :-) After all, the "bool" type is not an enum
>> (3.9.1#6), so why should an "ordering" be an enum.
>
>Why else could it be? It can't be a class if we want switch() to work. It 
>hardly seems worth adding a new primitive type (and hence reserved name) 
>to the language.

It would be a new type, just as "bool", adding new keywords as you say.

Orderings are very fundamental in computers, it seems: Every logical
structure can be given a total order, induced by some underlying binary
implementation, and then such a total order can be used to speed up
sorting & searching.

So I think it is worth having such a type.

>> One might though have a type "ordering" with values in the _set_ { 
>> less, equal, greater, unrelated}.
>
>If you have 4 values in the enum, the problem goes away, but now all code 
>has to deal with the "unrelated" case - often even if it is not possible.

That is the drawback, that the extra case must be considered in switches.

But if one is not exclusively dealing with total orders, it may be worth
giving it a consideration.

For example, if one defines "x => y" to be "x is derived from y", then
some elements are not comparable. -- In math, this is a quite common
situation, "lattice theory", etc.

So one must wiegh the drawback of having to consider the extra case in
swicth statements when using total orders against the advantage of being
able to use the structure for any type of order, not simply total orders.

  Hans Aberg      * Anti-spam: remove "remove." from email address.
                  * Email: Hans Aberg <remove.haberg@member.ams.org>
                  * Home Page: <http://www.matematik.su.se/~haberg/>
                  * AMS member listing: <http://www.ams.org/cml/>

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]



