Non-templated iostreams fix in optional_io

Better "illegal conversion" fail test


[SVN r32972]
This commit is contained in:
Fernando Cacciola
2006-02-16 20:52:55 +00:00
parent 0e10374194
commit 91bdde095d
2 changed files with 27 additions and 5 deletions

View File

@ -12,8 +12,18 @@
#ifndef BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP #ifndef BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP
#define BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP #define BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP
#include<ostream> # if defined __GNUC__
#include<istream> # if (__GNUC__ == 2 && __GNUC_MINOR__ <= 97)
#define BOOST_OPTIONAL_NO_TEMPLATED_STREAMS
#endif
#endif // __GNUC__
#if defined BOOST_OPTIONAL_NO_TEMPLATED_STREAMS
#include <iostream>
#else
#include <istream>
#include <ostream>
#endif
#include "boost/optional/optional.hpp" #include "boost/optional/optional.hpp"
@ -22,10 +32,15 @@
namespace boost namespace boost
{ {
#if defined (BOOST_NO_TEMPLATED_STREAMS)
template<class T>
inline std::ostream& operator<<(std::ostream& out, optional<T> const& v)
#else
template<class CharType, class CharTrait, class T> template<class CharType, class CharTrait, class T>
inline inline
std::basic_ostream<CharType, CharTrait>& std::basic_ostream<CharType, CharTrait>&
operator<<(std::basic_ostream<CharType, CharTrait>& out, optional<T> const& v) operator<<(std::basic_ostream<CharType, CharTrait>& out, optional<T> const& v)
#endif
{ {
if ( out.good() ) if ( out.good() )
{ {
@ -37,10 +52,15 @@ operator<<(std::basic_ostream<CharType, CharTrait>& out, optional<T> const& v)
return out; return out;
} }
#if defined (BOOST_NO_TEMPLATED_STREAMS)
template<class T>
inline std::istream& operator>>(std::istream& in, optional<T>& v)
#else
template<class CharType, class CharTrait, class T> template<class CharType, class CharTrait, class T>
inline inline
std::basic_istream<CharType, CharTrait>& std::basic_istream<CharType, CharTrait>&
operator>>(std::basic_istream<CharType, CharTrait>& in, optional<T>& v) operator>>(std::basic_istream<CharType, CharTrait>& in, optional<T>& v)
#else
{ {
if ( in.good() ) if ( in.good() )
{ {

View File

@ -13,14 +13,16 @@
#include "boost/optional.hpp" #include "boost/optional.hpp"
struct A {} ;
struct B {} ;
// //
// THIS TEST SHOULD FAIL TO COMPILE // THIS TEST SHOULD FAIL TO COMPILE
// //
void test_no_unsupported_conversion() void test_no_unsupported_conversion()
{ {
boost::optional<int> opt1(1) ; boost::optional<A> opt1;
boost::optional< std::string > opt2 ; boost::optional<B> opt2;
opt2 = opt1 ; // Cannot convert from "int" to "std::string" opt2 = opt1 ; // Cannot convert from "A" to "B"
} }