Article View: comp.std.c++
Article #3648Re: no operator bool()?
From: Pablo Halpern
Date: Wed, 13 Mar 1996 04:22
Date: Wed, 13 Mar 1996 04:22
45 lines
2345 bytes
2345 bytes
"Nathan Myers, http://www.cantrip.org/" <ncm@cantrip.org> wrote:
>Automatic conversions can be a problem in general, but the problems
>with automatic conversions to a numeric type are ridiculous.
>Compatibility with C has its downside.
>
>As a side note... The problem with automatic conversions is not
>only that the conversion may be called unexpectedly; the
>possibility of the conversion affects overloading, so it may
>force you to add "unnecessary" casts to guide the compiler to
>the correct choice of function to call.
Sounds like another reason to permit the keyword "explicit" to apply to
conversion operators. I really don't see why the committee is so
resistant to this concept. I think the following would be a perfectly
satisfactory usage:
class istream : public ...
{
...
explicit operator bool() const;
...
};
void f()
{
while (bool(cin))
// do something
}
Its clear. Its easy to remember. Its clean. Same would work for
auto_ptr<>.
-------------------------------------------------------------
Pablo Halpern phalpern@truffle.ultranet.com
I am self-employed. Therefore, my opinions *do* represent
those of my employer.
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID:
<31445809.5921189@news.ultranet.com>Path:
arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austernReferences:
<313ddfd9.16044605@sqarc.sq.com> <313E19BB.5AE2E407@cantrip.org>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern From: phalpern@truffle.ultranet.com (Pablo Halpern) Newsgroups: comp.std.c++ Subject: Re: no operator bool()? Date: 12 Mar 1996 20:22:20 PST Organization: UltraNet Communications, Inc. Approved: austern@isolde.mti.sgi.com Message-ID: <31445809.5921189@news.ultranet.com> References: <313ddfd9.16044605@sqarc.sq.com> <313E19BB.5AE2E407@cantrip.org> NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: Mon, 11 Mar 1996 17:30:52 GMT X-Newsreader: Forte Agent .99d/16.182 X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMUZNiEy4NqrwXLNJAQGd5wH/fQ331WXkTYEqEV/Ts8dCaB+reT+tQmqm m4R+3D0C810MaS7lrFTnAojtbECkeJf/DsRHmGRlJs94+4hf1AFrYw== =Gd/M Originator: austern@isolde.mti.sgi.com