operator>> behavior changed slightly so that the stream is not accessed when unrecognized character sequence is detected.

[SVN r67184]
This commit is contained in:
Andrey Semashev
2010-12-12 11:35:19 +00:00
parent 64d8062621
commit 646488e0e2
2 changed files with 88 additions and 56 deletions

View File

@ -25,6 +25,7 @@
# include <ostream>
#endif
#include <boost/none.hpp>
#include <boost/assert.hpp>
#include "boost/optional/optional.hpp"
#include "boost/utility/value_init.hpp"
@ -73,15 +74,18 @@ operator>>(std::basic_istream<CharType, CharTrait>& in, optional<T>& v)
}
else
{
if ( d != '-')
in.setstate( std::ios::failbit );
if (d == '-')
{
d = in.get();
if ( d != '-')
in.setstate( std::ios::failbit );
if (d == '-')
{
v = none;
return in;
}
}
v = optional<T>() ;
in.setstate( std::ios::failbit );
}
}

View File

@ -1263,6 +1263,33 @@ void test_swap_tweaking()
BOOST_CHECK( test_swap_member_function( ARG(optional_swap_test::template_whose_default_ctor_should_be_used<char>) ) );
}
// Test for support for classes with overridden operator&
class CustomAddressOfClass
{
int n;
public:
CustomAddressOfClass() : n(0) {}
CustomAddressOfClass(CustomAddressOfClass const& that) : n(that.n) {}
explicit CustomAddressOfClass(int m) : n(m) {}
int* operator& () { return &n; }
bool operator== (CustomAddressOfClass const& that) const { return n == that.n; }
};
void test_custom_addressof_operator()
{
boost::optional< CustomAddressOfClass > o1(CustomAddressOfClass(10));
BOOST_CHECK(!!o1);
BOOST_CHECK(o1.get() == CustomAddressOfClass(10));
o1 = CustomAddressOfClass(20);
BOOST_CHECK(!!o1);
BOOST_CHECK(o1.get() == CustomAddressOfClass(20));
o1 = boost::none;
BOOST_CHECK(!o1);
}
int test_main( int, char* [] )
{
try
@ -1273,6 +1300,7 @@ int test_main( int, char* [] )
test_conversions1();
test_conversions2();
test_swap_tweaking();
test_custom_addressof_operator();
}
catch ( ... )
{