使用 vm.count() 时,始终存在具有默认值的 Boost 程序选项
我一直在尝试使用 boost::program_options 验证我传递的选项。我的命令有多种模式,每种模式都有可以指定的关联参数。我想做的是确保这些关联的参数与模式一起传递,即
unicorn --fly --magic-wings-threshold
其中 --fly
是模式, --magic-wings-threshold
是相关参数我注意到的是,如果 --magic-wings-threshold
有默认值,例如
("magic-wings-threshold,w", po::value<double>(&wings_thresh)->default_value(0.8, "0.8"),
"Magic wings maximum power"
)
,那么我无法用来
if (vm.count("magic-wings-threshold")( {
// do stuff
}
检测用户是否传递了该参数。
看来默认值参数总是在 vm.count()
中传递和检测。有谁知道解决方法或替代方案?
I've been trying to validate my passed options with boost::program_options. My command has several modes, each of which have associated params that can be specified. What I'm trying to do is ensure these associated params are passed with the mode, i.e.
unicorn --fly --magic-wings-threshold
Where --fly
is the mode and --magic-wings-threshold
is an associated param. What I've noticed is if --magic-wings-threshold
has a default value, e.g.
("magic-wings-threshold,w", po::value<double>(&wings_thresh)->default_value(0.8, "0.8"),
"Magic wings maximum power"
)
then I can't use
if (vm.count("magic-wings-threshold")( {
// do stuff
}
to detect if the user passed that param.
It appears that default value params are always passed and detected in vm.count()
. Does anyone know a workaround or alternative?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
boost::程序选项::变量值::默认()
use
boost::program_options::variable_value::defaulted()
如果你想区分
你应该使用 po::value()->implicit_value(),你可以用以下方式区分不同的情况:
If you want to tell difference between
You should use po::value()->implicit_value(), You can tell the different situations with: