Subject: [Boost-bugs] [Boost C++ Libraries] #7929: boost::lexical_cast< std::string, std::wstring > gives a compiler error.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-01-26 01:44:35
#7929: boost::lexical_cast< std::string, std::wstring > gives a compiler error.
---------------------------------+------------------------------------------
Reporter: nate@⦠| Owner: apolukhin
Type: Bugs | Status: new
Milestone: To Be Determined | Component: lexical_cast
Version: Boost 1.52.0 | Severity: Problem
Keywords: |
---------------------------------+------------------------------------------
This causes a problem with `boost::program_options::typed_value<
std::wstring, wchar_t >::default_value( const std::wstring& v )` which
attempts to use lexical_cast to convert `v` into a `std::string`. Using
`lexical_cast` to convert a wide string to a normal one may be debatable,
but program_options should not give a compiler error on a valid use case
such as the one shown below. Luckily you can work around this by providing
an explicit `std::string` version or not using the `default_value` method
at all.
==== lexical_cast error ====
{{{#!cpp
#include <boost/lexical_cast.hpp>
#include <string>
int main( int argc, wchar_t* argv[] ){
std::wstring wstr = L"some string";
std::string str = boost::lexical_cast< std::string >( wstr );
return 0;
}
}}}
==== program_options error ====
{{{#!cpp
#include <boost/program_options.hpp>
#include <string>
int main( int argc, wchar_t* argv[] ){
namespace po = boost::program_options;
po::options_description opts( "Some opts" );
std::wstring str = L"";
opts.add_options()
(
"o",
po::wvalue< std::wstring >( &str )
->default_value( L"default value" ), // This line causes
error.
"an option"
);
return 0;
}
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/7929> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:11 UTC