www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.algorithm and immutable arrays

reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
I'm thinking of the recently discussed problem and it seems that 
immutable arrays are an issue not only for find(), but for all functions 
that need ranges.

To fix things I'd need to add code for detecting immutable(T[]) and 
converting it to immutable(T)[] for _every_ algorithm using ranges out 
there. That would make things worse from a readability standpoint.

So we're looking at a number of options:

(a) Leave things as they are. To use std.algorithm with immutable arrays 
you need to peel off the top-level immutable.

(b) Promote a change in the compiler to convert immutable(T[]) to 
immutable(T)[] when passed by value into a function. This is safe and 
sensible.

(c) Bludgeon std.algorithm to work with immutable(T[]).

What say you?


Andrei
Jun 09 2010
next sibling parent Michel Fortin <michel.fortin michelf.com> writes:
On 2010-06-09 20:41:48 -0400, Andrei Alexandrescu 
<SeeWebsiteForEmail erdani.org> said:

 (b) Promote a change in the compiler to convert immutable(T[]) to 
 immutable(T)[] when passed by value into a function. This is safe and 
 sensible.
This looks good to me. Although I wonder what happens if that range is a class, will you get a rebindable reference to a class? -- Michel Fortin michel.fortin michelf.com http://michelf.com/
Jun 09 2010
prev sibling next sibling parent BCS <none anon.com> writes:
Hello Andrei,

 (b) Promote a change in the compiler to convert immutable(T[]) to
 immutable(T)[] when passed by value into a function. This is safe and
 sensible.

 What say you?
b.vote++ Making that an implicit conversion on any copy should be safe. But would it have any side effects? Also, would that strip it by default or only when the called function demands it?
 
-- ... <IXOYE><
Jun 09 2010
prev sibling next sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:

 (b) Promote a change in the compiler to convert immutable(T[]) to  
 immutable(T)[] when passed by value into a function. This is safe and  
 sensible.
This absolutely seems sensiblest. Vote++; -- Simen
Jun 10 2010
prev sibling next sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:

 (b) Promote a change in the compiler to convert immutable(T[]) to  
 immutable(T)[] when passed by value into a function. This is safe and  
 sensible.
This absolutely seems sensiblest. Vote++; -- Simen
Jun 10 2010
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 09 Jun 2010 20:41:48 -0400, Andrei Alexandrescu  
<SeeWebsiteForEmail erdani.org> wrote:

 (b) Promote a change in the compiler to convert immutable(T[]) to  
 immutable(T)[] when passed by value into a function. This is safe and  
 sensible.
I think this works well. Same goes for const and shared. -Steve
Jun 10 2010
prev sibling parent Bruno Medeiros <brunodomedeiros+spam com.gmail> writes:
On 10/06/2010 01:41, Andrei Alexandrescu wrote:
 (b) Promote a change in the compiler to convert immutable(T[]) to
 immutable(T)[] when passed by value into a function. This is safe and
 sensible.
tailconst strikes back? :] -- Bruno Medeiros - Software Engineer
Jun 15 2010