Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop const from named() and positional() (or have it both ways?) #55

Closed
xparq opened this issue Nov 5, 2023 · 0 comments
Closed

Drop const from named() and positional() (or have it both ways?) #55

xparq opened this issue Nov 5, 2023 · 0 comments

Comments

@xparq
Copy link
Owner

xparq commented Nov 5, 2023

const std::vector<std::string>& positional() const { return unnamed_params; }
//! Note: std::map[key] would want to create a key if not yet there,
//! so named()[...] would fail, if const! But constness it is... (for consistency).
//! Use the op() and op[] accessors for direct element access!
const std::map<std::string, std::vector<std::string>>& named() const { return named_params; }

It's pretty orthodox to have them always const. I mean it's yours, change it all you want! :) Especially for #54!...

I can imagine use cases where a pristine command-line, safe from tampering, is nice to have, but as soon as you have the modifying methods, the same object is no longer tamper-proof anyway: just having const accessors, too, won't help. ;)
So, just copy your command-line to a const object if you want a safe reference.

Going with non-const only... (You'll get your compilation errors all right when trying to actually use those methods on a const obj.)
-> Err... OK, but then... No... Other const accessors do call these, so I still need the const pairs after all, too... :-/

@xparq xparq changed the title Drop const from named() and positional() (or have both) Drop const from named() and positional() (or have both?) Nov 5, 2023
@xparq xparq changed the title Drop const from named() and positional() (or have both?) Drop const from named() and positional() (or have them both ways?) Nov 5, 2023
@xparq xparq changed the title Drop const from named() and positional() (or have them both ways?) Drop const from named() and positional() (or have it both ways?) Nov 5, 2023
@xparq xparq changed the title Drop const from named() and positional() (or have it both ways?) Drop const from named() and positional() (or have it both ways?) Nov 5, 2023
@xparq xparq closed this as completed in fac5302 Nov 6, 2023
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

No branches or pull requests

1 participant