|
Boost : |
Subject: Re: [boost] quince: queries in C++ expressions
From: pfultz2 (pfultz2_at_[hidden])
Date: 2014-07-17 12:11:45
> If you can do *that* with Boost.Fusion then perhaps you can show us the
> code that does it, and we discuss costs and benefits.
Sure. You just access the field by using the key. Here is a quick-and-dirty
example here(I haven't compiled it yet, but it should communicate the idea):
https://gist.github.com/pfultz2/cfc447c7ccfa8ac2e76f
So then you should be able to write:
table<person> persons;
for(const person& p:persons.where(at_key<fields::age>(persons) == 60))
{
...
}
Another idea is to generate the member in with the key, perhaps something
like
this:
#define QUINCE_GEN_KEY(name, ...) \
struct name : __VA_ARGS__ \
{ \
template<class T> \
struct lazy \
{ \
T name; \
}; \
};
Then you can use the fusion keys to compose a class that inherits from each
lazy member, so you could still support accessing it using the `->`
operator.
I don't show an example here.
However, the first approach I think is sufficient.
> I mean, if I were to take the approach of implementing QUINCE_MAP_CLASS
> and QUINCE_MAP_CLASS_WITH_BASES by (a) using Boost.Fusion to define some
> kind of tuple, and then (b) using some other means to turn that tuple
> into the class I need, then I expect it would all be done in one place,
> _viz._ inside the definition of quince's private macro
> QUINCE_DEFINE_CLASS_MAPPER_WITH_BASES. So I would be introducing a
> dependency on Boost.Fusion for the sake of changing one point in my code.
You wouldn't generate your mapper class using the preprocessor, you can just
generate it using C++ template metaprogramming. Perhaps, you would use the
preprocessor to generate the keys, but not the mapper or table class(as I
show
in my little example).
Boost.Fusion does a great job of handling product types, which an ORM would
need. It seems unnecessary to reinvent the wheel here.
-Paul Fultz II
-- View this message in context: http://boost.2283326.n4.nabble.com/quince-queries-in-C-expressions-tp4665143p4665260.html Sent from the Boost - Dev mailing list archive at Nabble.com.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk