-
Notifications
You must be signed in to change notification settings - Fork 430
Implement apply with std 17 #2835
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
Conversation
6ed414e to
569b615
Compare
include/xtensor/utils/xutils.hpp
Outdated
| { | ||
| return self(self, std::size_t{i + 1}, t...); | ||
| } | ||
| XTENSOR_THROW(std::runtime_error, "Index applied to tuple of insufficient length"); |
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.
@JohanMabille I think the noexcept specification here was too restrictive. We need to provide some way of indicating when index exceeds sizeof...(S). In the old implementation I think we would simply get an access violation which is not ideal.
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.
The initial idea was to disable all checks to get the most opitmized generated code; I don't remember whether this function is used in critical parts of the code, so I cannot say for the NOEXCEPT, but I think we should prefer XTENSOR_ASSERT to XTENSOR_THROW.
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.
Moved to assert. Clang compiles this code nicely... MSVC was a bit of a mess but I'm not sure if it's a code generation issue or just noise.
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.
This is a link to the generated code. https://godbolt.org/z/sMdT517G4
It can calulate the result at compile time. Can I say it is the optimal solution then?
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.
Haha yeah I think so ;)
| { | ||
| using FT = std::add_pointer_t<R(F&&, const std::tuple<S...>&)>; | ||
| static const std::array<FT, sizeof...(I)> ar = {{&apply_one<R, F, I, S...>...}}; | ||
| return ar[index](std::forward<F>(func), s); |
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.
Potential access violation if index > I - 1.
include/xtensor/utils/xutils.hpp
Outdated
| return std::apply( | ||
| [&](const S&... args) -> R | ||
| { | ||
| return [&](const auto&... t) -> R |
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.
Why do we need an additional lambda here? Can't we have the implementation directly in the lambda passed to std::apply ?
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.
Oops. Yeah... My bad.
12be501 to
cbf4fc0
Compare
|
@JohanMabille I restored the noexcept specification and used an ASSERT as requested. Should be good to go! |
|
Moved the noexcept assert to static assertions as they are known at compile time. |
9befbea to
464a7c5
Compare
|
Thanks a lot! |
Checklist