forked from boostorg/conversion
Because of the errors in MSVC with fowarding and static_casting arrays it was decided to drop minor optimization and do not perfect forward source types in try_lexical_convert
This commit is contained in:
@@ -72,7 +72,7 @@ Library features defined in [@boost:boost/lexical_cast.hpp boost/lexical_cast.hp
|
||||
namespace conversion
|
||||
{
|
||||
template<typename Target, typename Source>
|
||||
bool try_lexical_convert(Source&& arg, Target& result);
|
||||
bool try_lexical_convert(const Source& arg, Target& result);
|
||||
|
||||
template <typename AnyCharacterType, typename Target>
|
||||
bool try_lexical_convert(const AnyCharacterType* chars, std::size_t count, Target& result);
|
||||
@@ -134,11 +134,11 @@ Exception used to indicate runtime lexical_cast failure.
|
||||
|
||||
[section try_lexical_convert]
|
||||
`boost::lexical_cast` remains the main interface for lexical conversions. It must be used by default in most cases. However
|
||||
some developers wish to make their own conversion functions, reusing all the optimizations of `boost::lexical_cast`. That's
|
||||
where the `boost::conversion::try_lexical_convert` function steps in.
|
||||
some developers wish to make their own conversion functions, reusing all the optimizations of the `boost::lexical_cast`.
|
||||
That's where the `boost::conversion::try_lexical_convert` function steps in.
|
||||
|
||||
`try_lexical_convert` returns `true` if conversion succeeded, otherwise returns `false`. If conversion failed and `false` was returned,
|
||||
state of `result` output variable is undefined.
|
||||
`try_lexical_convert` returns `true` if conversion succeeded, otherwise returns `false`. If conversion
|
||||
failed and `false` was returned, state of `result` output variable is undefined.
|
||||
|
||||
Actually, `boost::lexical_cast` is implemented using `try_lexical_convert`:
|
||||
``
|
||||
@@ -154,8 +154,7 @@ Actually, `boost::lexical_cast` is implemented using `try_lexical_convert`:
|
||||
}
|
||||
``
|
||||
|
||||
`try_lexical_convert` relaxes the requirements for `Target` type. `Target` must not be CopyConstructible or DefaultConstructible.
|
||||
|
||||
`try_lexical_convert` relaxes the CopyConstructible and DefaultConstructible requirements for `Target` type.
|
||||
Following requirements for `Target` and `Source` remain:
|
||||
|
||||
* Source must be OutputStreamable, meaning that an `operator<<` is defined that takes a `std::ostream` or `std::wostream` object on the left hand side and an instance of the argument type on the right.
|
||||
|
@@ -2077,9 +2077,6 @@ namespace boost {
|
||||
i_interpreter_type i_interpreter;
|
||||
|
||||
// Disabling ADL, by directly specifying operators.
|
||||
//
|
||||
// For compilers with perfect forwarding `static_cast<forward_type>(arg)` is
|
||||
// eqaul to `std::forward<T>(arg)`.
|
||||
if (!(i_interpreter.operator <<(arg)))
|
||||
return false;
|
||||
|
||||
@@ -2252,25 +2249,10 @@ namespace boost {
|
||||
|
||||
namespace conversion { namespace detail {
|
||||
|
||||
// MSVC fail to forward an array (DevDiv#555157 "SILENT BAD CODEGEN triggered by perfect forwarding",
|
||||
// fixed in 2013 RTM).
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && (!defined(BOOST_MSVC) || BOOST_MSVC >= 1800)
|
||||
template <typename Target, typename Source>
|
||||
inline bool try_lexical_convert(Source&& arg, Target& result)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<
|
||||
BOOST_DEDUCED_TYPENAME boost::remove_reference<Source>::type
|
||||
>::type no_cr_source_t;
|
||||
|
||||
typedef Source&& forward_type;
|
||||
#else
|
||||
template <typename Target, typename Source>
|
||||
inline bool try_lexical_convert(const Source& arg, Target& result)
|
||||
{
|
||||
typedef Source no_cr_source_t;
|
||||
typedef const Source& forward_type;
|
||||
#endif
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::detail::array_to_pointer_decay<no_cr_source_t>::type src;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::detail::array_to_pointer_decay<Source>::type src;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::type_traits::ice_or<
|
||||
boost::detail::is_xchar_to_xchar<Target, src >::value,
|
||||
@@ -2302,7 +2284,7 @@ namespace boost {
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME caster_type_lazy::type caster_type;
|
||||
|
||||
return caster_type::try_convert(static_cast<forward_type>(arg), result);
|
||||
return caster_type::try_convert(arg, result);
|
||||
}
|
||||
|
||||
template <typename Target, typename CharacterT>
|
||||
|
Reference in New Issue
Block a user