|
Boost : |
From: Klemens Morgenstern (klemensdavidmorgenstern_at_[hidden])
Date: 2024-11-14 16:51:50
> > I don't exactly know what you mean here. You can use pfr in C++20 for
> > a static_result_set (and describe for earlier standards).
>
> Boost.PFR is a C++14 library, so I don't understand where the C++20
> restriction comes from.
It's because structs get assigned by name (which is C++20 in pfr)
The reason here is that it's too easy to get this wrong, especially
when queries change over time.
If you have small examples with a single table this isn't an issue,
but once you start doing joins,
assigning the result by name will catch bugs.
>
> > I don't think I fully understand. What would `f`/`this` be pointing to
> > when `step` gets called?
>
> This is a simplified implementation of what I meant:
> https://godbolt.org/z/Mb5eqfvW4. Here, the state of the aggregate
> function is stored in the object whose member functions are called,
> and also the arguments are passed separately.
Ok, so you want to implicitly create a new instance of the function every time.
The example you posted could be done like this atm (ignoring the args for now):
struct Count
{
int n = 0;
void step(span<sqlite::value>) { ++n; }
int final() { return n; }
};
struct CountImpl
{
void step(Count & c, span<sqlite::value> sp) { c.step(sp); }
auto final(Count & c) {return c.final(): }
};
Would you think it would help if `CountImpl` could be made a template,
so a user could just write `dynamic_aggregate<Count>()` ?
What's the advantage of using multiple arguments of the same type over a span?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk