...ing logging 4.0

はてなブログに移行しました。D言語の話とかいろいろ。

inout(type) or inout(type)?

http://www.digitalmars.com/d/2.0/function.html

inout(int)[] foo(inout(int)[] a, int x, int y) { return a[x .. y]; }

ふむ.

import std.stdio;

inout(int)[] f(inout(int)[] a, int x, int y)
{
	return a[x .. y];
}

void main()
{
	auto b = f([1,2,3,4,5,6,7][], 1, 3);
	writeln(b);
}
hello.d(10): Error: function hello.f (inout(int)[] a, int x, int y) is not callable using argument types (int[],int,int)
hello.d(10): Error: cannot implicitly convert expression ([1,2,3,4,5,6,7][]) of type int[] to inout(int)[]

んー?

import std.stdio;

inout(int[]) f(inout(int[]) a, int x, int y)
{
	return a[x .. y];
}

void main()
{
	auto b = f([1,2,3,4,5,6,7][], 1, 3);
	writeln(b);
}

こうするといけた.

どうでもいいが[]を半角でタイトルに書くにはどうしたらいいんだ・・・.