1 /**************************************************************************/
2 /* Copyright 2012 Tim Day */
3 /* */
4 /* This file is part of Evolvotron */
5 /* */
6 /* Evolvotron is free software: you can redistribute it and/or modify */
7 /* it under the terms of the GNU General Public License as published by */
8 /* the Free Software Foundation, either version 3 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* Evolvotron is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU General Public License */
17 /* along with Evolvotron. If not, see <http://www.gnu.org/licenses/>. */
18 /**************************************************************************/
19
20 #include <boost/program_options.hpp>
21 #include <iostream>
22
23 namespace boost {
24 namespace program_options {
25
26 BOOST_PROGRAM_OPTIONS_DECL typed_value<std::pair<int,int> >* intpair(std::pair<int,int>*);
27
28 }
29 }
30
31 using namespace boost::program_options;
32
main(int argc,char ** argv)33 int main(int argc,char** argv)
34 {
35 bool flag;
36 int number;
37 std::pair<int,int> pair;
38
39 options_description options_desc("General options");
40 options_desc.add_options()
41 ("flag,f"
42 ,bool_switch(&flag)
43 ,"Control a bool")
44 ("number,n"
45 ,value<int>(&number)->default_value(23)
46 ,"Specify a number")
47 ("pair,p"
48 ,intpair(&pair)->default_value(std::make_pair(2,3))
49 ,"Specify 2 numbers")
50 ;
51
52 variables_map options;
53 store(parse_command_line(argc,argv,options_desc),options);
54 notify(options);
55
56 std::cout
57 << "Flag: " << flag << "\n"
58 << "Number: " << number << "\n"
59 << "Pair: " << pair.first << " " << pair.second << "\n";
60
61 return 0;
62 }
63