cxxopts icon indicating copy to clipboard operation
cxxopts copied to clipboard

Use of string_view's - documentation

Open eyalroz opened this issue 2 years ago • 5 comments

Can one reliably use values which are string_view's? Where the default value is a non-owning reference, and so is the parsed value?

The Wiki should clarify this point IMHO.

eyalroz avatar Aug 09 '22 14:08 eyalroz

Can you give me an example of what you would like to do?

jarro2783 avatar Aug 09 '22 21:08 jarro2783

options.add_options()("filename", "description", cxxopts::value<std::string_view>())

and later

my_sv parse_result["filename"].as<std::string_view>();

and for that to work.

eyalroz avatar Aug 09 '22 21:08 eyalroz

At the moment that won't work because the strings passed around are a temporary constructed as the command line is looked at. I'm not sure how much work it would be to make it possible, because there are also the default and implicit values to deal with in the same code.

jarro2783 avatar Aug 09 '22 21:08 jarro2783

@jarro2783 : Ok, this is not an issue about making it work - just about mentioning whether it works on the Wiki page about options.

eyalroz avatar Aug 09 '22 21:08 eyalroz

Ok sure. I'll add it to the wiki.

jarro2783 avatar Aug 10 '22 06:08 jarro2783