Implicit conversion to bool, and other conversions.
Jonathan M Davis
jmdavisProg at gmx.com
Fri Aug 16 15:11:05 PDT 2013
On Friday, August 16, 2013 14:35:53 Ali Çehreli wrote:
> On 08/16/2013 02:18 PM, Carl Sturtivant wrote:
> > The operator overloading page in the Language Reference and the operator
> > overloading discussion in TDLP say different things about
> >
> > T opCast(bool)() if(is(T==bool))
>
> The current syntax is the following:
>
> bool opCast(T : bool)() const
I'd advise against that, as what that's doing is overloading opCast for any
type which implicitly converts to bool rather than just bool. Depending on the
situation, that might be fine, but in general, you need to be very careful with
implicit conversions - especially when generic code is involved. It's far too
easy to end up with templated code that tries to instantiate with types that
it doesn't work with.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list