Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
January 10, 2011 [phobos] std.string.cmp | ||||
---|---|---|---|---|
| ||||
Hrm.. I think I'd like to object to today's change of std.string.cmp to return sizediff_t rather than int. The reason.. Object.opCmp returns int. So, using cmp is needlessly painful. A simple cast is dangerous.. consider what happens if some how the cmp returns a multiple of 2^32. But I guarantee that a simple cast is what most people that run into the mismatch will do. Thoughts? |
January 10, 2011 [phobos] std.string.cmp | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Roberts | I reverted to int. I was worried about a slight inefficiency but I guess it's hardly measurable.
Andrei
On 1/10/11 10:56 PM, Brad Roberts wrote:
> Hrm.. I think I'd like to object to today's change of std.string.cmp to return sizediff_t rather than int. The reason.. Object.opCmp returns int. So, using cmp is needlessly painful. A simple cast is dangerous.. consider what happens if some how the cmp returns a multiple of 2^32. But I guarantee that a simple cast is what most people that run into the mismatch will do.
>
> Thoughts?
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
|
January 10, 2011 [phobos] std.string.cmp | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Well, we can consider changing optic to return a sizediff_t, which removes the problems at the cost of an impacting change.
On 1/10/2011 11:11 PM, Andrei Alexandrescu wrote:
> I reverted to int. I was worried about a slight inefficiency but I guess it's hardly measurable.
>
> Andrei
>
> On 1/10/11 10:56 PM, Brad Roberts wrote:
>> Hrm.. I think I'd like to object to today's change of std.string.cmp to return sizediff_t rather than int. The reason.. Object.opCmp returns int. So, using cmp is needlessly painful. A simple cast is dangerous.. consider what happens if some how the cmp returns a multiple of 2^32. But I guarantee that a simple cast is what most people that run into the mismatch will do.
>>
>> Thoughts?
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
|
January 10, 2011 [phobos] std.string.cmp | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Sigh. The reverted version doesn't build on 64 bit: std/string.d(150): Error: cannot implicitly convert expression (s1.length - s2.length) of type ulong to int std/regexp.d(1714): Error: template instance std.string.icmp!(char,immutable(char)) error instantiating I agree that sizediff_t is much more convenient. Maybe it is better to go ahead and change the opCmp return type. On 1/10/2011 11:11 PM, Andrei Alexandrescu wrote: > I reverted to int. I was worried about a slight inefficiency but I guess it's hardly measurable. > > Andrei > > On 1/10/11 10:56 PM, Brad Roberts wrote: >> Hrm.. I think I'd like to object to today's change of std.string.cmp to return sizediff_t rather than int. The reason.. Object.opCmp returns int. So, using cmp is needlessly painful. A simple cast is dangerous.. consider what happens if some how the cmp returns a multiple of 2^32. But I guarantee that a simple cast is what most people that run into the mismatch will do. >> >> Thoughts? >> _______________________________________________ >> phobos mailing list >> phobos at puremagic.com >> http://lists.puremagic.com/mailman/listinfo/phobos > _______________________________________________ > phobos mailing list > phobos at puremagic.com > http://lists.puremagic.com/mailman/listinfo/phobos |
January 11, 2011 [phobos] std.string.cmp | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Roberts | Fixed.
Andrei
On 1/10/11 11:40 PM, Brad Roberts wrote:
> Sigh. The reverted version doesn't build on 64 bit:
>
> std/string.d(150): Error: cannot implicitly convert expression (s1.length -
> s2.length) of type ulong to int
> std/regexp.d(1714): Error: template instance
> std.string.icmp!(char,immutable(char)) error instantiating
>
> I agree that sizediff_t is much more convenient. Maybe it is better to go ahead and change the opCmp return type.
>
> On 1/10/2011 11:11 PM, Andrei Alexandrescu wrote:
>> I reverted to int. I was worried about a slight inefficiency but I guess it's hardly measurable.
>>
>> Andrei
>>
>> On 1/10/11 10:56 PM, Brad Roberts wrote:
>>> Hrm.. I think I'd like to object to today's change of std.string.cmp to return sizediff_t rather than int. The reason.. Object.opCmp returns int. So, using cmp is needlessly painful. A simple cast is dangerous.. consider what happens if some how the cmp returns a multiple of 2^32. But I guarantee that a simple cast is what most people that run into the mismatch will do.
>>>
>>> Thoughts?
>>> _______________________________________________
>>> phobos mailing list
>>> phobos at puremagic.com
>>> http://lists.puremagic.com/mailman/listinfo/phobos
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
|
Copyright © 1999-2021 by the D Language Foundation