template statistics

Jacob Carlborg doob at me.com
Thu Jun 4 11:13:12 UTC 2020


On Wednesday, 3 June 2020 at 21:01:48 UTC, Steven Schveighoffer 
wrote:

> But the question above is still unanswered -- writeln receives 
> a string as an immutable(char)[], and doesn't know that it's 
> from a literal.

Perhaps add an overload that takes `const(char)*`? Here's an 
example:

string foo(T...)(T args) // signature of `writeln`
{
     return "...";
}

string foo(const(char)* value)
{
     return "foo";
}

void main()
{
     assert(foo("bar") == "foo");
}

The above assertion pass. That means the compiler prefers the 
version with `const(char)*` for string literals in favor over the 
template version.

--
/Jacob Carlborg


More information about the Digitalmars-d mailing list