Reducing template constraint verbosity? [was Re: Slides from my ACCU Silicon Valley talk]
Jonathan M Davis
jmdavisProg at gmx.com
Wed Dec 15 10:57:35 PST 2010
On Wednesday, December 15, 2010 05:16:29 Steven Schveighoffer wrote:
> On Wed, 15 Dec 2010 04:34:53 -0500, Daniel Murphy
>
> <yebblies at nospamgmail.com> wrote:
> > "Patrick Down" <pat at codemoon.com> wrote in message
> > news:ie8kei$1gdg$1 at digitalmars.com...
> >
> >> Would it help to allow 'else' and 'else if' on the template constraints?
> >>
> >> void foo(R)(R r) if(isRandomAccessRange!R)
> >> {...}
> >> else if(isInputRange!R)
> >> {...}
> >>
> >> This could basically be translated into two specializations like this:
> >>
> >> void foo(R)(R r) if(isRandomAccessRange!R) {...}
> >> void foo(R)(R r) if(isInputRange!R && !isRandomAccessRange!R) {...}
> >
> > You can sorta already do this...
> >
> > template foo(R)
> > {
> >
> > static if (isRandomAccessRange!R)
> >
> > foo(R r) {}
> >
> > else static if (isInputRange!R)
> >
> > foo(R r) {}
> >
> > else
> >
> > static assert(0, "R must be at least an input range");
> >
> > }
>
> The compiler doesn't treat this the same:
>
> 1. no ifti
> 2. if no branches accept the R type, it tries another template.
By the way, what does IFTI stand for?
- Jonathan M Davis
More information about the Digitalmars-d
mailing list