refactor: replace remaining std::enable_if patterns with C++20 concepts#7645
Conversation
…ts/requires Replace all 6 remaining std::enable_if SFINAE patterns across 4 files with C++20 requires-clauses using standard concepts: - include/util/integer_range.hpp: enable_if<is_integral> -> requires std::integral<Integer>; replace <type_traits> with <concepts> - include/util/json_deep_compare.hpp: enable_if<!is_same> -> requires (!std::same_as<T1, T2>); add <concepts> header - include/guidance/turn_data_container.hpp: enable_if<Ownership==Container> -> requires(Ownership != View); the original enable_if was missing ::type (non-functional), actual behavior constrains out only View since both Container and External map to std::vector internally - include/server/api/parameters_parser.hpp: enable_if<is_parameter_t> -> requires is_parameter_t<ParameterT>::value Build: 117/117 targets compile, all 29 tests pass. Refs: #7530
There was a problem hiding this comment.
Pull request overview
This PR completes the repository’s remaining targeted SFINAE (std::enable_if) cleanups by replacing the last few patterns with C++20 requires-clauses / standard concepts, making template constraints explicit and improving diagnostics.
Changes:
- Replaced
std::enable_if-based constraints with C++20 concepts/requiresin utility and API headers. - Updated
TurnDataContainerImplmutating methods to be properly constrained viarequires(Ownership != View)(fixing the prior ineffectiveenable_ifusage). - Simplified constrained templates by removing dummy enable_if parameters and using direct constraint expressions.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| include/util/integer_range.hpp | Constrains irange() to std::integral via requires and drops enable_if usage. |
| include/util/json_deep_compare.hpp | Uses requires(!std::same_as<T1, T2>) for the cross-type comparator overload. |
| include/guidance/turn_data_container.hpp | Correctly constrains push_back()/append() to non-View ownership using requires. |
| include/server/api/parameters_parser.hpp | Replaces enable_if template parameters with requires constraints for parseParameters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #include <iterator> | ||
| #include <type_traits> | ||
| #include <concepts> |
There was a problem hiding this comment.
Fixed in the follow-up formatting commit (1cce17647) — <concepts> is now before <iterator>.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7645 +/- ##
==========================================
- Coverage 94.20% 90.80% -3.41%
==========================================
Files 483 483
Lines 37670 37670
==========================================
- Hits 35487 34205 -1282
- Misses 2183 3465 +1282 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
1cce176 to
85bf69d
Compare
Summary
Completes the SFINAE → C++20 concepts migration started in #7529 by replacing the last 6
std::enable_ifpatterns across 4 files.Changes
include/util/integer_range.hppenable_if<is_integral<Integer>>requires std::integral<Integer>include/util/json_deep_compare.hppenable_if<!is_same<T1,T2>>requires(!std::same_as<T1,T2>)include/guidance/turn_data_container.hppenable_if<Ownership==Container>(×2)requires(Ownership != View)include/server/api/parameters_parser.hppenable_if<is_parameter_t<T>>(×2)requires is_parameter_t<T>::valueNotable: turn_data_container.hpp fix
The original
enable_ifwas missing::type(std::enable_if<cond>instead ofstd::enable_if<cond>::type), making it a no-op —push_back()andappend()were always available regardless ofOwnership. BothContainerandExternalmap tostd::vectorinternally (onlyViewmaps to non-mutablevector_view), so the correct constraint isOwnership != View.Verification
enable_if/void_t/is_detectedpatterns remain in OSRM source codeCloses #7530
🤖 Claude Code, deepseek-v4-pro