Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR upgrades the codebase to require C++20 as the minimum standard for extension builds. The change modernizes the codebase by replacing older C++17 constructs and string formatting approaches with C++20 features.
Key changes:
- Updates minimum C++ standard requirement from C++17 to C++20
- Replaces
std::ostringstreamstring formatting with C++20std::format - Modernizes template syntax using C++20
requiresclauses instead of SFINAE - Updates build configuration and CI workflows to use C++20
Reviewed Changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| CMakeLists.txt | Updates minimum C++ standard requirement from 17 to 20 |
| src/treespec/unflatten.cpp | Replaces ostringstream with std::format, adds std::span usage |
| src/treespec/treespec.cpp | Extensive modernization with std::format, std::span, std::ranges, and constinit |
| src/treespec/traversal.cpp | Updates string formatting to use std::format |
| src/treespec/serialization.cpp | Uses std::unordered_map::contains instead of find comparison |
| src/treespec/richcomparison.cpp | Replaces std algorithm calls with std::ranges equivalents |
| src/treespec/hashing.cpp | Uses std::unordered_map::contains for cleaner code |
| src/treespec/flatten.cpp | Comprehensive string formatting updates and template parameter renaming |
| src/treespec/constructors.cpp | String formatting modernization and std::ranges usage |
| src/registry.cpp | Updates string formatting and replaces PYBIND11_CONSTINIT with constinit |
| src/optree.cpp | String formatting updates and constinit usage |
| include/optree/treespec.h | Updates function signatures to use std::span and modernizes template parameters |
| include/optree/pytypes.h | Adds std::formatter specializations and modernizes template syntax with requires clauses |
| include/optree/pymacros.h | Replaces PYBIND11_CONSTINIT with constinit |
| include/optree/exceptions.h | Major refactoring using std::source_location and std::format for error handling |
| README.md | Updates documentation to reflect C++20 requirement |
| CPPLINT.cfg | Adds whitespace/braces filter |
| .github/workflows/tests.yml | Removes C++17 compatibility test |
| .github/workflows/lint.yml | Updates clang-tidy to use C++20 |
| .clang-format | Updates standard from c++17 to c++20 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #235 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 14 14
Lines 1416 1416
Branches 175 175
=========================================
Hits 1416 1416 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
9388aa9 to
b3e5183
Compare
|
6887698 to
c0e6a1d
Compare
ce0ec4b to
5af5e9b
Compare
430d021 to
f35b9b6
Compare
74793af to
947195f
Compare
b834e96 to
4caf09f
Compare
b40c207 to
0b08991
Compare
84639eb to
2d05490
Compare
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Description
Raise the minimum C++ standard from C++17 to C++20 and adopt C++20 features throughout the extension codebase.
C++20 features adopted
std::format: Replace allstd::ostringstreamandoperator+string concatenation for error/exception messages withstd::format. Addstd::formatterspecializations forpy::handleandpy::object.std::source_location: Replace__FILE__,__LINE__, and__PRETTY_FUNCTION__macros inInternalErrorwithstd::source_location::current()default parameters.std::span: Replace raw pointer + size pairs (py::object *children, ssize_t num_children) withstd::span<py::object>inMakeNodeand related functions.std::ranges: Replacestd::copy/std::reversewith iterator pairs bystd::ranges::copy/std::ranges::reversewith range arguments.requiresclauses: Replacestd::enable_if_tSFINAE with C++20requiresexpressions in template functions (TupleGetItemAs,ListGetItemAs,DictGetItemAs).std::unordered_map::contains: Replace.find() != .end()pattern with.contains().Build and CI changes
CMakeLists.txt: Raise minimum standard from C++17 to C++20.MACOSX_DEPLOYMENT_TARGET=15.0andIPHONEOS_DEPLOYMENT_TARGET=16.3(required forstd::formatsupport in Apple libc++)..clang-formatstandard toc++20andclang-tidyto use C++20.Motivation and Context
C++20 provides standard library features that simplify the codebase and improve code clarity:
std::formateliminates verbosestd::ostringstreampatterns for string formatting.std::source_locationreplaces non-portable compiler macros (__PRETTY_FUNCTION__) with a standard mechanism.std::spanprovides a safer, more expressive alternative to raw pointer + size parameters.This is a breaking change: C++20 compiler support is now required to build the extension from source.
Types of changes
Checklist
make format. (required)make lint. (required)make testpass. (required)