Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-10-26 08:01:59

From: "Ross Smith" <r-smith_at_[hidden]>
> Peter Dimov wrote:
> >
> > All these solutions have a common drawback:
> >
> > template<class Numeric> void foo(Numeric n);
> >
> > foo(pi()); // calls void foo<some_type_that_is_not_numeric>
> foo(double(pi()));
> Actually I think that specific example falls foul of the infamous
> is-it-a-function-call-or-a-declaration bug^H^H^Hfeature of the language
> and would have to be written as a static_cast rather than a
> constructor-style cast. But you get the idea.

Yes I do. But the original may compile, which is the problem. Or it might
generate some cryptic error inside 'foo'.

> _Any_ generic solution would require the type to be explicitly specified
> in this sort of context; mine is no worse than anyone else's.

True. It might be argued that foo(pi<double>()) is no better than
foo(static_cast<double>(pi())) since you have to say 'double' in both cases.

But my point is that all 'plain pi' solutions that rely on implicit
conversions only promise to provide the ease of the simple 'pi' constant and
the robustness of

template<class T> T pi();

but don't really deliver - in both cases.

Peter Dimov
Multi Media Ltd.

Boost list run by bdawes at, gregod at, cpdaniel at, john at