http://f17.aaa.livedoor.jp/~labamba/
配列リテラルで変数を初期化できるようになった.
今度はautoも使えるようにして欲しいな.
import std.stdio;
template Const()
{
this() { writefln("call Const"); }
}
template Dest()
{
~this() { writefln("call Dest"); }
}
class Mixin
{
mixin Const!(); // コンストラクタのミックスイン1回目
// mixin Const!(); // コンストラクタのミックスイン2回目 -> エラー
mixin Dest!(); // デストラクタのミックスイン1回目
mixin Dest!(); // デストラクタのミックスイン2回目 (*)
}
class Foo
{
class Bar {}
}
void main()
{
const int[] a = [1,2,3]; // 静的初期化
int[] b = [1,2,3]; // 配列リテラルで初期化 (*)
//auto c = [1,2,3]; // 配列リテラルで初期化 -> エラー (*)
auto d = ([1,2,3]); // 配列リテラルで初期化 (*)
auto e = cast(int[])[1,2,3]; // 配列リテラルで初期化 (*)
char[][] i = ["abc","def","ghi"]; // 配列リテラルの[][]へのキャスト (*)
Foo f = new Foo; // 普通にnew
Foo.Bar g = f.new Foo.Bar; // interクラスのnew
Foo h = g.outer; // outerプロパティ (*)
Mixin j = new Mixin(); // ミックスインを含むクラスのnew
}実行結果
call Const call Dest call Dest
コメントの最後に(*)が付いているのが今回から使えるようになるはずの部分.
エラーになるところは今後改善されるかな?
それにしてもmixin関係の意義は何なんだかさっぱりわからん.