What is the best declaration type for a string like parameter?

Gary Willoughby via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jan 28 09:32:31 PST 2016


On Thursday, 28 January 2016 at 15:10:38 UTC, Adam D. Ruppe wrote:
> On Thursday, 28 January 2016 at 13:36:46 UTC, Puming wrote:
>> I searched the forum and found that people use `const(char)[]` 
>> or `in char[]` to accept both string and char[] arguments.
>
> There's also the hyper-generic signatures Phobos uses like
>
> void foo(S)(S s) if(isSomeString!S)

Yep, this is your answer.

void foo(S)(S s) if(isSomeString!S)
{
     //use s
}

Call normally as it can implicitly determine the type of S:

foo("bar");


More information about the Digitalmars-d-learn mailing list