Choice ranges?

Meta jared771 at gmail.com
Fri Mar 28 12:27:24 PDT 2014


On Friday, 28 March 2014 at 19:02:48 UTC, H. S. Teoh wrote:
> 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

You could try using std.variant.Algebraic. I've used it 
successfully before, but it's a bit clumsy and out of date.


More information about the Digitalmars-d-learn mailing list