Re: Default argument for templatized function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, May 12, 2004 at 10:49:51AM -0700, Adrian Bentley wrote:

> Yeah, ok.  I really do know what I'm talking about with C++, I just
> haven't
> been able to get it to do what I want :P.  And I figured it was
> something
> like that (with respect to interpreting...), but why would it work so
> easily
> for the other case? (and yes just calling with the two parameters works
> just
> fine...)

I can't get the code you posted (incomplete as it was) to compile with
GCC 2.95, 3.3, 3.4, or with Comeau's compiler.

> I definitely know MANY ways to get around it, but it still makes generic
> programming WAY more of a pain in the ass if you can't let it figure
> things
> like that out for itself.

The solution I posted does what you want, with little extra code. Making
it do it your way would require a change to the language, which is
unnecessary since you can achieve the desired effect as I showed.

> Without the functionality of deriving the template for a default
> argument,
> which seems pretty straight forward to me by the way, it makes that a
> fairly
> gross limitation of gcc (lack of function specialization AND lack of
> ability
> to intuit from a default parameter). I know there could be some issues
> depending on the order the compiler goes through the steps, but man...
> it
> doesn't seem that complicated (I don't have any specific reference in
> Bjarne
> or anything...).

You never said which version of the compiler you had tried, but it doesn't
matter as GCC is right to reject the code you posted.

> So should I submit this as a bug then?  It seems like the compiler
> should be
> able to do that (since it can't do def. template arguments for
> functions).

That's the rules of the language.  As llewelly said, see 14.8.2.4/17.

Calling a function template with no arguments and without explicitly
stating which specialisation you want means that the compiler cannot
deduce the parameters. This is not a limitation of GCC.

> Of course if they add default template arguments for functions... then
> it
> would be fine.  Suggestions?

You could submit a proposal for a language change to the standards
committee (but don't hold your breath for it to be accepted).

jon

-- 
"The only cure for the ills of democracy is more democracy."
	- Al Smith

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux