Boost logo

Boost :

From: Joaquín Mª López Muñoz (joaquin_at_[hidden])
Date: 2003-09-11 06:00:48


Jonathan de Halleux ha escrito:

> [snipped]
>
> Very (very) interresting. I know you mention that "it is not intended to
> provide a full-fledged relational database framework" but could it be
> possible to support basic join operations.
>
> Suppose that we have:
>
> struct client
> {
> int id;
> bool operator<(const client& e)const{return id<e.id;}
> };
>
> struct order
> {
> int id;
> int client_id; // foreign key to client
> bool operator<(const order& o)const{return id<o.id;}
> };
>
> Ok, so the indexed sets for these would be:
> typedef indexed_set<
> client,
> index_list<
> unique<identity<client>
> >
> > client_set;
>
> typedef indexed_set<
> order,
> index_list<
> unique<identity<order> >,
> non_unique< tag<client>, member<order,int,&employee::client_id> > >
> > order_set;
>
> Now that I have my two sets, I would like to get all the orders done by a
> particular client ?
>

There is no join going on here. Once you have the id for the client
you only have to do something like:

order_set os;
...
order_set::iterator_type<client>::type it0,it1;
boost::tuples::tie(it0,it1)=os.equal_range(id);

Take a look at example 3 in the docs for a more elaborate
search using intermediate results. Maybe the kind of ops you're
after can be coded with similar techniques.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk