Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #599 (closed defect: wontfix)

Opened 12 years ago

Last modified 11 years ago

tango.core.Array search functions don't allow searching for a B in an A[]

Reported by: Deewiant Assigned to: sean
Priority: minor Milestone: 1.0
Component: Core Functionality Version: 0.99 RC3 Xammy
Keywords: triage Cc:

Description

Consider the following.

struct S {
	int x;

	int opCmp(int y) {
		return typeid(int).compare(&x, &y);
	}
}

S[] array;

Currently, it is impossible to use, say, tango.core.Array.bsearch to find an int in array. Since the template expects S[] and S, this can't even be done by providing a custom predicate.

The issue can be bypassed (by wrapping the int in an S, which is hacky if S contains more members), but it's still functionality I'd like to see.

Change History

09/06/07 17:12:03 changed by sean

  • status changed from new to assigned.

Good point. This is something that has always annoyed me about the C++ algorithms / containers as well. I suppose the correct approach may be to accept any type for the two params and perhaps simply try to verify they are compatible using template magic. It will mean a rather fundamental change to the way this module is written, however, so I'd like to think it over.

05/27/08 21:34:32 changed by larsivi

  • keywords set to triage.

07/25/08 19:43:18 changed by sean

  • status changed from assigned to closed.
  • resolution set to wontfix.

I've decided that this is too fundamental a change to implement. In instances where this sort of behavior is desired, I suggest using the "if" routines instead. For example: "findIf( buf, (T val) {return val == x;} );" where x is an instance of type B.