From 7808998079633895712
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,51be5305f0d11752
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2001-02-26 15:08:11 PST
Path: supernews.google.com!sn-xit-02!supernews.com!easynews!feedwest.us.telia.net!feedeast.us.telia.net!us.telia.net!howland.erols.net!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: "Deja User" <gennaro_prota@my-deja.com>
Newsgroups: comp.std.c++
Subject: Re: Proposal: change to condition ? value1 : value2
Date: Mon, 26 Feb 2001 23:07:14 GMT
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <200102251739.JAA32287@mail18.bigmailbox.com>
X-Trace: mail2news.demon.co.uk 983228838 mail2news:27513 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)
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
Mime-Version: 1.0
X-Originating-Ip: [213.255.28.211]
Lines: 59
Xref: supernews.google.com comp.std.c++:3783

On Thu, 22 Feb 2001 23:32:53 GMT, gt5163b@prism.gatech.edu (Brian McNamara!) wrote:


>Does something like this suffice?
>
>   template <class T>
>   T ifElseDefault( T value, T def) {
>      return value ? value : def ;
>   }
>   
>   const char *comma = ifElseDefault( strchr(input, ','), "");
>
>It seems to me a function provides the same abstraction without any need
>to extend the language.  
>
>(Although, if the default value is an expression with side-effects that
>shouldn't be evaluated if the condition is true, then indeed, the
>function above is insufficient.  Indeed, I can't even find a solution
>with a macro.)
>

Hehe... :-)))  So it seems that the extension Greg Brewer proposes makes sense!

Just a note: it is natural, in my opinion, that:

  cond? : expr2;

should not evaluate cond twice, even if cond is true; this is different from

cond? cond : expr2,


For instance,

    const char* input = "This, has, commas";
    const char *comma = strchr(input, ',')?   :   "";

should cause at the most one call of strchr.

[I refer to the proposed extension for the ?: operator... i'm not saying that your function
template produces a double evaluation, it's obvious that one evaluation of the
argument used to initialize the parameter 'value' occurs :-)  ]

What do you think about it?

     Gennaro Prota

------------------------------------------------------------
--== Sent via Deja.com ==--
http://www.deja.com/


---
[ 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.     ]



