-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add Delegate type #1059
feat: Add Delegate type #1059
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1059 +/- ##
==========================================
+ Coverage 48.54% 48.58% +0.04%
==========================================
Files 339 340 +1
Lines 17380 17400 +20
Branches 8221 8224 +3
==========================================
+ Hits 8437 8454 +17
Misses 3190 3190
- Partials 5753 5756 +3
Continue to review full report at Codecov.
|
I've also been playing with this in Godbolt. First a couple of minor tweaks:
I compared
Anyway, since GCC isn't yet clever enough to optimise the To my eye, Thanks and sorry for the random comments, |
Hey @timadye, no worries I'm super happy about comments like this! I hadn't looked at the objects generated via In terms of the interface: yes, I'm not sure this works with an assignment operator, since the callable has to be given as a template parameter. Lambas with captures cannot be converted to a function pointer, so the only reason I'm able to "capture" the target callable is because it's a compile time parameters. So even an assignment operator which gives the function pointer at runtime wouldn't work, since I can't generate the wrapping lambda that discards the empty instance pointer. Now, I have one overload void connect(function_type callable); already added which takes a callable at runtime, but that callable explicitly has to accept an |
Hi @paulgessinger, Thanks for the interesting discussion. I think the How about this idea: implement a
and maybe also the copy constructor to initialise at construction:
That seems clearer to me, but maybe it's just needless tinkering? I don't know whether Even nicer would be to have a What do you think? |
Hey @timadye, I've added a constructor and an assignment operator from runtime function pointer. I could add a The underlying problem is that this is a value template parameter and not a type, and I'm not sure if they can be deducted somehow, and I'm pretty sure you can't provide explicit template arguments to the constructor. |
Hi @paulgessinger, I'm not really sure how the I suggested I don't feel very strongly about any of this, just suggesting to explore some alternatives in case you found them useful. So if you prefer Thanks, |
PS. were you planning to add the missing |
I feel like having the extra constructor and operator is a good enough tradeoff, so I think I'd stick to this version. I just added the If you're happy, can you approve? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I didn't know if I had permission to approve anything. Let's see if this works :)
This PR changes the way the extension mechanism for the (C)KF work. It switches from templating them on all of these extension structs to using the `Delegate` type to define the interface. At the same time this PR restructures the measurement selection and internal implementation of the `filter` method. Selection should now be more efficient (in place as much as possible) and not make use of our variant `Measurement` type anymore, but operate directly on the track states. This PR is dependent on - #1059 - #1060 - #1061 and includes their changes, so this PR's changeset will reduce once they are merged. I'll have to do some manual rebasing to undo changes needed to make the other 3 PRs standalone, so I'll keep this WIP until that's completed.
This type is intended as a sort-of replacement of
std::function
without the virtual function overhead of that type. This is ultimately meant to support the new extension mechanism for the KF and CKF, where these delegates will be used for the calibrator, smoother, and so on.Delegate type that allows type erasure of a callable without allocation and with a single level of indirection. This type can support:
Note:
Delegate
does not assume ownership of the instance. You need to ensure that the lifetime of the callable instance is longer than that of the @c Delegate.Currently
Delegate
only supports callables that areconst
.The usage of this type looks like this for a free function:
and like this for a member pointer with instance: