Re: Lexicographic comparison of arrays (of chars)

2020-08-02 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 22 January 2020 at 15:11:09 UTC, Jacob Carlborg wrote: BTW, why don't you implement `opCmp` with the built-in comparison operators. Those are going to get lower to a call to `__cmp`. Something like this: int opCmp()(const scope typeof(this) that) const @nogc { auto a =

Re: Lexicographic comparison of arrays (of chars)

2020-01-22 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 22 January 2020 at 15:11:09 UTC, Jacob Carlborg wrote: int opCmp()(const scope typeof(this) that) const @nogc { auto a = this[]; auto b = that[]; return a < b ? -1 : (a > b); } -- /Jacob Carlborg I see. Good to know. Thanks

Re: Lexicographic comparison of arrays (of chars)

2020-01-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 22, 2020 7:50:01 AM MST Per Nordlöw via Digitalmars-d- learn wrote: > On Wednesday, 22 January 2020 at 10:19:38 UTC, Jacob Carlborg > > wrote: > > That looks like it's for internal use. There is a `compare` > > method in the `TypeInfo` of each type. > > Will that incur an

Re: Lexicographic comparison of arrays (of chars)

2020-01-22 Thread Jacob Carlborg via Digitalmars-d-learn
On Wednesday, 22 January 2020 at 14:50:01 UTC, Per Nordlöw wrote: Will that incur an extra runtime cost compared to __cmp? I haven't looked at how `__cmp` is implemented but I would guess there's some extra overhead. Need to get type info and then there will be several virtual method calls

Re: Lexicographic comparison of arrays (of chars)

2020-01-22 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 22 January 2020 at 10:19:38 UTC, Jacob Carlborg wrote: That looks like it's for internal use. There is a `compare` method in the `TypeInfo` of each type. Will that incur an extra runtime cost compared to __cmp?

Re: Lexicographic comparison of arrays (of chars)

2020-01-22 Thread Jacob Carlborg via Digitalmars-d-learn
On Wednesday, 22 January 2020 at 08:44:15 UTC, Per Nordlöw wrote: I just found import core.internal.array.comparison : __cmp; I presume that is a better alternative if Phobos' independence is desired. That looks like it's for internal use. There is a `compare` method in the `TypeInfo`

Re: Lexicographic comparison of arrays (of chars)

2020-01-22 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 22 January 2020 at 08:30:55 UTC, Per Nordlöw wrote: is a suitable definition of `opCmp` for `SSOString` in terms of independence of Phobos' `std.algorithm.comparison.cmp`. I just found import core.internal.array.comparison : __cmp; I presume that is a better alternative if

Lexicographic comparison of arrays (of chars)

2020-01-22 Thread Per Nordlöw via Digitalmars-d-learn
I've implement a small size optimized `string` at https://github.com/nordlow/phobos-next/blob/c35fa4052738af0cd7ad39a9fa715b5ec29c7bba/src/nxt/sso_string.d I'm now wondering whether or not its definition of comparison at