Replace =delete with SFINAE for invalid Vec integer methods - #575
Conversation
|
|
7ee36c5 to
33e84ff
Compare
|
I think it's probably unwise to rely on either std::is_floating_point or std::is_integral. We should probably define our own extensible type trait that will capture what we really intend and be user-extensible and future-proof. |
de0bf8a to
326e68b
Compare
|
Thanks @lgritz, I added an is_float_like that defaults to std::is_floating_point with a specialization for half. Let me know if this is along the lines of what you had in mind |
|
Could a reviewer please take a look at this? Wouldn't want it go stale |
|
Apologies for the delay, I've been consumed with other issues. And thanks for you continued efforts! I'm happy to work through the issues. The implementation needs to support I think something like this is the right direction: In and then in and then later: and finally: Also note that this needs to work with C++17 through C++26, and unfortunately some of these trait template change signature, so it's a little tricky. It would also be good to add CI jobs that build with the various C++ standards. Also, be sure to configure your fork of the repo to run the CI on your local branch. That way, you can confirm it works before pushing to the PR. When I find myself in a situation like this where I have to make substantial changes to an already-submitted PR, I often create a second branch, work there until I'm happy, then squash the commits and cherry-pick them over to the branch for the PR. That avoids a lot of noise on the PR. |
What the heck does that mean? |
|
hey both, any updates on this? |
|
My apologies again for letting this drop. This almost working. I copied your branch and made a few extensions to resolve the remaining issues, you can inspect it here: https://github.com/cary-ilm/Imath/tree/refs/heads/sfinae-vec-integer-methods This addresses several issues:
If you'd like feel free to cherry pick my commits there into your branch and push them to the PR. That would require adding my branch to your repo as a remote. Or simply download the files and copy/paste them into your branch, that's fine, too. There is another unrelated outstanding issue with the pybind11 bindings that is causing the CI to fail, affecting all PRs, not just yours. I have a fix that I'll submit shortly, which you can also include. Thanks again for the contribution and your patience. |
…oftwareFoundation#559) Signed-off-by: maychin <chinmay.cc.06@gmail.com> Signed-off-by: chinmaychahar <chinmay.cc.06@gmail.com>
Signed-off-by: chinmaychahar <chinmay.cc.06@gmail.com>
The IMATH_ENABLE_IF macro places () around __VA_ARGS__ in enable_if_t<>. Since the parentheses appear in the method declaration (via IMATHENABLE_IF), they must also appear in the definition, so the two match exactly. Signed-off-by: Cary Phillips <seabeepea@gmail.com>
static_asserts validate that the methods appear for float-like types and do not appear for non-float-like types. This also validates the Vec classes can be instantiated with custom class objects, CustomFLoat and CustomNonFloat, provided that they are accompanied by a specialization of is_float_like<>. Assisted-by: GitHub Copilot CLI (model: Claude Sonnet 5) Signed-off-by: Cary Phillips <seabeepea@gmail.com>
These methods are templates now, so an ordinary method won't work. Signed-off-by: Cary Phillips <seabeepea@gmail.com>
c7815a5 to
796f323
Compare
|
Thanks a lot @cary-ilm, really appreciate you taking the time to work through the remaining issues. I've cherry-picked your three commits and rebased onto latest main |
|
I ran the full CI on my fork first before pushing here and everything's green. Let me know if there's anything else you'd like changed. |
cary-ilm
left a comment
There was a problem hiding this comment.
Everything looks in order, thanks!
* Replace =delete with SFINAE for invalid Vec integer methods (#559) Signed-off-by: maychin <chinmay.cc.06@gmail.com> Signed-off-by: chinmaychahar <chinmay.cc.06@gmail.com> * Add is_float_like trait and use it for SFINAE guards Signed-off-by: chinmaychahar <chinmay.cc.06@gmail.com> * Add () around (is_float_like<S>::value) in definitions in ImathVec.h The IMATH_ENABLE_IF macro places () around __VA_ARGS__ in enable_if_t<>. Since the parentheses appear in the method declaration (via IMATHENABLE_IF), they must also appear in the definition, so the two match exactly. Signed-off-by: Cary Phillips <seabeepea@gmail.com> * Add tests for SFINAE declarations of length(), normalize(), etc static_asserts validate that the methods appear for float-like types and do not appear for non-float-like types. This also validates the Vec classes can be instantiated with custom class objects, CustomFLoat and CustomNonFloat, provided that they are accompanied by a specialization of is_float_like<>. Assisted-by: GitHub Copilot CLI (model: Claude Sonnet 5) Signed-off-by: Cary Phillips <seabeepea@gmail.com> * Use lambas for length(), normalize(), etc. These methods are templates now, so an ordinary method won't work. Signed-off-by: Cary Phillips <seabeepea@gmail.com> --------- Signed-off-by: maychin <chinmay.cc.06@gmail.com> Signed-off-by: chinmaychahar <chinmay.cc.06@gmail.com> Signed-off-by: Cary Phillips <seabeepea@gmail.com> Co-authored-by: Cary Phillips <seabeepea@gmail.com>
Summary
Fixes #559
Replace
= deletetemplate specializations with SFINAE using the existingIMATH_ENABLE_IFmacro forlength(),normalize(),normalizeExc(),normalizeNonNull(),normalized(),normalizedExc(), andnormalizedNonNull()in Vec2, Vec3, and Vec4.Removes the entire
Specializations for VecN<short>, VecN<int>block including the@cond Doxygen_Suppresswrapper which will no longer be needed when SFINAE makes the methods invisible to both the compiler and Doxygen for non-applicable types.Status
Draft PR. I will iterate based on feedback and open questions in #559