Extend vector ops to boolean operators?

Timon Gehr timon.gehr at gmx.ch
Wed Mar 7 01:14:54 PST 2012


On 03/06/2012 10:10 PM, Simen Kjærås wrote:
> On Tue, 06 Mar 2012 21:35:11 +0100, Timon Gehr <timon.gehr at gmx.ch> wrote:
>
>> On 03/06/2012 09:30 PM, H. S. Teoh wrote:
>>> It'd be really cool if I could do this:
>>>
>>> void func(int[] vector, int[] bounds) {
>>> assert(vector[]>= 0&& vector[]< bounds[]);
>>> ...
>>> }
>>>
>>> Is there any reason why we shouldn't implement this?
>>>
>>>
>>> T
>>>
>>
>> Comparing arrays already does lexical-style comparison (which makes
>> sense).
>
> Comparing two arrays makes sense, absolutely. Comparing one T[] and
> one T currently does not. Also, foo[] already changes the behavior  of
> operators on foo,


No, it does not change their behavior, it is just required to allow 
them. Array slices have value semantics, and foo[] is currently 
shorthand for foo[0..$].


> making it do a per-element compare would be in line
> with this pattern.
>

Making array slicing change the behavior of some operator wouldn't have 
any precedent.

> This is also already in bugzilla:
> http://d.puremagic.com/issues/show_bug.cgi?id=5636



More information about the Digitalmars-d mailing list