auto ref and non-templated functions

Jens Mueller jens.k.mueller at gmx.de
Tue Dec 25 02:44:45 PST 2012


Jonathan M Davis wrote:
> On Tuesday, December 25, 2012 11:12:43 Jens Mueller wrote:
> > Jonathan M Davis wrote:
> > > On Tuesday, December 25, 2012 01:56:42 Peter Alexander wrote:
> > > > On Monday, 24 December 2012 at 17:40:54 UTC, Jonathan M Davis
> > > > 
> > > > wrote:
> > > > > Why can't we simply make auto ref work with non-templated
> > > > > functions by making
> > > > > it automatically generate both the ref and non-ref versions?
> > > > > 
> > > > > [snip]
> > > > > 
> > > > > What problems does this cause? Why haven't we just done this
> > > > > already?
> > > > 
> > > > What does this generate?
> > > > 
> > > > auto foo(auto ref S a, auto ref S b, auto ref S c, auto ref S d)
> > > > { ... }
> > > > 
> > > > 16 different functions, one for each combination? Sounds like a
> > > > bad idea.
> > > 
> > > Excellent point.
> > 
> > I'm not sure but doesn't the compiler only create such a function when
> > it is called.
> > Still it may be confusing but it's similar to a function template. But
> > here it's a template regarding passing convention.
> 
> If it were a template, sure. But the whole point is that we need a solution 
> which _isn't_ a template, which in this case would mean generating every 
> possible combination regardless of whether they were used or not. So, I think 
> that Peter has shown why that particular approach is untenable.

And the solution needs to be non-template based because it needs to work
with classes? Is that the only reason?

Jens


More information about the Digitalmars-d mailing list