Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost] [program options] Recommended way to specify a list of strings
From: TSalm (tsalm_at_[hidden])
Date: 2009-12-30 13:10:24


Le Wed, 23 Dec 2009 07:04:19 +0100, Vladimir Prus
<vladimir_at_[hidden]> a écrit:

> Sanjit Jhala wrote:
>
>> How would I specify an empty vector of strings as the default value for
>> this
>> option?
>>
>> po::value< vector<string> >()->default_value(??)
>
> Use vector<string>() as the default value.
>
Hi,

I have the same problem.
But when I'm using :

   configuration.add_options()
     ("DEFAULT.bytecompile",program_options::value< vector<string>
>()->default_value(vector<string>()))
     ;

G++ won't compile.

Here is the complete source code :

#include <vector>
#include <boost/program_options.hpp>

int main(int argc, char** argv)
{
   using namespace std;
   using namespace boost;

   program_options::options_description configuration;
   boost::program_options::variables_map vm;
   vector<string> empty_vector;

   // Set options and default values
   configuration.add_options()
     ("DEFAULT.bytecompile",program_options::value< vector<string>
>()->default_value(vector<string>()))
     ;

   program_options::store (
            program_options::parse_command_line(argc, argv, configuration)
          , vm );

   program_options::notify( vm );

   return 0;
}

And the error message :

/usr/include/boost/lexical_cast.hpp: In member function ‘bool
boost::detail::lexical_stream<Target, Source>::operator<<(const Source&)
[with Target = std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, Source = std::vector<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >]’:
/usr/include/boost/lexical_cast.hpp:222: instantiated from ‘Target
boost::lexical_cast(const Source&) [with Target = std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, Source =
std::vector<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::allocator<std::basic_string<char,
std::char_traits<char>, std::allocator<char> > > >]’
/usr/include/boost/program_options/value_semantic.hpp:190: instantiated
 from ‘boost::program_options::typed_value<T, charT>*
boost::program_options::typed_value<T, charT>::default_value(const T&)
[with T = std::vector<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::allocator<std::basic_string<char,
std::char_traits<char>, std::allocator<char> > > >, charT = char]’
config_file__vector.cpp:16: instantiated from here
/usr/include/boost/lexical_cast.hpp:151: error: no match for ‘operator<<’
in ‘((boost::detail::lexical_stream<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::vector<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::allocator<std::basic_string<char,
std::char_traits<char>, std::allocator<char> > > >
>*)this)->boost::detail::lexical_stream<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::vector<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::allocator<std::basic_string<char,
std::char_traits<char>, std::allocator<char> > > > >::stream << input’
/usr/include/c++/4.3/ostream:112: note: candidates are:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(std::basic_ostream<_CharT, _Traits>&
(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:121: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(std::basic_ios<_CharT, _Traits>&
(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:131: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT =
char, _Traits = std::char_traits<char>]
/usr/include/c++/4.3/ostream:169: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(long int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:173: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:177: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(bool) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/bits/ostream.tcc:97: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(short int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:184: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/bits/ostream.tcc:111: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:195: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(unsigned int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:204: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(long long int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:208: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits
= std::char_traits<char>]
/usr/include/c++/4.3/ostream:213: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(double) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:217: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(float) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:225: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(long double) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:229: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(const void*) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/bits/ostream.tcc:125: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT
= char, _Traits = std::char_traits<char>]

-- 
Utilisant le client e-mail révolutionnaire d'Opera :  
http://www.opera.com/mail/

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net