Re: Default argument for templatized function

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

 



Ok to ammend that, I'm not trying to be hostile.  I'm really just
looking for sympathy :P, perhaps that would have been better found else
where.

Adruab
On Thu, 2004-05-13 at 14:46, Adrian Bentley wrote:
> Yeah, ok, fine, it's nice to see that no one else finds this
> irritating.  I fixed it already, but it is a hack (generics are supposed
> to be elegant...).
> 
> However, gcc still seems to be inconsistent.  The reason why the second
> one worked, was that I had two functions (one with a 3rd argument and
> one without).  Shouldn't it cause a warning or something if it's
> ignoring a default argument like that, and there's a second function
> with the exact same first two?  I mean sure it can all be chalked up to
> template weirdness, but sheesh.
> 
> In the end these are all just work arounds for not being able to have
> default template arguments for functions (which should have been fixed
> long ago).  Standards are good, but it seems to be becoming more and
> more inflexible, but perhaps that is just me being confused.
> 
> Thanks for the smackdown folks (slightly enlightening though it was),
> I'll be sure to just fix what I've got in the future.
> 
> Adruab
> 
> On Thu, 2004-05-13 at 01:05, Jonathan Wakely wrote:
> > 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
> 
> 
> 


[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