Article View: comp.std.c++
Article #2920Re: stop adding keywords to C++
From: mfinney
Date: Sat, 09 Dec 1995 13:18
Date: Sat, 09 Dec 1995 13:18
43 lines
2104 bytes
2104 bytes
In <DJAJ44.J5w@research.att.com>, ark@research.att.com (Andrew Koenig) writes:
>How would you arrange for the expression 3<4 to yield the right type?
type unsigned char bool;
inline bool operator<(int x, int y) {
return bool(x < y); }
would probably do the trick. Just because the definition of bool
is opaque for the purposes of typing, there shouldn't be any
problem casting a value to an opaque type because the compiler
could cast to the underlying type. The only difference I see in
an opaque "type" vs transparent "typedef" is when matching
types.
Since I can overload on bool as defined above, I can define a
global operator (when necessary) to solve problems like this.
It should also be possible to solve the problem by...
inline operator bool(int x) {return (bool)(unsigned char)x;}
Although this approach might be enhanced by something more
like...
inline implicit operator bool(int x) {return (bool)(unsigned char)x;}
where the "implicit" keyword would put a user-defined type
conversion at the same level as that of the built-in type conversions.
Right now, when the user defines a type conversion it is really
a second class citizen compared to the "trivial" conversions and
the built-in conversions because of the rule that says only one
conversion can be applied.
Michael Lee Finney
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<4abhes$cv8@mujibur.inmind.com>Path:
arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!MattReferences:
<Pine.SOL.3.91.951203010216.13007A-100000@barney> <49vplf$mvs@engnews2.Eng.Sun.COM> <4a12d7$vps@mujibur.inmind.com> <DJAJ44.J5w@research.att.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt From: mfinney@inmind.com Newsgroups: comp.std.c++ Subject: Re: stop adding keywords to C++ Date: 09 Dec 1995 13:18:15 GMT Organization: In Mind, Inc. Approved: Matt@Austern Message-ID: <4abhes$cv8@mujibur.inmind.com> References: <Pine.SOL.3.91.951203010216.13007A-100000@barney> <49vplf$mvs@engnews2.Eng.Sun.COM> <4a12d7$vps@mujibur.inmind.com> <DJAJ44.J5w@research.att.com> Reply-To: mfinney@inmind.com NNTP-Posting-Host: austern.hip.berkeley.edu