Boost logo

Boost Users :

From: Filip Konvička (filip.konvicka_at_[hidden])
Date: 2008-02-19 06:32:38

> The following example could not be compiled:
> =================================================================
> #include <string>
> #include <boost/program_options.hpp>
> namespace po = boost::program_options;
> int main()
> {
> std::wstring test;
> po::options_description desc("Allowed options");
> desc.add_options()
> ("test", po::wvalue<std::wstring>(&test)->default_value(L"value"),
> "description");
> }
> =================================================================
> It is due to wvalue::default_value tries to do
> lexical_cast<std::string>(std::wstring).
> Also I cannot change default_value to default_value("value") as soon
> as it accepts only something convertible to std::wstring.
> In other words it is impossible to specify default_value for wstring
> option.
I've solved this by providing alternative value description in a
char-based encoding. In my case, I use UTF-8 for all descriptions, and
filter all output of boost::program_options through UTF8->wchar_t

So in your case

    ("test", po::wvalue<std::wstring>(&test)->default_value(L"value",
"value"), "description");

will probably compile fine.

However, I agree that this is a bug - wvalue should probably use
wstringstream and not stringstream for conversions. I also think that
other classes like options_descriptions should accept wide strings,
because otherwise we need to use the UTF8 trick to enable localization
of these.

Moreover, some english strings seem to be hard-coded in program_options
(exception messages, etc.) There should be another way of handling
cmdline errors - we can't presume that the user understands english
text. And there does not seem to be a way of translating the po
exceptions to localized strings without accessing/changing some po

Hope this helps,

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at