Skip to content

feat: introduce std::span for c++20 dependencies - #97

Open
k-wasniowski wants to merge 1 commit into
cisco:mainfrom
k-wasniowski:use-std-span
Open

feat: introduce std::span for c++20 dependencies#97
k-wasniowski wants to merge 1 commit into
cisco:mainfrom
k-wasniowski:use-std-span

Conversation

@k-wasniowski

Copy link
Copy Markdown
Contributor

Use std::span when available, fall back to gsl_lite::span

Summary

Introduces a compile-time selection between std::span (C++20) and gsl_lite::span for the span type used across sframe's public API. Consumers building against a standard library that provides std::span no 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::span is a drop-in replacement for the subset of gsl::span that sframe uses, we can select it automatically and keep gsl-lite only as a C++17 fallback.

Changes

  • New header include/sframe/span.h that:
    • Includes <version> when available to make feature-test macros visible.
    • When __cpp_lib_span >= 202002L is defined, includes <span> and exposes SFRAME_NAMESPACE::span as an alias for std::span.
    • Otherwise includes <gsl-lite/gsl-lite.hpp> and aliases SFRAME_NAMESPACE::span to gsl_lite::span.
  • include/sframe/sframe.h and include/sframe/vector.h:
    • Drop the direct <gsl-lite/gsl-lite.hpp> include and the namespace gsl = ::gsl_lite; alias.
    • Include <sframe/span.h> and use the unqualified span alias (input_bytes / output_bytes unchanged 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.

Copilot AI lite review requested due to automatic review settings September 9, 2026 11:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.h to select between std::span and gsl_lite::span at compile time.
  • Updated public API aliases in include/sframe/sframe.h to use the new span abstraction (input_bytes / output_bytes).
  • Updated include/sframe/vector.h to accept/convert via the new span type 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.

Comment thread include/sframe/span.h
Copilot AI review requested due to automatic review settings September 9, 2026 12:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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

Comment thread include/sframe/span.h
Comment thread include/sframe/vector.h Outdated
Copilot AI review requested due to automatic review settings September 9, 2026 13:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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

Comment thread include/sframe/span.h
Copilot AI review requested due to automatic review settings September 10, 2026 10:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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

Comment thread .github/workflows/build.yml
Comment thread CMakeLists.txt
)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to build with")
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.

2 participants