improving the join function

Simen kjaeraas simen.kjaras at gmail.com
Mon Oct 11 18:28:33 PDT 2010


Daniel Gibson <metalcaedes at gmail.com> wrote:

> (*) Something like
> Range!(Tuple!(T1, T2)) join(T1, T2)(Range!(T1) r1, Range!(T2) r2,  
> BinaryPredicate!(T1, T2) joinPred)
> just pseudo-code, I'm not really familiar with D2 and std.algorithm.
> The idea is you have a Range r1 with elements of type T1, a Range r1  
> with elements of type T2 and a predicate that gets a T1 value and a T2  
> value and returns bool if they match and in that case a Tuple with those  
> two values is part of the Range that is returned.

Once again I see the combinatorial range in the background. Man, why does
this have to be so hard?

That is, your join could be implemented as follows, given the
combinatorial product range combine:


auto join( alias fun, R... )( R ranges ) if ( allSatisfy!( isForwardRange,  
R ) ) {
     return filter!fun( combine( ranges );
}

-- 
Simen


More information about the Digitalmars-d mailing list