Template parameter defaults

Jacob Carlborg doob at me.com
Mon May 30 07:12:11 PDT 2011


On 2011-05-30 15:42, Johann MacDonagh wrote:
> I'm wondering if there's a cleaner way to do this:
>
> class Test(T = uint)
> {
> this(string s)
> {
> }
> }
>
> void main(string[] argv)
> {
> auto a = new Test!()("test");
> }
>
> I'd *like* to be able to do this:
>
> auto a = new Test("test");
>
> and:
>
> auto a = new Test!double("test");
>
> The only possibility I see is to do this:
>
> alias Test!() Test2;
>
> But that introduces two types a user has to decide between. Any ideas?
> Am I out of luck here?
>
> Thanks

If you want to use the default parameter I think you have to do this:

auto a = new Test!()("test");

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list