Hi!
I came up with a I/O weird behaviour with boost::tuple. In the following
example program:
#include
#include
#include <iostream>
#include <sstream>
int
main()
{
using namespace std ;
using namespace boost ;
typedef ::boost::tuple< float > tuple_type ;
float v ;
tuple_type t ;
string str = "0.1" ;
istringstream str_in( str ) ;
str_in >> v ;
if ( str_in >> t )
{
cout << "yes " ;
}
else
{
cout << "no " ;
}
cout << t << endl ;
return 0 ;
}
I expect the output to be "no (0)", but I get "yes (0)". Usually, I expect
operator>> with streams to change the state of the stream to some kind of
failure state if it could not read the requested type. For example if I
replace the 'if' with the following:
if ( str_in >> t.get< 0 >() )
then I get "no (0)". Although I know it is not the equivalent to reading
the tuple t directly (no open/close character), at least I get the error
set I as expected. If the end of input (eof) as been read before reading
the tuple, then the condition will be false.
So, I am wrong to expect such a behavior? Or is there a bug here (either
in the way I use it or in the tuple's input operator)?
If it matters, the compiler used is g++ 4.0.
Thanks,
--
François Duranleau
LIGUM, Université de Montréal
"Do you want to use a machine, or do you want the machine to use you?"
- Doohan, in _Cowboy Bebop_