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

Inconsistent use of type alias. #1507

Closed
DodoMomo opened this issue Mar 8, 2019 · 5 comments
Closed

Inconsistent use of type alias. #1507

DodoMomo opened this issue Mar 8, 2019 · 5 comments
Labels
state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated state: waiting for PR

Comments

@DodoMomo
Copy link

DodoMomo commented Mar 8, 2019

Inside basic_json the alias reference and const_reference are used in inconsistently, for example the method iteration_proxy uses const_reference as a parameter type, while push_back uses const basic_json&.
Which one should be used? I think the non-alias are better and i would like make a PR if you agree.

Sorry about my horrible english.

@nlohmann
Copy link
Owner

That is indeed inconsistent. Thanks for reporting. A pull request would be more than welcome!

@garethsb
Copy link
Contributor

Note that e.g. std::vector defines reference but uses const value_type& in push_back. I've always assumed the rationale was a reference to a stored value vs an input arg.

@nlohmann
Copy link
Owner

I just had a look at the source of <vector>, and it seems they use reference and const_reference internally:

const_reference
operator[](size_type __n) const
{ return *(this->_M_impl._M_start + __n); }

I also tried to do this in basic_json, and I understood this issue to have found spots where I used const basic_json& instead of const_reference somewhere. Looking at #1523, it seems that @DodoMomo wants to go the other way and replace all reference´/const_reference`. I am not sure that this is a good idea.

@DodoMomo
Copy link
Author

In my opinion it will make the code much more clear, unlike vector, basic_json is recursive container so the value_type is really confusing.

@stale
Copy link

stale bot commented Apr 17, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Apr 17, 2019
@stale stale bot closed this as completed Apr 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated state: waiting for PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants