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

Should StackTrace::operator[](size_t idx) be declared const? #87

Closed
travisdowns opened this issue Nov 17, 2017 · 2 comments
Closed

Should StackTrace::operator[](size_t idx) be declared const? #87

travisdowns opened this issue Nov 17, 2017 · 2 comments

Comments

@travisdowns
Copy link
Contributor

Semantically it seems like StackTrace::operator[](size_t idx) is a const operation, since it is simply returning by value a Trace object constructed out of the current state of the stack traces, but it is not currently declared const.

This impedes some uses, the obvious ones being that you have to pass around a non-const StackTrace object to methods that might use [], but I ran into the case where a StackTrace member of another class couldn't be accessed with operator[] in a const function of the containing class.

The current (Linux) implementation of operator[] doesn't have any problem being declared const. Adding const should be a non-breaking change, although you couldn't rule out that some other implementation would want to make this a physically non-const operation (e.g., caching values, whatever) - but that's where mutable comes in.

@bombela
Copy link
Owner

bombela commented Nov 17, 2017

Seems reasonable, thank you for the detailed proposal. Feel free to propose a pull request :)

@travisdowns
Copy link
Contributor Author

Thanks, I submitted a PR.

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

2 participants