Path: utzoo!attcan!uunet!ncrlnk!ncrcae!hubcap!gatech!bbn!bbn.com!lpringle From: lpringle@bbn.com (Lewis G. Pringle) Newsgroups: comp.lang.c++ Subject: Re: goodbye cpp ??? Message-ID: <33617@bbn.COM> Date: 16 Dec 88 20:57:54 GMT References: <6590072@hplsla.HP.COM> <1106@etive.ed.ac.uk> <33528@bbn.COM> <1907@ogccse.ogc.edu> Sender: news@bbn.COM Reply-To: lpringle@labs-n.bbn.com (Lewis G. Pringle) Organization: Bolt Beranek and Newman Inc., Cambridge MA Lines: 36 In article <1907@ogccse.ogc.edu> wm@ogccse.UUCP (Wm Leler) writes: >I don't think you could extend switch statements to work on strings, >since there is some ambiguity between whether you want to compare >the strings by comparing their contents (using strcmp) or by comparing >their pointers (a very reasonable thing to do). > You seem to have missed something. What I suggested was more general than extending switch to work with strings. The compiler would barf on strings unless the user had defined the approriate conversion operators and op== functions. The user could then define op== however he wanted (pointer equality or strcmp() equality). A more interesting problem is one brought up by Michael Tiemann. He pointed out that that the result of the evaluation of the switch() would be a auto temp variable whose op== function would end up called a bunch of times. This is kosher, so long as op== is guarenteed not to modify either of its arguments, but the compiler does not enforce this! This leads me to another suggestion - which may already be true for all I know - that whenever you define an op== function (or other comparitor) it be required to have as aguements const-references. I kind of like this idea (I would be unhappy do discover that in some library I was using, the op== function changed one of the things I was comparing!) but it would be a great departure from the current c++ definition where these comparison operators are not assumed to have any particular semantics. Lewis. "OS/2: half an operating system for half a computer." In Real Life: Lewis Gordon Pringle Jr. Electronic Mail: lpringle@labs-n.bbn.com Phone: (617) 873-4433