Opened 15 years ago

Closed 13 years ago

#1645 closed Bugs (wontfix)

Invalid unicode support for default_value

Reported by: anonymous Owned by: Vladimir Prus
Milestone: Boost 1.36.0 Component: program_options
Version: Boost 1.34.1 Severity: Problem
Keywords: Cc: s.ochsenknecht@…

Description

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.

Change History (2)

comment:1 by Sascha Ochsenknecht <s.ochsenknecht@…>, 13 years ago

Cc: s.ochsenknecht@… added

This problem appears for every value type which makes problem with lexical_cast<std::string>().

Here is a workaround: There as an overloaded version of default_value() which can be used to define the string representation of the default value:

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

This string (second parameter of default_value()) is then used for the help output. I would recommend to use this approach.

Please comment.

comment:2 by Vladimir Prus, 13 years ago

Resolution: wontfix
Status: newclosed

I agree that explicitly specifying the textual rendition of default value is the best approach for now.

Note: See TracTickets for help on using tickets.