Allow std::string "name" arguments for ParmParse methods#4695
Allow std::string "name" arguments for ParmParse methods#4695WeiqunZhang merged 8 commits intoAMReX-Codes:developmentfrom
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.
The c_str() here is also redundant.
|
Yup, I missed a few redundant c_str()'s the first time, in |
Summary
The
ParmParseconstructor accepts argumentprefix == std::string. But once the object is created, methods on it requirechar *objects for thenameargument, leading to code like:The proposed patch adds wrappers to allow arguments to
ParmParsemethodsget,query, etc, to allow thenameargument 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::stringinterface for the two-name version ofget:because with
stringvalues for the first two arguments and anintvalue 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
getis that in the two-name version both names arechar*and in the template the second argumentrefisstd::string, allowing the first argument to bestringbreaks 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_fallbackorget2or similar.Checklist
The proposed changes: