|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r73818 - in trunk: boost libs/conversion
From: antoshkka_at_[hidden]
Date: 2011-08-16 13:09:25
Author: apolukhin
Date: 2011-08-16 13:09:25 EDT (Tue, 16 Aug 2011)
New Revision: 73818
URL: http://svn.boost.org/trac/boost/changeset/73818
Log:
Fixes #5783
Fixes ambiguities with operators >> and <<. Adds tests for such cases.
Text files modified:
trunk/boost/lexical_cast.hpp | 3 ++-
trunk/libs/conversion/lexical_cast_test.cpp | 28 ++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletions(-)
Modified: trunk/boost/lexical_cast.hpp
==============================================================================
--- trunk/boost/lexical_cast.hpp (original)
+++ trunk/boost/lexical_cast.hpp 2011-08-16 13:09:25 EDT (Tue, 16 Aug 2011)
@@ -1687,7 +1687,8 @@
interpreter(buf, buf + src_len);
Target result;
- if(!(interpreter << arg && interpreter >> result))
+ // Disabling ADL, by directly specifying operators.
+ if(!(interpreter.operator <<(arg) && interpreter.operator >>(result)))
BOOST_LCAST_THROW_BAD_CAST(Source, Target);
return result;
}
Modified: trunk/libs/conversion/lexical_cast_test.cpp
==============================================================================
--- trunk/libs/conversion/lexical_cast_test.cpp (original)
+++ trunk/libs/conversion/lexical_cast_test.cpp 2011-08-16 13:09:25 EDT (Tue, 16 Aug 2011)
@@ -99,6 +99,7 @@
void test_wallocator();
#endif
void test_char_types_conversions();
+void operators_overload_test();
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
@@ -140,6 +141,7 @@
#endif
suite->add(BOOST_TEST_CASE(&test_char_types_conversions));
+ suite->add(BOOST_TEST_CASE(&operators_overload_test));
return suite;
}
@@ -958,7 +960,33 @@
+struct foo_operators_test
+{
+ foo_operators_test() : f(2) {}
+ int f;
+};
+template <typename OStream>
+OStream& operator<<(OStream& ostr, const foo_operators_test& foo)
+{
+ ostr << foo.f;
+ return ostr;
+}
+template <typename IStream>
+IStream& operator>>(IStream& istr, foo_operators_test& foo)
+{
+ istr >> foo.f;
+ return istr;
+}
+
+void operators_overload_test()
+{
+ foo_operators_test foo;
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(foo), "2");
+ BOOST_CHECK_EQUAL((boost::lexical_cast<foo_operators_test>("2")).f, 2);
+ // Must compile
+ (void)boost::lexical_cast<foo_operators_test>(foo);
+}
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