refactor(util): replace SFINAE with C++20 concepts in packed_vector.hpp#7631
Merged
Conversation
Replace std::enable_if_t<std::is_integral<T>::value> and T::value_type SFINAE patterns with std::integral concept and requires clauses. Also replace the enable_if on reserve() with a direct requires clause on the class template parameter, eliminating the artificial bool template param. Part of #7530
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors include/util/packed_vector.hpp to replace several SFINAE-based overload constraints with C++20 concepts/requires-clauses, aiming to improve readability and diagnostics while keeping runtime behavior the same.
Changes:
- Replace
std::enable_if_t<std::is_integral<...>>overload constraints withrequires std::integral<T>/requires (!std::integral<T>). - Replace the
reserve()SFINAE pattern (with an auxiliarybool enabledtemplate parameter) with a directrequires(Ownership != storage::Ownership::View)constraint. - Minor formatting/one-liner refactors for small operators/helpers.
Comments suppressed due to low confidence (1)
include/util/packed_vector.hpp:97
- This overload should be constrained to types that have a nested
value_type(as it was with the oldtypename T::value_type* = nullptrSFINAE). With only!std::integral<T>as a constraint, unsupported types (e.g. enums, floating-point) will produce hard errors in the function body.
template <typename WordT, typename T>
inline WordT set_upper_value(WordT word, WordT mask, std::uint8_t offset, T value)
requires(!std::integral<T>)
{
static_assert(std::is_unsigned<WordT>::value, "Only unsigned word types supported for now.");
return (word & ~mask) |
((static_cast<WordT>(static_cast<T::value_type>(value)) >> offset) & mask);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+47
to
+50
| template <typename WordT, typename T> | ||
| inline T get_lower_half_value(WordT word, | ||
| WordT mask, | ||
| std::uint8_t offset, | ||
| typename T::value_type * = nullptr) | ||
| { | ||
| return T{static_cast<T::value_type>((word & mask) >> offset)}; | ||
| } | ||
| inline T get_lower_half_value(WordT word, WordT mask, std::uint8_t offset) | ||
| requires(!std::integral<T>) | ||
| { return T{static_cast<T::value_type>((word & mask) >> offset)}; } |
Comment on lines
57
to
63
| template <typename WordT, typename T> | ||
| inline T get_upper_half_value(WordT word, | ||
| WordT mask, | ||
| std::uint8_t offset, | ||
| typename T::value_type * = nullptr) | ||
| inline T get_upper_half_value(WordT word, WordT mask, std::uint8_t offset) | ||
| requires(!std::integral<T>) | ||
| { | ||
| static_assert(std::is_unsigned<WordT>::value, "Only unsigned word types supported for now."); | ||
| return T{static_cast<T::value_type>((word & mask) << offset)}; | ||
| } |
Comment on lines
81
to
88
| template <typename WordT, typename T> | ||
| inline WordT set_lower_value( | ||
| WordT word, WordT mask, std::uint8_t offset, T value, typename T::value_type * = nullptr) | ||
| inline WordT set_lower_value(WordT word, WordT mask, std::uint8_t offset, T value) | ||
| requires(!std::integral<T>) | ||
| { | ||
| static_assert(std::is_unsigned<WordT>::value, "Only unsigned word types supported for now."); | ||
| return (word & ~mask) | | ||
| ((static_cast<WordT>(static_cast<T::value_type>(value)) << offset) & mask); | ||
| } |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7631 +/- ##
==========================================
+ Coverage 90.83% 94.23% +3.40%
==========================================
Files 484 484
Lines 37816 37816
==========================================
+ Hits 34350 35637 +1287
+ Misses 3466 2179 -1287 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Closes #7533
Part of #7530
Replace all
std::enable_if_t<std::is_integral<T>::value>andtypename T::value_type * = nullptrSFINAE patterns withrequires std::integral<T>/requires (!std::integral<T>)clauses. Also replace theenable_ifSFINAE onreserve()with a direct trailing requires clause on the class template parameter, eliminating the artificialbool enabledtemplate parameter.🤖 Generated with Claude Code, Claude Sonnet 4.6
Tasklist