Fun with templates

Manu turkeyman at gmail.com
Fri Jul 5 20:32:31 PDT 2013


On 6 July 2013 11:41, Daniel Murphy <yebblies at nospamgmail.com> wrote:

>
> "Manu" <turkeyman at gmail.com> wrote in message
> news:mailman.1752.1373074509.13711.digitalmars-d at puremagic.com...
> > Okay, so I feel like this should be possible, but I can't make it work...
> > I want to use template deduction to deduce the argument type, but I want
> > the function arg to be Unqual!T of the deduced type, rather than the
> > verbatim type of the argument given.
> >
> > I've tried: void f(T : Unqual!U, U)(T a) {}
> > and: void f(T)(Unqual!T a) {}
> >
> > Ie, if called with:
> >  const int x;
> >  f(x);
> > Then f() should be generated void f(int) rather than void f(const int).
> >
> > I don't want a million permutations of the template function for each
> > combination of const/immutabe/shared/etc, which especially blows out when
> > the function has 2 or more args.
> >
> > Note: T may only be a primitive type. Obviously const(int*) can never be
> > passed to int*.
> >
>
> void f(T)(T _a) { Unqual!T a = _a; ... }
>

That doesn't do what I want at all. The signature is still f(T) not
f(Unqual!T).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130706/7bc891b1/attachment-0001.html>


More information about the Digitalmars-d mailing list