参考自d程序设计语言---我的博客http://my.oschina.net/u/218155/blog?fromerr=SwOkb7Sw fllow me
inout主要是用来推测是否是imutability,const,空类型的.
我们可以 inout(char)[]代表既可以是immutable(char)[] 也可以是 char[]有点类似泛型。但是他只作用于immutable
import std.stdio;
void main() {
string parenthesized1(string phrase) {
return '(' ~ phrase ~ ')';
}
writeln(parenthesized1("hiparenthesized"));
char[] m;
m ~= "hi";
//writeln(parenthesized(m));
char[] parenthesized2(char[] phrase) {
return '(' ~ phrase ~ ')';
}
writeln(parenthesized2(m));
const(char)[] parenthesized3(const(char)[] phrase) {
return '(' ~ phrase ~ ')';
}
writeln(parenthesized3(m));
inout(char)[] parenthesized(inout(char)[] phrase) {
return '(' ~ phrase ~ ')';
}
writeln(typeof("hiparenthesized").stringof);
writeln(parenthesized("hiparenthesized"));
writeln(typeof(m).stringof);
writeln(parenthesized(m));
writeln(typeid(typeof("hiparenthesized")));
string c1(string s){
return '#'~s;
}
char[] c2(char[] s){
return '#'~s;
}
inout (char)[] c3(inout(char)[] s){
return '#'~s;
}
}