Modernize: switch read-only accessors from vector const& to std::span (issue #62 item 3) - #64
Conversation
…ssors, noexcept on RecipeView delegates
|
Pre-merge fixup (commit 404393f) addresses review:
m3 deliberately deferred: 135/135 tests still pass. |
|
Second-pass review fixup (commit e5d7f83): addresses cpp-pro's Major from REVIEW-pr-62-round2.md — Earlier fixup (commit 404393f) addresses round-1 M1 (span-invalidation comment on m3 ( CI green; 135/135 tests. |
…uction path only
# Conflicts: # include/numsim_codegen/passes/recipe_view.h
Item 3 of #62. Stylistic refactor: read-only accessors now return `std::span` instead of `std::vector const &`. No behaviour change.
Why std::span
What changed
`include/numsim_codegen/recipe.h` (ConstitutiveModel accessors):
```cpp
// before
[[nodiscard]] auto symbols() const -> std::vector const &;
[[nodiscard]] auto outputs() const -> std::vector const &;
[[nodiscard]] auto state_variables() const -> std::vector const &;
[[nodiscard]] auto parameters() const -> std::vector const &;
[[nodiscard]] auto inputs() const -> std::vector const &;
// after
[[nodiscard]] auto symbols() const noexcept -> std::span;
[[nodiscard]] auto outputs() const noexcept -> std::span;
[[nodiscard]] auto state_variables() const noexcept -> std::span;
[[nodiscard]] auto parameters() const noexcept -> std::span;
[[nodiscard]] auto inputs() const noexcept -> std::span;
```
`include/numsim_codegen/passes/recipe_view.h` delegates updated to match.
`` added to both headers' includes.
What didn't change
Verification
135/135 tests pass. No new tests — every consumer iterates the returned range, which span supports identically. Existing call sites in:
all use range-based for or index-based access, both of which work identically on `std::span` and `std::vector const &`.
Migration notes for downstream users
The only breaking change is type-explicit code:
```cpp
// breaks:
std::vector const &syms = model.symbols();
// works:
auto syms = model.symbols(); // span
auto const &syms = model.symbols(); // span (extra const harmless)
for (auto const &s : model.symbols()) ... // unchanged
```
We have no downstream users today; this is the right time for the migration.
Stack
`main ← this`. Independent of PRs #63 (std::format) and the still-to-be-opened std::expected PR.