-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
refactor: Migrate raw function pointers to std::function #4461
Conversation
…into std_function
7adb306
to
0a1a075
Compare
…into std_function
…into std_function
…into std_function
…into std_function
…into std_function
…into std_function
…into std_function
…into std_function
…into std_function
Maybe it's helpful to seperate the issues when thinking about naming things. There are 2 tensions:
|
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.
Perf results seem good. It makes sense to pass shared_ptr by reference to avoid allocation, locking and copy overhead. I think most people here would have been watching out for that anyway. Looks good to me. Thanks!
This PR replaces several raw function pointers with
std::function
objects.The biggest changes are to the
learner
class, which is now no longer templated. To erase the data type, learner builders will bind the data object to their input functions via a lambda capture. To erase the example type, the lambda will accept apolymorphic_ex
wrapper aroundVW::example*
andVW::multi_ex*
, which implicitly converts back to the original type. The resulting lambda can be stored in astd::function
object with a type which does not depend on DataT nor ExampleT.This removes all undefined behavior around function pointer typecasting.