Fwd: [odb-users] Error when trying to use odb compiler on custom class

Boris Kolpackov boris at codesynthesis.com
Tue May 14 22:58:27 EDT 2013


Hi Rafal,

Rafal Grasman <rjg1094 at gmail.com> writes:

> Ah, it works for the ODB compiler but now Visual Studio is complaining on
> the generated header

I tried your example, and, actually, mapping std::tuple is tricky
because it doesn't contain the members directly (like, for example,
std::pair). Rather, it uses base classes to "allocate" the required
number of elements.

So, if you don't have a requirement to use tuples, then it will
probably be much easier and more straightforward to reimplement
this as a struct/class. For example:

#pragma db value
struct ban_type
{
  std::string first;
  unsigned long long second;
  std::string third;
  unsigned long long fourth;
};

You will probably want to use more descriptive names instead of first,
second, etc.

Now, if you must use std::tuple, then it should be possible to map it
using the virtual data member feature in ODB. For example:

typedef std::tuple<std::string,
                   unsigned long long,
                   std::string,
                   unsigned long long> ban_type;

#pragma db value(ban_type) transient
#pragma db member(ban_type::first) virtual(std::string) access(std::get<0> (this))
#pragma db member(ban_type::second) virtual(unsigned long long) access(std::get<1> (this))
#pragma db member(ban_type::third) virtual(std::string) access(std::get<2> (this))
#pragma db member(ban_type::fourth) virtual(unsigned long long) access(std::get<3> (this))

As you can see it is quite verbose.

Above I said "should" instead of "can" because the current version of
ODB (2.2.0) has a bug that prevents this mapping from working. I've
fixed it for the next release of ODB so once 2.3.0 is out, it will
work.

Boris



More information about the odb-users mailing list