An addition to what @huw-walters demonstrated above: you don't necessarily need to provide the 'store' with the constructor
CountValue(std::size_t* store):
But with slight changes, you can just use the po::variables_map::at() to get the verbosity value, just add a store_ member variable and you can remove the parameterized constructor:
class CountValue : public po::typed_value<std::size_t>
{
public:
CountValue(/*std::size_t* store*/):
po::typed_value<std::size_t>(&store_),
store_(0)
{
....
virtual void xparse(boost::any& store, const std::vector<std::string>& /*tokens*/) const
{
// Replace the stored value with the access count.
store_ = ++count_;
store = boost::any(store_);
}
private:
mutable std::size_t count_{ 0 };
mutable size_t store_;
};
And then you can get the 'verbose' value as:
size_t verbosity = varMap.at("verbose").as<size_t>();