Choice ranges?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Mar 28 12:00:59 PDT 2014


Today I ran into an interesting situation where I have a function f that
needs to return ranges of different types (but identical element types):

	auto f(A...)(A args) {
		...
		if (someCondition)
			return cartesianProduct(x, y)
				.joiner;
		else
			return cartesianProduct(x, y)
				.joiner
				.filter!someFilter;
	}

This obviously can't compile, because the return types are not the same.
(Note that someCondition is only known at runtime.) But abstractly
speaking, it *should* work, because the element type of the returned
range is identical.

So how would I implement something like this?


T

-- 
The fact that anyone still uses AOL shows that even the presence of options doesn't stop some people from picking the pessimal one. - Mike Ellis


More information about the Digitalmars-d-learn mailing list