Set Intersection and Set Difference on Compile-Time lists

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 25 10:18:25 PDT 2017


On Tue, Apr 25, 2017 at 05:08:36PM +0000, David Sanders via Digitalmars-d-learn wrote:
> I have two compile-time lists of types. How do I find their set
> intersection (to determine if one is a subset of the other) and their
> set difference? See the block comments below:

What's your definition of set intersection / set difference? Is order
important?  For example, is (float, int) a subset of (int, int, float),
or do you only consider (int, float) to be a subset of (int, int,
float)?  Also, is (int, int, float) the same thing as (int, float) or
are duplicates in the list considered to be distinct set members?

If order is not important, can the lists be assumed to be sorted?

If order is not important and the lists are not sorted, you may run into
trouble with this kind of code, because you'd need to implement O(n^2)
algorithms for computing subsets / set differences, and given the way
templates are currently implemented, this may quickly exhaust available
memory in the compiler.

Given what you're trying to achieve, you *may* have better luck
implementing your type arithmetic using string manipulations, and then a
mixin at the end to turn it back into a type list.


--T


More information about the Digitalmars-d-learn mailing list