|
Boost : |
From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2000-09-13 05:49:07
Daryle Walker (<darylew_at_[hidden]>) wrote:
> I can't compile the test code. It has a problem with default arguments.
> The token_iterator (template) class has two constructors that can take a
> constant reference of a tokenizer object as the final argument. This
> argument is defaulted to the default value of that type. Unfortunately,
my
> compiler [Metrowerks CodeWarrior Pro 5 (with 5.3 update) for the Mac OS]
> can't handle the template when the tokenizer type is not
> default-constructable. Only one of the test samples has that property,
but
> the compiler doesn't even allow the work-around of explicitly giving the
> last argument a specific value.
>
> In other words:
>
> class MyFirst
> {
> MyFirst() {}
> //...
> };
>
> class MySecond
> {
> MySecond( int i ) : i_(i) {}
> //...
> }
>
> //...
>
> // This works
> Iter x;
> token_iterator<Iter, MyFirst> begin( x.begin(), x.end() ), end;
>
> // This doesn't work, by choking on MySecond not having a default
> // constructor, even though I don't try to use one!
> Iter y;
> token_iterator<Iter, MySecond> begin2( y.begin(), y.end(), MySecond(1) ),
> end2( MySecond(0) );
The compiler is wrong here. From 14.7.1 [temp.inst], para 2:
"Unless a call is to a function template explicit specialization or to a
member function of an explicitly specialized class template, a default
argument for a function template or a member function of a class template is
implicitly instantiated when the function is called in a context that
requires the value of the default argument. "
--Aleksey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk