From 4220576172115518679
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,5be30c38f618a07b
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-05-01 10:16:01 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!kibo.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: Gennaro Prota <gennaro_prota@yahoo.com>
Newsgroups: comp.std.c++
Subject: Re: Why switch w/ only integral types?
Date: Wed,  1 May 2002 17:15:30 GMT
Organization: [Infostrada]
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <18fvcukf5521rtopvnt2btjnbho34ra82b@4ax.com>
References: <6ee7d287.0203202005.63e0b7b3@posting.google.com> <qfpm8.12422$cy2.680922353@newssvr21.news.prodigy.com> <3CCE6310.672E55DF@webmaster.com>
X-Trace: mail2news.demon.co.uk 1020273337 mail2news:5415 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)
X-Newsreader: Forte Agent 1.9/32.560
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Date: Wed, 01 May 2002 12:04:48 MET DST
Lines: 70
Xref: archiver1.google.com comp.std.c++:10945

On Tue, 30 Apr 2002 18:44:01 GMT, David Schwartz
<davids@webmaster.com> wrote:

[...]
>
>	There are reasons. Consider:
>
>MyFoo f;
>
>switch (f)
>{
> case 1:
>  // code
> case 2:
>  // code
>}
>
>	What should happen if MyFoo::operator==(int) returns 'true' for both 1
>and 2?
>

I think you completely missed the point.
We are talking about using non-integral expressions in case labes, not
in the switch condition.

With the current rules, the following is legal:


class A {
    public:
	typedef char whatever;
	A(whatever) {}
	operator int() const { return 1;}
};
	
	
switch (A a = 'x') {
	case 1:
		/*...*/
	case 2:
		/*...*/
	default:
}

and causes A::operator int() const to be invoked at the evaluation of
A a = 'x' . No operator ==() is currently needed.


P.S.: for Greg Comeau (I hope you are reading...). Comeau online seems
to accept the above switch statement in some cases where A has more
than one conversion function to integral/enumeration types, for
instance:

       operator int() const { return 1;}
       operator char() const {return 'a';}
       operator bool() {return true;}


Anyhow it emits an error if I declare also operator bool() as a
const-function. Isn't this a bug?


Genny.

---
[ 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.jamesd.demon.co.uk/csc/faq.html                       ]



