forked from boostorg/conversion
Fix ambiguity while using lexical_cast with std::transform or other functions that may take a pointer to lexical_cast (refs #7421)
[SVN r83457]
This commit is contained in:
@@ -2446,17 +2446,59 @@ namespace boost {
|
|||||||
return caster_type::lexical_cast_impl(arg);
|
return caster_type::lexical_cast_impl(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Target, typename CharType>
|
template <typename Target>
|
||||||
inline Target lexical_cast(const CharType* chars, std::size_t count)
|
inline Target lexical_cast(const char* chars, std::size_t count)
|
||||||
{
|
{
|
||||||
BOOST_STATIC_ASSERT_MSG(boost::detail::is_char_or_wchar<CharType>::value,
|
return ::boost::lexical_cast<Target>(
|
||||||
"CharType must be a character or wide character type");
|
::boost::iterator_range<const char*>(chars, chars + count)
|
||||||
|
|
||||||
return boost::lexical_cast<Target>(
|
|
||||||
boost::iterator_range<const CharType*>(chars, chars + count)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Target>
|
||||||
|
inline Target lexical_cast(const unsigned char* chars, std::size_t count)
|
||||||
|
{
|
||||||
|
return ::boost::lexical_cast<Target>(
|
||||||
|
::boost::iterator_range<const unsigned char*>(chars, chars + count)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Target>
|
||||||
|
inline Target lexical_cast(const signed char* chars, std::size_t count)
|
||||||
|
{
|
||||||
|
return ::boost::lexical_cast<Target>(
|
||||||
|
::boost::iterator_range<const signed char*>(chars, chars + count)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_LCAST_NO_WCHAR_T
|
||||||
|
template <typename Target>
|
||||||
|
inline Target lexical_cast(const wchar_t* chars, std::size_t count)
|
||||||
|
{
|
||||||
|
return ::boost::lexical_cast<Target>(
|
||||||
|
::boost::iterator_range<const wchar_t*>(chars, chars + count)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifndef BOOST_NO_CHAR16_T
|
||||||
|
template <typename Target>
|
||||||
|
inline Target lexical_cast(const char16_t* chars, std::size_t count)
|
||||||
|
{
|
||||||
|
return ::boost::lexical_cast<Target>(
|
||||||
|
::boost::iterator_range<const char16_t*>(chars, chars + count)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifndef BOOST_NO_CHAR32_T
|
||||||
|
template <typename Target>
|
||||||
|
inline Target lexical_cast(const char32_t* chars, std::size_t count)
|
||||||
|
{
|
||||||
|
return ::boost::lexical_cast<Target>(
|
||||||
|
::boost::iterator_range<const char32_t*>(chars, chars + count)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#else // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
#else // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
#include <boost/type_traits/integral_promotion.hpp>
|
#include <boost/type_traits/integral_promotion.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <algorithm> // std::transform
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#if (defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64)) \
|
#if (defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64)) \
|
||||||
@@ -622,6 +623,10 @@ void test_getting_pointer_to_function()
|
|||||||
typedef std::string(*f3)(const int&);
|
typedef std::string(*f3)(const int&);
|
||||||
f3 p3 = &boost::lexical_cast<std::string, int>;
|
f3 p3 = &boost::lexical_cast<std::string, int>;
|
||||||
BOOST_CHECK(p3);
|
BOOST_CHECK(p3);
|
||||||
|
|
||||||
|
std::vector<int> values;
|
||||||
|
std::vector<std::string> ret;
|
||||||
|
std::transform(values.begin(), values.end(), ret.begin(), boost::lexical_cast<std::string, int>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user