operator<< improvements

This commit is contained in:
Andrzej Krzemienski
2015-01-21 00:10:51 +01:00
parent cc17103070
commit 726b227aa9
39 changed files with 213 additions and 46 deletions

View File

@ -1226,10 +1226,13 @@ get_pointer ( optional<T>& opt )
return opt.get_ptr() ;
}
// Forward declaration to prevent operator safe-bool from being used.
template<class CharType, class CharTrait, class T>
// The following declaration prevents a bug where operator safe-bool is used upon streaming optional object if you forget the IO header.
template<class CharType, class 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_detail::optional_tag const& v)
{
BOOST_STATIC_ASSERT_MSG(sizeof(CharType) == 0, "If you want to output boost::optional, include header <boost/optional/optional_io.hpp>");
}
// optional's relational operators ( ==, !=, <, >, <=, >= ) have deep-semantics (compare values).
// WARNING: This is UNLIKE pointers. Use equal_pointees()/less_pointess() in generic code instead.

View File

@ -16,9 +16,8 @@
#include <ostream>
#include <boost/none.hpp>
#include <boost/assert.hpp>
#include "boost/optional/optional.hpp"
#include "boost/utility/value_init.hpp"
namespace boost
{