www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Set and Ranges template.

reply Fredrik Olsson <peylow gmail.com> writes:
Ddoc documentation:
Actual implementation:

I whipped up a module with templates for Ranges and Sets. Ranges are 
only useful for numerical values. Sets can be used for any value; a set 
of {1, 2, 3} is just as valid as a set of {green, whale, 42}.

Currently only empty and finite ranges are supported (Infinite set if 
you make a range over real numbers), infinite and non continuous ranges 
would be nice, but that is a task for another day. Unions, intersection, 
complements, membership test and iterations can naturally be done on 
sets. As well as construction a set from a range non continuous range.

Empty, finite, and infinite sets are supported. Unions, intersections, 
unary and binary complements, membership tests, and iterations over set 
members supported.

Three classes are used in combination to allow for full naive set algebra;
Set - For finite sets.
FunctionSet - An infinite set with members defined by function.
CombiningSet - An infinite set construction by combining sets.

The optimal set class is constructed for each operation (union, 
intersection, etc). Maybe CombinedSet should be named ComputedSet?

Three global sets provided;
evenIntSet - A set of all even integers.
oddIntSet - A set of all odd integers.
primeIntSet - A set of all primes.

Comments, and bug hunt requested :)

// Fredrik
Jul 08 2006
parent Fredrik Olsson <peylow gmail.com> writes:
Small additional comments:

Is it a bug in GDC or am I using Templates wrong? When putting the 
templates in a separate module I get linking errors when compiling with 
template instantiations not originally used by the imported module.
For example:
/usr/bin/ld: Undefined symbols:

Also i need to make "static if"s on numerical (any real or integer type) 
and on integers (Only integer but all types). How do I do this in an 
easy way?

// Fredrik
Jul 08 2006