Array length : size_t

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Sep 18 16:11:00 PDT 2013


On Thu, Sep 19, 2013 at 12:52:55AM +0200, Dicebot wrote:
> On Wednesday, 18 September 2013 at 22:20:45 UTC, H. S. Teoh wrote:
> >If the C function only accepts int, then just use to!int(array.size).
> >If the size overflows int, to() will throw an exception which you can
> >handle. This is probably the best you can do anyway, since if the C
> >function doesn't take anything bigger than int, then there's no way
> >you can pass the real size to it.
> 
> Ah, `to!()` does check valid ranges before conversion? Good to know,
> thanks.

Yes, it's handled explicitly by the following overload of toImpl() in
std.conv:

	T toImpl(T, S)(S value)
	    if (!isImplicitlyConvertible!(S, T) &&
		(isNumeric!S || isSomeChar!S || isBoolean!S) &&
		(isNumeric!T || isSomeChar!T || isBoolean!T) && !is(T == enum))
	{
	    ...
	}


T

-- 
Too many people have open minds but closed eyes.


More information about the Digitalmars-d-learn mailing list