[odb-users] reuse inheritance with templated base class

Michael Powell mwpowellhtx at gmail.com
Wed Aug 13 08:45:38 EDT 2014


On Wed, Aug 13, 2014 at 7:02 AM, Boris Kolpackov
<boris at codesynthesis.com> wrote:
> Hi Marcel,
>
> Marcel Nehring <mne at qosmotec.com> writes:
>
>> One of my template classes has a member of type std::map<unsigned int,
>> std::pair<T, std::string>>. ODB could not persist this automatically,
>> so I put the following inside the class' definition:
>>
>> typedef std::pair<T, std::string> Item;
>> #pragma db value(Item)

If you stop and think about how preprocessor and compile time
(template) issues are resolved, this makes perfect sense. ODB does not
have enough information to preprocess the type at that time.

>> And changed the member declaration to std::map<unsigned int, Item>
>>
>> However, this too does not work and gives me a "unable to instantiate
>> composite value class template" error for the typedef line. Any ideas?
>
> I probably haven't explained this well enough in my previous emails.
> ODB only operates on class template instantiations. It doesn't process
> class templates themselves. So having something like this in a class
> template:
>
> typedef std::pair<T, std::string> Item;
> #pragma db value(Item)
>
> doesn't tell ODB anything since this is itself a template (it is
> inside a template and depends on the template parameter T). What you
> need to do is have the value pragma for the instantiation of this.
> Here is what I mean:
>
> template <typename T>
> class base
> {
>   typedef std::pair<T, std::string> Item;
>   //#pragma db value(Item) // This won't work, Item is a "template".
>
>   std::map<unsigned int, Item> map;
> };
>
> typedef base<int> int_base;
> #pragma db object(int_base)
>
> #pragma db value(int_base::Item); // This will work, int_base::Item is
>                                   // an instantiation.
>
> Boris
>



More information about the odb-users mailing list