[odb-users] Use of shared database pointer in lazy_ptr

Boris Kolpackov boris at codesynthesis.com
Fri Dec 14 06:57:52 EST 2012

Hi Paul,

Stath Paul <pstath at axxcelera.com> writes:

> I was wondering if there is any way I can utilize a shared pointer to
> odb::database when I need to construct a lazy pointer.

No, there is no way. Short of rolling out your own lazy_ptr implementation
(in fact, you can probably "wrap" one provided by ODB). Which is perfectly
doable. So if you want to go that route, I can give you more pointers.

> I store my odb::database in a shared pointer. When I construct a lazy
> pointer, I don't like to borrow the reference to the database from the
> shared pointer. Seems sloppy, since it may be possible to deconstruct
> the shared pointer to be database, but still have a dangling
> pointer to the database in the lazy pointer.

We have to draw a line somewhere. ODB cannot be infinitely flexible
and customizable (which shared_ptr?, can I also use weak_ptr? etc,
etc). So with odb::database we say that it should outlive any other
ODB instance that may reference it (lazy_ptr, session, prepared query,
etc). For most application, I believe, this is a fairly natural


More information about the odb-users mailing list