Proposal?

Daniel N no at public.email
Wed May 30 19:05:57 UTC 2018


On Wednesday, 30 May 2018 at 12:22:28 UTC, FeepingCreature wrote:
> On Wednesday, 30 May 2018 at 10:05:42 UTC, H. S. Teoh wrote:
>> What about this?
>>
>> ------
>> struct EndOfArgs { }
>> EndOfArgs eoa;
>>
>> void func(string s, EndOfArgs _ = eoa,
>> 	string file = __FILE__, size_t line = __LINE__)
>> {
>> 	import std.stdio;
>> 	writefln("%s:%d: msg=%s", file, line, s);
>> }
>>
>> void main() {
>> 	func("hello");
>> 	func("there");
>> }
>> ------
>>
>>
>> Basically, use a dummy empty struct to differentiate between 
>> real arguments and context info.
>>
>>
>> T
>
> Thank you, this seems to work well!
>
> We're using struct Fence { } Fence _ = Fence(), and it doesn't 
> add much overhead.
>
> Barring the proposed compiler change, this seems the cleanest 
> fix.

void func(NONE...)(string s, NONE, string file = __FILE__, size_t 
line = __LINE__) if(!NONE.length)
{
	import std.stdio;
	writefln("%s:%d: msg=%s", file, line, s);
}

void main() {func("hello"); func("there");
}


More information about the Digitalmars-d mailing list