參考自d程序設計語言---個人博客http://my.oschina.net/u/218155/blog?fromerr=SwOkb7Sw fllow mespa
inout主要是用來推測是不是imutability,const,空類型的..net
咱們能夠 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; } }