From 91bdde095dec3b1da7f33a69cc1b77a1ded87bc2 Mon Sep 17 00:00:00 2001 From: Fernando Cacciola Date: Thu, 16 Feb 2006 20:52:55 +0000 Subject: [PATCH] Non-templated iostreams fix in optional_io Better "illegal conversion" fail test [SVN r32972] --- include/boost/optional/optional_io.hpp | 24 ++++++++++++++++++++++-- test/optional_test_fail3b.cpp | 8 +++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/include/boost/optional/optional_io.hpp b/include/boost/optional/optional_io.hpp index cc55e7b..0de086d 100644 --- a/include/boost/optional/optional_io.hpp +++ b/include/boost/optional/optional_io.hpp @@ -12,8 +12,18 @@ #ifndef BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP #define BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP -#include -#include +# if defined __GNUC__ +# if (__GNUC__ == 2 && __GNUC_MINOR__ <= 97) +#define BOOST_OPTIONAL_NO_TEMPLATED_STREAMS +#endif +#endif // __GNUC__ + +#if defined BOOST_OPTIONAL_NO_TEMPLATED_STREAMS +#include +#else +#include +#include +#endif #include "boost/optional/optional.hpp" @@ -22,10 +32,15 @@ namespace boost { +#if defined (BOOST_NO_TEMPLATED_STREAMS) +template +inline std::ostream& operator<<(std::ostream& out, optional const& v) +#else template inline std::basic_ostream& operator<<(std::basic_ostream& out, optional const& v) +#endif { if ( out.good() ) { @@ -37,10 +52,15 @@ operator<<(std::basic_ostream& out, optional const& v) return out; } +#if defined (BOOST_NO_TEMPLATED_STREAMS) +template +inline std::istream& operator>>(std::istream& in, optional& v) +#else template inline std::basic_istream& operator>>(std::basic_istream& in, optional& v) +#else { if ( in.good() ) { diff --git a/test/optional_test_fail3b.cpp b/test/optional_test_fail3b.cpp index a7d2f1a..8058b8b 100644 --- a/test/optional_test_fail3b.cpp +++ b/test/optional_test_fail3b.cpp @@ -13,14 +13,16 @@ #include "boost/optional.hpp" +struct A {} ; +struct B {} ; // // THIS TEST SHOULD FAIL TO COMPILE // void test_no_unsupported_conversion() { - boost::optional opt1(1) ; - boost::optional< std::string > opt2 ; - opt2 = opt1 ; // Cannot convert from "int" to "std::string" + boost::optional opt1; + boost::optional opt2; + opt2 = opt1 ; // Cannot convert from "A" to "B" }