From: Vertleyb (vertleyb_at_[hidden])
Date: 2002-04-27 14:44:16
We used template meta-programming technics to implement a library that
defines a type-safe "relational table" container, as well as the full set of
relational operations on such containers.
Any type that can be used in an STL container, can be used as a column type.
For example, one could define a table like following:
using namespace rel;
list<c2> > > > table_t;
The result will be:
The rel::tuple class differs from tuples::tuple, and is based on the idea of
loki::GenScatterHierarchy suggested by Andrei Alexandrescu (In fact, all the
idea of writing the library was inspired by this book). We didn't used loki
though, since we wanted the library compiled by MSVC (because of the same
reason we use our own implementation of typelist, select, etc.). The tuple
class, therefore, is designed as following:
Each column is represented by a class. The above COLUMN macro unwrappes
into something like this:
class c1 : public column<int>
As is clear from the example, columns are placed into a typelist, and passed
to the tuple class template, who inherits from all of them. Then
static_cast is used
to access individual fields.
We believe using classes as column identifiers is quite benefitial, since
classes are much easier to operate at compile time than strings. We found
no limitations so far.
Each operation is itself a "table", so it's possible to combine them,
something like this:
print(projection<list<c1> >(cross_product(tab1, tab2)));
The library now compiles with MSVC and G++ (thanks to the idea of
"identity", "borrowed" from mpl, the number of #ifdefs is minimal), and
implements the following relational operations:
as well as some additional operations and utilities:
-fast selection and join based on the sort order
-print, serialization, etc.
We beleve there is a range of tasks, where one could benefit from the
relational algebra without the need to use an external database and ODBC.
For such applications our library provides the benefits of consistency and
type safety, ensured by the compiler.
Please let us know if there is any interest in such a library.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk