-
Notifications
You must be signed in to change notification settings - Fork 4
changes #3
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
base: master
Are you sure you want to change the base?
changes #3
Conversation
…ak strict-aliasing rules [-Wstrict-aliasing] with 2 lines splitup: Concept *cpt = reinterpret_cast<Concept*>(memory); cpt->~Concept(); - use std::size_t instead of unsigned - align according to alignof(std::max_align_t) - use mutable F to get the following functor compiled: struct Func1 { int operator()(int val) // const { return val * 2; } int a[10]; }; - use static_assert instead of enable_if - add: SmallFun& operator=(F const&f)
You can see it in action in the following benchmark: PS: what commands do I have to use, to get this buckaroo thing working? Thanks! |
I'm compiling with gcc under Linux. Which compiler do you use? Are my changes with |
Thanks for your efforts!
The
It works for your use case but it would break other cases. Checkout the godbolt example and see how the return value of T::operator() changes based on the presence of the mutable keyword. In order to handle both situations correctly, we need a smarter approach. As of the alignment issue, good spot! Would love to get that merged.
|
? |
(edited)
{
T t{};
smallfun::SmallFun<int()> f(t);
std::cout << f() << "\t should get " << t() << std::endl;
}
{
const T t{};
smallfun::SmallFun<int()> f(t);
std::cout << f() << "\t should get " << t() << std::endl;
}
Sorry... I just noticed that this is probably not a problem, since (Oh and by the way... Interesting reading here: |
(edited) I should also mention that the following
(ref) is important! It's one way to fix a bug in your original, where a destructor is not called. The fix is to uncomment line 3 #include "smallfun_changed.hpp" /* mine */ -- it should then print |
I've got a branch called my_experiments: https://github.com/user706/smallfunction/tree/my_experiments |
fix gcc warning warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
with 2 lines splitup:
std::size_t
instead ofunsigned
alignof(std::max_align_t)
mutable F
to get the following functor compiled:(used here: https://github.com/user706/CxxFunctionBenchmark).
I knew what to do here, thanks to @arobenko - ref
static_assert
instead ofenable_if
SmallFun& operator=(F const&f)