 |
I went to see a talk by Damien Conway in Holborn a short while ago. It was hosted by the London
Perl Mongers in, of all places, the Conway Hall! Damien talked for a couple of hours on a number
of topics. His main focus was, however, his 'Quantum::Superpositions' library for PERL. This
enabled programmers to use variables that could hold more than 1 value - at the same time!
He demonstrated that using superpositions it was easy to write searches and the like (because the one variable
holds all the values, you just need one conditional 'if X=any(superposition)'. He also demonstrated
various other algorithms using superpositions, such as GCD and prime numbers. It was most intriguing.
On the way home I decided to re-write the library for the C++ community. On 2/6/2001 I finished it!
|
 |
There are two parts to the library, the variable handlers and the quantum manipulators. Without the
latter, the library isn't much more than an exercise in set operations ( 2+{1,2,3} = {3,4,5} ). This code
was written first using the STL vector template. Although it might seem more natural to use the one for
'set' I wanted my first excursion into STL to include more familar ground.
I started by implementing operator overloading to make the code appear natural C++.
Once I had a proof of concept (e.g. {3,4} * {10,20} produced {30,40,60,80} ) I converted the code into
a template, allowing superpositions of any type (and not just ints). I also copied the 'C' code from
the '.cpp' file I was using to test, into the '.h' file for final production. Templated code has to exist
in the '.h', since without it, the compiler can not implement the functions. I discovered this the hard way!
Finally, the quantum code was added. Quite quickly, really. The 'any', 'all' and 'eigenstates' methods
were used (ahem, 'stolen'!) from Damien's PERL original and a number of utility functions (AddRange, for instance)
were added to support the end user.
The demo programs were converted from PERL and uploaded. Throughout, I tried to maintain the spirit
of the PERL, but because the syntax of both languages differ, I decided to maintain a C++ approach to the code
as opposed to trying to mimic PERL.
|