module pind.samples.ja.const_member_functions.const_member_functions_1; import std.stdio; struct Container { int[] elements; inout(int)[] firstPart(size_t n) inout { return elements[0 .. n]; } } void main() { { // 不変のコンテナ auto container = immutable(Container)([ 1, 2, 3 ]); auto slice = container.firstPart(2); writeln(typeof(slice).stringof); } { // constコンテナ auto container = const(Container)([ 1, 2, 3 ]); auto slice = container.firstPart(2); writeln(typeof(slice).stringof); } { // 変更可能なコンテナ auto container = Container([ 1, 2, 3 ]); auto slice = container.firstPart(2); writeln(typeof(slice).stringof); } }