Thread overview
Parameterized enum does not work
Jan 09, 2015
Andre
Jan 09, 2015
Daniel Kozak
Jan 09, 2015
Daniel Kozak
Jan 09, 2015
Daniel Kozak
Jan 09, 2015
Andre
January 09, 2015
Hi,

Should following coding work?

string lpad(ubyte length, long n)
{
	import std.string: rightJustify;
	import std.conv: to;
	return rightJustify(to!string(n), length, '0');
}
	
enum lpad14(long n) = lpad(14, n);

void main()
{
	lpad14(123);
}

There is following error from dmd:

source\app.d(12): Error: template app.lpad14 cannot deduce function from argumen
t types !()(int), candidates are:
source\app.d(8):        app.lpad14(long n)

Kind regards
André
January 09, 2015
On Friday, 9 January 2015 at 06:17:53 UTC, Andre wrote:
> Hi,
>
> Should following coding work?
>
> string lpad(ubyte length, long n)
> {
> 	import std.string: rightJustify;
> 	import std.conv: to;
> 	return rightJustify(to!string(n), length, '0');
> }
> 	
> enum lpad14(long n) = lpad(14, n);
>
> void main()
> {
> 	lpad14(123);
> }
>
> There is following error from dmd:
>
> source\app.d(12): Error: template app.lpad14 cannot deduce function from argumen
> t types !()(int), candidates are:
> source\app.d(8):        app.lpad14(long n)
>
> Kind regards
> André

What are you trying to do?

January 09, 2015
On Friday, 9 January 2015 at 07:50:53 UTC, Daniel Kozak wrote:
> On Friday, 9 January 2015 at 06:17:53 UTC, Andre wrote:
>> Hi,
>>
>> Should following coding work?
>>
>> string lpad(ubyte length, long n)
>> {
>> 	import std.string: rightJustify;
>> 	import std.conv: to;
>> 	return rightJustify(to!string(n), length, '0');
>> }
>> 	
>> enum lpad14(long n) = lpad(14, n);
>>
>> void main()
>> {
>> 	lpad14(123);
>> }
>>
>> There is following error from dmd:
>>
>> source\app.d(12): Error: template app.lpad14 cannot deduce function from argumen
>> t types !()(int), candidates are:
>> source\app.d(8):        app.lpad14(long n)
>>
>> Kind regards
>> André
>
> What are you trying to do?

OK I probably see it now :):

import std.stdio;

string lpad(ubyte length, long n)
{
    import std.string: rightJustify;
    import std.conv: to;
    return rightJustify(to!string(n), length, '0');
}

enum lpad14(long n) = lpad(14, n);

void main()
{
    writeln(lpad14!(123));
}
January 09, 2015
On Friday, 9 January 2015 at 07:52:50 UTC, Daniel Kozak wrote:
> On Friday, 9 January 2015 at 07:50:53 UTC, Daniel Kozak wrote:
>> On Friday, 9 January 2015 at 06:17:53 UTC, Andre wrote:
>>> Hi,
>>>
>>> Should following coding work?
>>>
>>> string lpad(ubyte length, long n)
>>> {
>>> 	import std.string: rightJustify;
>>> 	import std.conv: to;
>>> 	return rightJustify(to!string(n), length, '0');
>>> }
>>> 	
>>> enum lpad14(long n) = lpad(14, n);
>>>
>>> void main()
>>> {
>>> 	lpad14(123);
>>> }
>>>
>>> There is following error from dmd:
>>>
>>> source\app.d(12): Error: template app.lpad14 cannot deduce function from argumen
>>> t types !()(int), candidates are:
>>> source\app.d(8):        app.lpad14(long n)
>>>
>>> Kind regards
>>> André
>>
>> What are you trying to do?
>
> OK I probably see it now :):
>
> import std.stdio;
>
> string lpad(ubyte length, long n)
> {
>     import std.string: rightJustify;
>     import std.conv: to;
>     return rightJustify(to!string(n), length, '0');
> }
>
> enum lpad14(long n) = lpad(14, n);
>
> void main()
> {
>     writeln(lpad14!(123));
> }

However this is only for compile time, if you want runtime version you need something like this:

import std.stdio;

string lpad(ubyte length)(long n)
{
    import std.string: rightJustify;
    import std.conv: to;
    return rightJustify(to!string(n), length, '0');
}

alias lpad14 = lpad!14;

void main()
{
    writeln(lpad14(123));
}
January 09, 2015
Thanks a lot.

Kind regards
André

On Friday, 9 January 2015 at 07:59:51 UTC, Daniel Kozak wrote:
> On Friday, 9 January 2015 at 07:52:50 UTC, Daniel Kozak wrote:
>> On Friday, 9 January 2015 at 07:50:53 UTC, Daniel Kozak wrote:
>>> On Friday, 9 January 2015 at 06:17:53 UTC, Andre wrote:
>>>> Hi,
>>>>
>>>> Should following coding work?
>>>>
>>>> string lpad(ubyte length, long n)
>>>> {
>>>> 	import std.string: rightJustify;
>>>> 	import std.conv: to;
>>>> 	return rightJustify(to!string(n), length, '0');
>>>> }
>>>> 	
>>>> enum lpad14(long n) = lpad(14, n);
>>>>
>>>> void main()
>>>> {
>>>> 	lpad14(123);
>>>> }
>>>>
>>>> There is following error from dmd:
>>>>
>>>> source\app.d(12): Error: template app.lpad14 cannot deduce function from argumen
>>>> t types !()(int), candidates are:
>>>> source\app.d(8):        app.lpad14(long n)
>>>>
>>>> Kind regards
>>>> André
>>>
>>> What are you trying to do?
>>
>> OK I probably see it now :):
>>
>> import std.stdio;
>>
>> string lpad(ubyte length, long n)
>> {
>>    import std.string: rightJustify;
>>    import std.conv: to;
>>    return rightJustify(to!string(n), length, '0');
>> }
>>
>> enum lpad14(long n) = lpad(14, n);
>>
>> void main()
>> {
>>    writeln(lpad14!(123));
>> }
>
> However this is only for compile time, if you want runtime version you need something like this:
>
> import std.stdio;
>
> string lpad(ubyte length)(long n)
> {
>     import std.string: rightJustify;
>     import std.conv: to;
>     return rightJustify(to!string(n), length, '0');
> }
>
> alias lpad14 = lpad!14;
>
> void main()
> {
>     writeln(lpad14(123));
> }