Skip to content

refactor(util): replace SFINAE with C++20 concepts in packed_vector.hpp#7631

Merged
DennisOSRM merged 2 commits into
masterfrom
sfinae-concepts-packed-vector
Jun 21, 2026
Merged

refactor(util): replace SFINAE with C++20 concepts in packed_vector.hpp#7631
DennisOSRM merged 2 commits into
masterfrom
sfinae-concepts-packed-vector

Conversation

@DennisOSRM

Copy link
Copy Markdown
Collaborator

Issue

Closes #7533
Part of #7530

Replace all std::enable_if_t<std::is_integral<T>::value> and typename T::value_type * = nullptr SFINAE patterns with requires std::integral<T> / requires (!std::integral<T>) clauses. Also replace the enable_if SFINAE on reserve() with a direct trailing requires clause on the class template parameter, eliminating the artificial bool enabled template parameter.

🤖 Generated with Claude Code, Claude Sonnet 4.6

Tasklist

  • self-review code for correctness and following the coding guidelines
  • add tests (existing tests cover both integral and Alias types)
  • review
  • adjust for comments

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
Copilot AI review requested due to automatic review settings June 21, 2026 15:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with requires std::integral<T> / requires (!std::integral<T>).
  • Replace the reserve() SFINAE pattern (with an auxiliary bool enabled template parameter) with a direct requires(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 old typename T::value_type* = nullptr SFINAE). 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 thread include/util/packed_vector.hpp Outdated
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

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.23%. Comparing base (b9d7303) to head (44dfa64).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@DennisOSRM DennisOSRM merged commit 3049880 into master Jun 21, 2026
46 of 47 checks passed
@DennisOSRM DennisOSRM deleted the sfinae-concepts-packed-vector branch June 21, 2026 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SFINAE -> Concepts: PoC: packed_vector to concepts

2 participants