feat: introduce std::span for c++20 dependencies - #97
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The span backend is selected per translation unit, which can cause ABI/link mismatches between the compiled library and consumers built under different C++ standards.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR introduces a new SFRAME_NAMESPACE::span abstraction that uses std::span on C++20-capable standard libraries and falls back to gsl_lite::span otherwise, aiming to avoid pulling gsl-lite transitively through public headers on modern toolchains.
Changes:
- Added
include/sframe/span.hto select betweenstd::spanandgsl_lite::spanat compile time. - Updated public API aliases in
include/sframe/sframe.hto use the newspanabstraction (input_bytes/output_bytes). - Updated
include/sframe/vector.hto accept/convert via the newspantype and to construct spans from(pointer, size).
File summaries
| File | Description |
|---|---|
| include/sframe/span.h | New compatibility header that selects std::span vs gsl_lite::span. |
| include/sframe/sframe.h | Switches input_bytes / output_bytes to the new span alias and removes direct gsl-lite exposure. |
| include/sframe/vector.h | Migrates constructors/append/conversions from gsl::span to span. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
fba7b93 to
2d4b293
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The current span.h feature detection checks __cpp_lib_span before including <span>, which can incorrectly select the gsl-lite fallback even when std::span is available.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 2
- Review effort level: Lite
2d4b293 to
508ccf4
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The new feature-detection header can select std::span in non-C++20 language modes based solely on __cpp_lib_span, which can break intended C++17 fallback behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Lite
508ccf4 to
a7386d6
Compare
There was a problem hiding this comment.
🟡 Changes recommended
CI and build configuration should validate/support the C++20 std::span path and avoid overriding integrators’ chosen C++ standard when used as a subproject.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 2
- Review effort level: Lite
| ) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 17) | ||
| set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to build with") |
Use
std::spanwhen available, fall back togsl_lite::spanSummary
Introduces a compile-time selection between
std::span(C++20) andgsl_lite::spanfor the span type used across sframe's public API. Consumers building against a standard library that providesstd::spanno longer pull in<gsl-lite/gsl-lite.hpp>transitively through sframe headers.Motivation
Downstream integrators on modern C++ toolchains (e.g. WebRTC on C++20) do not want gsl-lite in their include graph. Since C++20's
std::spanis a drop-in replacement for the subset ofgsl::spanthat sframe uses, we can select it automatically and keep gsl-lite only as a C++17 fallback.Changes
include/sframe/span.hthat:<version>when available to make feature-test macros visible.__cpp_lib_span >= 202002Lis defined, includes<span>and exposesSFRAME_NAMESPACE::spanas an alias forstd::span.<gsl-lite/gsl-lite.hpp>and aliasesSFRAME_NAMESPACE::spantogsl_lite::span.include/sframe/sframe.handinclude/sframe/vector.h:<gsl-lite/gsl-lite.hpp>include and thenamespace gsl = ::gsl_lite;alias.<sframe/span.h>and use the unqualifiedspanalias (input_bytes/output_bytesunchanged in signature).vector's span conversion operators construct the span from(pointer, size)so the same code compiles under either backend without relying on CTAD deduction differences.