Skip to content

[Feature] Expand [[nodiscard]] and adopt std::string_view for read-only params #74

Description

@Jgocunha

What would you like?

Two small, low-risk idiom improvements:

  1. Add [[nodiscard]] to query/accessor methods whose return value should never be silently
    dropped.
  2. Use std::string_view for read-only string parameters where it doesn't conflict with the
    existing std::string-keyed maps / shared_ptr APIs.

Use case / motivation

[[nodiscard]] turns "called a getter and ignored the result" (often a bug) into a compiler
warning — especially valuable for clone(), getParameters(), getComponent*(), and
toString(). string_view avoids needless std::string allocations for read-only arguments.
Both are cheap, incremental modernizations.

What's missing today?

[[nodiscard]] is used in a few places (e.g. some parameter toString() declarations) but is
absent from most query methods (Element::clone(), getParameters(), getComponent(),
getComponentPtr(), getInputs(), etc.). There is zero std::string_view usage; read-only
string params are uniformly const std::string& (already fine, but string_view is the modern
default for non-owning reads).

Possible approach

  • Add [[nodiscard]] to const query methods across include/elements/element.h,
    include/simulation/simulation.h, the parameter headers, and visualization getters. Build and
    fix any newly-surfaced discarded-result warnings.
  • For string_view: convert genuinely read-only string parameters that are only inspected (not
    stored, not used as a map key, not forwarded to a std::string&-taking API). Do not touch
    the component-name / element-id keys used to index std::unordered_map<std::string, ...> (a
    string_view overload there would just rebuild a std::string and add no value). Keep this
    conservative.

Verifiable end state: core query methods are [[nodiscard]]; a handful of read-only string
parameters use std::string_view where it's a clean win; the build is warning-clean. Part of
the modern-C++ idioms roadmap (Phase 2).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions