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

Puming via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jan 28 05:36:46 PST 2016


I have a function that reads a line of string and do some 
computation.

I searched the forum and found that people use `const(char)[]` or 
`in char[]` to accept both string and char[] arguments.


What's the difference between `const(char)[]` and `in char[]`?

If they are not the same, then which is better? If they are, then 
why both forms exists?

I found it a bit confusing and not quite readable, so I made an 
alias:

alias str = const(char)[]

and so far it works. But if `in char[]` is better, then I cannot 
alias it:

alias str = in char[]

this does not compile.


More information about the Digitalmars-d-learn mailing list