I am learning boost through examples, but I do not understand why the following c++ code failed to execute, I am only changing int to uint8_t, am I missing anything?
#include <stdint.h>
#include <iostream>
#include <vector>
#include <boost/program_options.hpp>
int main()
{
namespace po = boost::program_options;
const int argc = 5;
const char* argv[] = {"foo", "--data", "1", "127", "255" };
std::vector<uint8_t> databytes;
po::variables_map vm;
po::options_description cmd_options( "options" );
cmd_options.add_options()
( "data", po::value<std::vector<uint8_t>>( &databytes )->multitoken(), "DATA" );
po::store( po::parse_command_line( argc, argv, cmd_options ), vm );
po::notify( vm );
std::cout << "size: " << databytes.size() << std::endl;
for (size_t i = 0; i < databytes.size(); i++) {
std::cout << i << ": " << (int)databytes[i] << std::endl;
}
}
I'd have my cake and eat it too. @StackOverflowNeko correctly points at a custom notifier. However, it conflicts a bit with using automatic variable notification. So if you avoid that, you can hide the conversion/validation step:
Live On Coliru
With various test cases: