Multi-argument select()
supports mapped classes as an output
format, as an alternative to std::tuple
s.
The generated SQL is no different, but the classes might afford some
extra convenience, if you like to use meaningful member names instead
of get<0>()
etc.
If C
is a mapped class, with mapped members
m0
, m1
, ... (in
the order they were listed to QUINCE_MAP_CLASS
),
and with no mapped bases, then you can call q.select<
C
>(
exprn0
,
exprn1
,
... )
,
provided that:
q.select(
exprn0
,
exprn1
,
... )
are satisfied, and
C
::
mi
is the same as the result type of exprni
(this is checked at compile time).
q
.select<
C
>(
exprn0
,
exprn1
,
... )
returns a query
with
the following characteristics:
C
.
class_mapper<
C
>
, in which each member
mapper mi
is identical to the respective
exprni
.
q
.select(
exprn0
,
exprn1
,
... )
,
except that what would have gone into member i
of an output std::tuple
now goes into member mi
of an output
C
.
// Somewhere in a namespace, not in a function: struct assortment { point p; float plus; float minus; }; QUINCE_MAP_CLASS(assortment, (p)(plus)(minus)); // Somewhere inside a function: // Use operator* to get points's entire value mapper: // const query<assortment> assortments = points .select<assortment>(*points, points->x + points->y, points->x - points->y); // Classes are statically mapped; therefore assortments->p is not just an // abstract_mapper<point>, it's a class_mapper<point>. So we can use its // class_mapper features, e.g ".x": // const query<float> xs_times_pluses = assortments .select(assortments->p.x * assortments->plus); // assortments->p is strictly identical to *point, // so we can use one instead of the other (stylistically questionable though): // const query<float> xs_times_pluses_again = assortments .select(points->x * assortments->plus);