Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-01-18 13:33:35

"Pavel Vozenilek" <pavel_vozenilek_at_[hidden]> wrote in message
> Problem:
> ----------
> Often one would like to have some data value associated with a
> E.g. with list of window controls one may find handy to have
pointer to
> parent
> window "be somewhere within" the list.
> Current Solutions:
> --------------------
> a) Use std::pair<list<WindowControl>, Window*> pair. But it makes
> accessing
> the list more clumsy (add .first everywhere). It is pain if
needed in
> the middle of
> a project, even more if the need for associated pointer
> (and reappears again).

Why not:

    struct WindowList : list<WindowControl*> : noncopyable {
        WindowList() : parent(0) { }
        WindowControl* parent;


I know it violates the dictum 'never derive from a concrete class',
but it seems fairly harmless. Of course, you might have to define your
own constructors. And if you dispense with noncopyable you have to
write a copy-assignment operator.

> Sample Implementation:
> ---------------------------
> Changing container class is relatively easy. I attached container
> (array of 2 items) that can use associated data as example (tested
> Intel C++ 7.0).

Could you post it at Yahoo? My virus software ate your attachment (and
the partially digested version is hard to read :-)


Boost list run by bdawes at, gregod at, cpdaniel at, john at