mirror of
https://github.com/boostorg/optional.git
synced 2025-07-23 17:17:17 +02:00
operator>> behavior changed slightly so that the stream is not accessed when unrecognized character sequence is detected.
[SVN r67184]
This commit is contained in:
@ -25,6 +25,7 @@
|
|||||||
# include <ostream>
|
# include <ostream>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <boost/none.hpp>
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
#include "boost/optional/optional.hpp"
|
#include "boost/optional/optional.hpp"
|
||||||
#include "boost/utility/value_init.hpp"
|
#include "boost/utility/value_init.hpp"
|
||||||
@ -73,15 +74,18 @@ operator>>(std::basic_istream<CharType, CharTrait>& in, optional<T>& v)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( d != '-')
|
if (d == '-')
|
||||||
in.setstate( std::ios::failbit );
|
{
|
||||||
|
|
||||||
d = in.get();
|
d = in.get();
|
||||||
|
|
||||||
if ( d != '-')
|
if (d == '-')
|
||||||
in.setstate( std::ios::failbit );
|
{
|
||||||
|
v = none;
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
v = optional<T>() ;
|
in.setstate( std::ios::failbit );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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>) ) );
|
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* [] )
|
int test_main( int, char* [] )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -1273,6 +1300,7 @@ int test_main( int, char* [] )
|
|||||||
test_conversions1();
|
test_conversions1();
|
||||||
test_conversions2();
|
test_conversions2();
|
||||||
test_swap_tweaking();
|
test_swap_tweaking();
|
||||||
|
test_custom_addressof_operator();
|
||||||
}
|
}
|
||||||
catch ( ... )
|
catch ( ... )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user