That's actually really useful, thankyou Mateusz.
I think it's your first suggestion that I'll end up following, which means
two type_conversion specialisations per domain object, which is a drag, but
hardly the end of the world.
I guess in the second case you mention, I'd be subclassing my domain
object, and casting away constness for from_base operations? I'll have a
think about that, although I am trying to avoid the use of vtables as much
as possible, so that might not be my best bet.
I'm not entirely sure what you mean in your third suggestion -- is that a
continuation of your first (ie., create two containing types, const and
non-const, and specialise for them)? Or am I missing something there?
(Always entirely probable!)
I'm having a think about a custom delegator class, but that could end up
being a lot of work, and leaving me, ultimately, in the same position. I'll
have a think on it, but these things are never as easy in static languages!
:)
And thanks again for your suggestions,
   Doug.


On 14 November 2012 21:58, Mateusz Loskot <mate...@loskot.net> wrote:

> On 14 November 2012 19:04, doug livesey <biot...@gmail.com> wrote:
> > Hi -- I'm trying to implement persistence with SOCI in a C++ project I'm
> > working on, but am coming a little unstuck when saving models that need
> to
> > know their parent's id for persistence. Which is most of the objects!
> > I've tried creating a std::pair (with child and parent domain classes)
> > specialisation for the type_conversion template, and this does work, but
> it
> > requires me to either relax security on my models, or to create a
> > specialisation for const and non-const members.
>
> Generally, that's the way things work with templates.
> Although, you have choices to avoid code duplicate:
>
> - use two different types/names: const_mytype and mytype
>
> - use inheritance, as (counter-intuitively) non-const operations are
> specialisation of const ones, so you can use compile-type polymorphism to
> hide/block const operations in non-const subtype, and provide
> non-const version of operation
>
> - use template specialisation (a canonical way (?)).
>
> Sorry, I'm not really able to give any in-depth insights.
>
> Best regards,
> --
> Mateusz Loskot, http://mateusz.loskot.net
>
>
> ------------------------------------------------------------------------------
> Monitor your physical, virtual and cloud infrastructure from a single
> web console. Get in-depth insight into apps, servers, databases, vmware,
> SAP, cloud infrastructure, etc. Download 30-day Free Trial.
> Pricing starts from $795 for 25 servers or applications!
> http://p.sf.net/sfu/zoho_dev2dev_nov
> _______________________________________________
> soci-users mailing list
> soci-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/soci-users
>
------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
soci-users mailing list
soci-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to