www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Deprecation

reply Ali <mammadov.ali ideal.az> writes:
Hello. I am having an issue with the code below. the out put 
after compiling is this :

Deprecation: foreach: loop index implicitly converted from size_t 
to uint

the code is :

auto available = new int[cast(uint) max - min];
		foreach (uint i, ref a; available)
			a = min + i;

Any help would be highly appreciated.
Jan 18
next sibling parent Neia Neutuladh <neia ikeran.org> writes:
On Fri, 18 Jan 2019 22:53:23 +0000, Ali wrote:
 Hello. I am having an issue with the code below. the out put after
 compiling is this :
 
 Deprecation: foreach: loop index implicitly converted from size_t to
 uint
 
 the code is :
 
 auto available = new int[cast(uint) max - min];
 		foreach (uint i, ref a; available)
 			a = min + i;
 
 Any help would be highly appreciated.
You are trying to use a uint (max value 2^32-1) to give an index for an array (which might be more than 2^32-1 elements long). That's deprecated and will be gone from the language in a few releases. Instead, write: foreach (size_t i, ref a; available) a = cast(uint)(min + i);
Jan 18
prev sibling next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Fri, Jan 18, 2019 at 10:53:23PM +0000, Ali via Digitalmars-d-learn wrote:
 Hello. I am having an issue with the code below. the out put after
 compiling is this :
 
 Deprecation: foreach: loop index implicitly converted from size_t to
 uint
 
 the code is :
 
 auto available = new int[cast(uint) max - min];
Replace uint with size_t.
 		foreach (uint i, ref a; available)
Ditto.
 			a = min + i;
 
 Any help would be highly appreciated.
T -- Study gravitation, it's a field with a lot of potential.
Jan 18
prev sibling parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 1/18/19 5:53 PM, Ali wrote:
 Hello. I am having an issue with the code below. the out put after 
 compiling is this :
 
 Deprecation: foreach: loop index implicitly converted from size_t to uint
 
 the code is :
 
 auto available = new int[cast(uint) max - min];
          foreach (uint i, ref a; available)
foreach (i, ref a; available)
              a = min + i;
a = cast(uint)(min + i);
 
 Any help would be highly appreciated.
-Steve
Jan 18