謎's キッチン

謎のひとりごと。Amazon欲しい物リストはこちら: https://www.amazon.co.jp/hz/wishlist/ls/CCPOV7C6JTD2

pythonの内包表記

内包表記的な何か」の意図が汲めなかったのでそのページの上のpythonの例をそのまま移植してみた。多分あってるはず。

private import std.stdio,std.typetuple;
template range(int min, int max){
  template _for(alias temp, int n=min){
    int dummy;
    static if(n == max)
      template _for(args...){
        alias TypeTuple!() _for;
      }
    else
      template _for(args...){
        alias TypeTuple!(temp!(args, n) , range!(min,max)._for!(temp, n+1)._for!(args)) _for;
      }
  }
}

template mul(args...){
  const mul=args[0]*args[1];
}

void main(){
  int[] ary = [range!(1,4)._for!(range!(1,4)._for!(mul)._for)._for!()];
  writefln(ary);
}