Comment #0 by andrej.mitrovich — 2013-02-25T16:13:37Z
In one of my templated functions I've misused the hasLength template to figure out if I can call ".empty" on a type:
void add(E elem)
{
static if (hasLength!E)
if (elem.empty)
return;
// do something with 'elem'
}
Unfortunately this won't work with strings because hasLength returns false for strings (it's deliberate, but I missed this part of the docs).
Anyway the proper template I should use is 'hasEmpty', which is missing from phobos.
Comment #1 by andrej.mitrovich — 2013-02-25T16:20:05Z
I don't know that it's necessarily a bad idea to add this, but _all_ ranges have empty by definition. isInputRange requires it, so if you're dealing with range-based stuff, there's no point in checking for hasEmpty. It's already guaranteed.
Comment #3 by andrej.mitrovich — 2013-02-25T17:06:49Z
(In reply to comment #2)
> I don't know that it's necessarily a bad idea to add this, but _all_ ranges
> have empty by definition.
Hmm yeah, isInputRange would actually work here. Knowing this now I'm on the fence of whether the enhancement is worth adding. Perhaps non-range types could implement "empty", but in that case this doesn't belong to std.range.
I guess we can close it then.