|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r80787 - in branches/release: boost libs/conversion libs/conversion/doc
From: antoshkka_at_[hidden]
Date: 2012-09-30 12:07:33
Author: apolukhin
Date: 2012-09-30 12:07:32 EDT (Sun, 30 Sep 2012)
New Revision: 80787
URL: http://svn.boost.org/trac/boost/changeset/80787
Log:
Merege fix for #7421 from trunk
Text files modified:
branches/release/boost/lexical_cast.hpp | 52 ++++++++++++++++++++++++++++++++++++---
branches/release/libs/conversion/doc/lexical_cast.qbk | 4 +-
branches/release/libs/conversion/lexical_cast_test.cpp | 15 +++++++++++
3 files changed, 64 insertions(+), 7 deletions(-)
Modified: branches/release/boost/lexical_cast.hpp
==============================================================================
--- branches/release/boost/lexical_cast.hpp (original)
+++ branches/release/boost/lexical_cast.hpp 2012-09-30 12:07:32 EDT (Sun, 30 Sep 2012)
@@ -2300,17 +2300,59 @@
return caster_type::lexical_cast_impl(arg);
}
- template <typename Target, typename CharType>
- inline Target lexical_cast(const CharType* chars, std::size_t count)
+ template <typename Target>
+ inline Target lexical_cast(const char* chars, std::size_t count)
{
- BOOST_STATIC_ASSERT_MSG(::boost::detail::is_char_or_wchar<CharType>::value,
- "CharType must be a character or wide character type");
+ return ::boost::lexical_cast<Target>(
+ ::boost::iterator_range<const char*>(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 CharType*>(chars, chars + count)
+ ::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
#else // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Modified: branches/release/libs/conversion/doc/lexical_cast.qbk
==============================================================================
--- branches/release/libs/conversion/doc/lexical_cast.qbk (original)
+++ branches/release/libs/conversion/doc/lexical_cast.qbk 2012-09-30 12:07:32 EDT (Sun, 30 Sep 2012)
@@ -107,8 +107,8 @@
Returns the result of streaming arg into a standard library string-based stream and then out as a Target object. Where Target is either `std::string` or `std::wstring`, stream extraction takes the whole content of the string, including spaces, rather than relying on the default `operator>>` behavior. If the conversion is unsuccessful, a `bad_lexical_cast` exception is thrown.
``
- template <typename Target, typename CharType>
- Target lexical_cast(const CharType* chars, std::size_t count);
+ template <typename Target>
+ Target lexical_cast(const AnyCharacterType* chars, std::size_t count);
``
Takes an array of `count` characters as input parameter and streams them out as a Target object. If the conversion is unsuccessful, a `bad_lexical_cast` exception is thrown. This call may be useful for processing nonzero terminated array of characters or processing just some part of character array.
Modified: branches/release/libs/conversion/lexical_cast_test.cpp
==============================================================================
--- branches/release/libs/conversion/lexical_cast_test.cpp (original)
+++ branches/release/libs/conversion/lexical_cast_test.cpp 2012-09-30 12:07:32 EDT (Sun, 30 Sep 2012)
@@ -88,6 +88,7 @@
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS)
void test_char32_conversions();
#endif
+void test_getting_pointer_to_function();
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
@@ -125,6 +126,7 @@
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS)
suite->add(BOOST_TEST_CASE(&test_char32_conversions));
#endif
+ suite->add(BOOST_TEST_CASE(&test_getting_pointer_to_function));
return suite;
}
@@ -599,4 +601,17 @@
}
#endif
+template <class To, class From, class Func>
+To try_cast_by_ptr(const From& from, const Func& f) {
+ return f(from);
+};
+
+void test_getting_pointer_to_function()
+{
+ // Just checking that &lexical_cast<To, From> is not ambiguous
+ BOOST_CHECK_EQUAL(100, try_cast_by_ptr<int>("100", &boost::lexical_cast<int, const char[4]>));
+ BOOST_CHECK_EQUAL(100, try_cast_by_ptr<int>("100", &boost::lexical_cast<int, std::string>));
+ BOOST_CHECK_EQUAL(std::string("100"), try_cast_by_ptr<std::string>(100, &boost::lexical_cast<std::string, int>));
+}
+
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk