Top 5
Denis Koroskin
2korden at gmail.com
Fri Oct 10 02:45:41 PDT 2008
On Fri, 10 Oct 2008 03:50:58 +0400, Sergey Gromov <snake.scaly at gmail.com>
wrote:
> I think that the base type should offer both speed and safety by
> default. To achieve this I propose to disallow unsafe operations on
> current arrays, call them slices, and introduce a built-in memory
> management class, Array(T). Here's why built-in:
>
> void main()
> {
> auto arr = new char[]; // arr is of type Array!(char)
> arr.length = 10; // OK
> arr ~= 'c'; // fast
> arr ~= "foo bar"; // fast
> foo(arr); // implicit cast to char[]
> bar(arr); // passed by reference
> // "text" is appended
> }
>
> void foo(char[] a)
> {
> char x = a[0]; // OK
> char[] word = a[10..14]; // fine
> size_t l = a.length; // 18
> a.length = 20; // error, .length is read-only
> a ~= "text"; // error, append not supported
> char[] n = a[15..18] ~ "some" // type of expression is Array!(char)
> ~ word // fast
> ~ "baz" // fast
> ; // implicit cast to char[]
> }
>
> void bar(Array!(char) a)
> {
> a ~= "text"; // OK
> }
>
The basic idea is good, but I believe that the proposal as is is too much
complex. I think Array!(T) should not be casted to T[] implicitly,
instead, it could have T[] all() method to be on par with ranges design.
But then, this reduces usefulness of T[]. When should it be used? What are
the benefits of const(T)[] over const(Array!(T))?
As you prosope, difference between T[] functionality (mutable but not
resizable) over Array!(T) (mutable and resizable) is just too narrow.
Besides, Array!(T) is not a good name for build-in type.
Again, I think that basic idea is good, but details still need to be
worked on.
More information about the Digitalmars-d
mailing list