[odb-users] Wrapping existing members with std::atomic<>

Boris Kolpackov boris at codesynthesis.com
Fri Jul 14 03:58:09 EDT 2017


Andrew Cunningham <andrew at a-cunningham.com> writes:

>                 I need to take some of my 'existing' persistent member
> variables (typically int and bool) and wrap them in std::atomic<> without
> messing with my schema.

I think the "proper" way to handle this would be to define the
odb::wrapper_traits specialization for std::atomic, similar to
nullable, optional, smart pointers, etc. For an example, see the
specialization for boost::optional in libodb-boost (files of
interest are optional.options and optional/wrapper-traits.hxx in
the odb/boost/ subdirectory). Except in your case it won't be a
NULL handler.

There is one snag with this approach: the odb::wrapper_traits
interface expects you to return references to the underlying
value. I think there is a way to make it work if you don't
need atomicity during database operations. Is this a reasonable
assumption in your case?

Boris



More information about the odb-users mailing list