
Boost : 
From: Maarten Kronenburg (M.Kronenburg_at_[hidden])
Date: 20060525 12:10:39
It seems that
if( x )
works with x any base type,
also floating points.
However it does not work with
a type like complex.
When in a template someone uses
if( x )
then it is implicitly assumed that x is
a base type.
For that template to work with other
numeric types like complex or integer,
it should be replaced with something like
if( x != T() )
when it should work for all numeric types,
because
if( x != 0 )
does not work with complex as it does not
construct with base type int, only with
if( x != 0.0 )
So the complex constructors are not explicit,
and complex also does not have a conversion
operator to bool.
Regards, Maarten.
"Maarten Kronenburg" <M.Kronenburg_at_[hidden]> wrote in message
news:e54h1p$dkr$1_at_sea.gmane.org...
> Joe,
> Forgot to mention that for conversion
> to bool type one can also use
> if( x != 0 )
> which works for base type int and for
> type integer.
> This one should be used in templates.
> if( !x.is_zero() )
> of
> if( x.get_sign() )
> only works for type integer,
> and therefore should not be used in
> templates.
> So if there are templates which work with
> if( x )
> where x is a template type parameter int,
> when this template should also work for
> template type parameter integer, this should
> be replaced by
> if( x != 0 )
> This is a price that has to be payed for
> avoiding ambiguities generated with
> a bool conversion operator in integer.
> By the way I wonder if
> if( x )
> also works when x is a floating point
> type like float, double or long double.
> Regards, Maarten.
>
> "Joe Gottman" <jgottman_at_[hidden]> wrote in message
> news:e52u60$h8i$1_at_sea.gmane.org...
> >
> > "Maarten Kronenburg" <M.Kronenburg_at_[hidden]> wrote in message
> > news:e5254e$tba$1_at_sea.gmane.org...
> > > In the boost vault
> > > http://boostconsulting.com/vault/
> > > under Math  Numerics the document
> > > infintdraft.pdf contains the
> > > Proposal for an Infinite Precision Integer
> > > for Library Technical Report 2, Draft.
> >
> > There's a few members that I'd really like to see.
> >
> > First, an operator unspecified_bool_type(), like the one found in
> > shared_ptr. There's a lot of code that looks like the following:
> >
> > long x = doSomething();
> > if (x) { //whatever.
> >
> > If integer is going to be a dropin replacement for long then it should
> have
> > this functionality.
> >
> > Second, it would be very nice if we could have a twoparameter
constructor
> > for emulating scientific notation:
> >
> > integer googol(1, 100);
> >
> > I'm not sure how technically feasible this second one is, but it would
> > certainly be useful.
> >
> > Joe Gottman
> >
> >
> >
> > _______________________________________________
> > Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
> >
>
>
>
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk