What would you like?
Two small, low-risk idiom improvements:
- Add
[[nodiscard]] to query/accessor methods whose return value should never be silently
dropped.
- 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).
What would you like?
Two small, low-risk idiom improvements:
[[nodiscard]]to query/accessor methods whose return value should never be silentlydropped.
std::string_viewfor read-only string parameters where it doesn't conflict with theexisting
std::string-keyed maps /shared_ptrAPIs.Use case / motivation
[[nodiscard]]turns "called a getter and ignored the result" (often a bug) into a compilerwarning — especially valuable for
clone(),getParameters(),getComponent*(), andtoString().string_viewavoids needlessstd::stringallocations for read-only arguments.Both are cheap, incremental modernizations.
What's missing today?
[[nodiscard]]is used in a few places (e.g. some parametertoString()declarations) but isabsent from most query methods (
Element::clone(),getParameters(),getComponent(),getComponentPtr(),getInputs(), etc.). There is zerostd::string_viewusage; read-onlystring params are uniformly
const std::string&(already fine, butstring_viewis the moderndefault for non-owning reads).
Possible approach
[[nodiscard]]to const query methods acrossinclude/elements/element.h,include/simulation/simulation.h, the parameter headers, and visualization getters. Build andfix any newly-surfaced discarded-result warnings.
string_view: convert genuinely read-only string parameters that are only inspected (notstored, not used as a map key, not forwarded to a
std::string&-taking API). Do not touchthe component-name / element-id keys used to index
std::unordered_map<std::string, ...>(astring_viewoverload there would just rebuild astd::stringand add no value). Keep thisconservative.
Verifiable end state: core query methods are
[[nodiscard]]; a handful of read-only stringparameters use
std::string_viewwhere it's a clean win; the build is warning-clean. Part ofthe modern-C++ idioms roadmap (Phase 2).