示例#1
0
int main()
{
	int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
	const slist<int> sl(arr, arr + sizeof(arr)/sizeof(arr[0]));
	
	for(auto i : sl)
		std::cout << i << ' ';
	std::cout << std::endl;

	auto iter = sl.begin();
	++iter;
	++iter;
	iter = sl.previous(iter);

	std::cout << *iter << std::endl;

	iter._M_node = __slist_reverse(iter._M_node);

	for(auto i : sl)
		std::cout << i << ' ';
	std::cout << std::endl;

	std::cout << *iter << std::endl;

	return 0;
}//main
po::options_description store_and_notify(vector<string> argv,
                                         po::variables_map &vm,
                                         po::options_description* generic) {
   po::options_description config_file_options;
   populate_options(config_file_options);

   po::options_description cmdline_options;
   if (generic)
      cmdline_options.add(*generic);
   cmdline_options.add(config_file_options);

   /** Config hierarchy:
    *  - first,  command line arguments
    *  - second, /home/nao/data/configs/$hostname.cfg
    *  - third,  /home/nao/data/runswift.cfg
    *  - fourth, `pwd`/runswift.cfg
    **/
   // arguments from this call
   store(po::command_line_parser(argv).options(cmdline_options).run(), vm);

   // arguments from previous calls
   static slist<vector<string> > argvs;
   for (slist<vector<string> >::const_iterator argv_ci = argvs.begin();
        argv_ci != argvs.end(); ++argv_ci)
      store(po::command_line_parser(*argv_ci).options(cmdline_options).run(),
            vm);

   ifstream ifs;
   string hostname;

   ifs.open("/etc/hostname");
   ifs >> hostname;
   ifs.close();

   ifs.open(string("/home/nao/data/configs/" + hostname + ".cfg").c_str());
   store(parse_config_file(ifs, config_file_options), vm);
   ifs.close();

   ifs.open("/home/nao/data/runswift.cfg");
   store(parse_config_file(ifs, config_file_options), vm);
   ifs.close();

   ifs.open("runswift.cfg");
   store(parse_config_file(ifs, config_file_options), vm);
   ifs.close();

   /** Doesn't do anything right now, but will 'notify' any variables
    * we try to set via program_options */
   po::notify(vm);

   // assuming all options were valid and no exception was thrown, save argv for
   // repeated use
   argvs.push_front(argv);

   return cmdline_options;
}