digitalmars.D.learn - Searching for a T in a T[]
- =?UTF-8?B?Tm9yZGzDtnc=?= (4/4) Jun 22 2016 Is there now algorithm (similar to `canFind`) that can search for
- David Nadlinger (4/7) Jun 22 2016 What about
- =?UTF-8?B?Tm9yZGzDtnc=?= (3/5) Jun 22 2016 My mistake. The reason for the template error message was another
- cym13 (15/19) Jun 22 2016 I don't see why canFind isn't good enough for you, maybe I don't
Is there now algorithm (similar to `canFind`) that can search for a `T` in a `T[]`? Existing `canFind` only supports sub-sequence needles. I'm aware of `std.string.indexOf` but that's only for strings.
Jun 22 2016
On Wednesday, 22 June 2016 at 08:04:34 UTC, Nordlöw wrote:Is there now algorithm (similar to `canFind`) that can search for a `T` in a `T[]`? Existing `canFind` only supports sub-sequence needles.What about — David
Jun 22 2016
On Wednesday, 22 June 2016 at 08:07:51 UTC, David Nadlinger wrote:What aboutMy mistake. The reason for the template error message was another than I though of. Thanks.
Jun 22 2016
On Wednesday, 22 June 2016 at 08:04:34 UTC, Nordlöw wrote:Is there now algorithm (similar to `canFind`) that can search for a `T` in a `T[]`? Existing `canFind` only supports sub-sequence needles. I'm aware of `std.string.indexOf` but that's only for strings.I don't see why canFind isn't good enough for you, maybe I don't get what you want: void main(string[] args) { import std.algorithm: canFind; struct Coord { int x, y; } Coord[] list = [Coord(0, 0), Coord(3, 14), Coord(1, 2), Coord(4, 2)]; assert( list.canFind(Coord(3, 14))); assert( list.canFind(Coord(4, 2))); assert(!list.canFind(Coord(4, 3))); assert(!list.canFind(Coord(-1, 3))); }
Jun 22 2016