-
Notifications
You must be signed in to change notification settings - Fork 421
Allow std::string "name" arguments for ParmParse methods #4695
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
Allow std::string "name" arguments for ParmParse methods #4695
Conversation
If we want to support std::string directly, we probably could use std::string_view. Something like
|
Why is string_view better than string? My patch uses std::string, I can change it to string_view but I'd like to understand the rationale. |
You might have misunderstood my comments. The For example,
is arguably better than
|
As for |
Thank you for the clarification. |
9cc7e99
to
ba05760
Compare
I modified the code to use string_view as suggested. Reopening this pull request. |
The approach with "string_view" caused a lot of tests to fail. One issue is that existing code which already calls
generates a "redundant call to c_str" warning
Another issue is that the pyamrex build is failing:
I don't think the If you would be willing to accept the patch with wrapper functions, I will go back to that version. Otherwise I will respectfully close this MR and live with the Please advise, |
The warnings are easy to fix. As for pyamrex, once this is merge, we can fix it. In CI tests, we intentionally treat warnings as errors so that we can fix the warnings. It will not break the user's code unless they also treat warnings as errors. |
Thank you. I understand that the AMReX CI uses If you are not worried about user code producing warnings, I will continue with the string_view approach. |
Sounds good. Those warnings are not even compiler warnings. They are from clang-tidy, which is even more strict on styles. |
Tests/EB_CNS/Source/CNS.cpp
Outdated
while (pp.queryarr("refine_box_lo_"+std::to_string(irefbox), refboxlo)) | ||
{ | ||
pp.getarr(("refine_box_hi_"+std::to_string(irefbox)).c_str(), refboxhi); | ||
pp.getarr("refine_box_hi_"+std::to_string(irefbox).c_str(), refboxhi); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The c_str()
here is also redundant.
Yup, I missed a few redundant c_str()'s the first time, in |
Summary
The
ParmParse
constructor accepts argumentprefix == std::string
. But once the object is created, methods on it requirechar *
objects for thename
argument, leading to code like:The proposed patch adds wrappers to allow arguments to
ParmParse
methodsget
,query
, etc, to allow thename
argument to be astd::string
, so thec_str()
is not needed and the interface is consistent. It also fixes a few mismatches between comments and code.Additional background
Wrappers are provided for all methods except one. It was not possible to add a
std::string
interface for the two-name version ofget
:because with
string
values for the first two arguments and anint
value for the third, this creates an ambiguity with the standardget
:For this reason, a wrapper is not provided for the two-name version of
get
.Currently the only thing that disambiguates this template from the standard
get
is that in the two-name version both names arechar*
and in the template the second argumentref
isstd::string
, allowing the first argument to bestring
breaks this. This is an unforunate feature of the API design.Furthermore I believe this function is somewhat obscure and it should possibly be deprecated or renamed to
get_with_fallback
orget2
or similar.Checklist
The proposed changes: