On 03/28/14 20:00, 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?

eg
        auto f(A...)(A args) {
                ...
                return cartesianProduct(x, y)
                        .joiner
                        .filter!(a=>somecondition?true:somefilter(a));
        }

artur

Reply via email to