Index: boost/program_options/detail/value_semantic.hpp =================================================================== --- boost/program_options/detail/value_semantic.hpp (revision 80990) +++ boost/program_options/detail/value_semantic.hpp (working copy) @@ -11,7 +11,7 @@ namespace boost { namespace program_options { extern BOOST_PROGRAM_OPTIONS_DECL std::string arg; - + template std::string typed_value::name() const @@ -86,7 +86,7 @@ validators::check_first_occurrence(v); std::basic_string s(validators::get_single_string(xs)); try { - v = any(lexical_cast(s)); + v = any(detail::convert_to(s)); } catch(const bad_lexical_cast&) { boost::throw_exception(invalid_option_value(s)); Index: boost/program_options/value_semantic.hpp =================================================================== --- boost/program_options/value_semantic.hpp (revision 80990) +++ boost/program_options/value_semantic.hpp (working copy) @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include @@ -20,6 +22,38 @@ namespace boost { namespace program_options { + namespace detail { + + template + struct is_optional : false_type { + }; + + template + struct is_optional > : true_type { + }; + + template + To convert_to_impl(From const& v, false_type, false_type) { + return lexical_cast(v); + }; + + template + To convert_to_impl(From const& v, false_type, true_type) { + return lexical_cast(*v); + }; + + template + To convert_to_impl(From const& v, true_type, false_type) { + return lexical_cast(v); + }; + + template + To convert_to(From const& v) { + return convert_to_impl(v, is_optional(), is_optional()); + } + + } + /** Class which specifies how the option's value is to be parsed and converted into C++ types. */ @@ -195,7 +229,7 @@ typed_value* default_value(const T& v) { m_default_value = boost::any(v); - m_default_value_as_text = boost::lexical_cast(v); + m_default_value_as_text = detail::convert_to(v); return this; } @@ -223,7 +257,7 @@ { m_implicit_value = boost::any(v); m_implicit_value_as_text = - boost::lexical_cast(v); + detail::convert_to(v); return this; }