Allow std::string "name" arguments for ParmParse methods #4695
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: