[Boost-bugs] [Boost C++ Libraries] #9603: boost::optional operator<< does the wrong thing

Subject: [Boost-bugs] [Boost C++ Libraries] #9603: boost::optional operator<< does the wrong thing
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-01-23 17:22:27


#9603: boost::optional operator<< does the wrong thing
-------------------------------+-----------------------
 Reporter: a.luenser+boost@… | Owner: fcacciola
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: optional
  Version: Boost 1.55.0 | Severity: Problem
 Keywords: |
-------------------------------+-----------------------
 {{{
 template<class CharType, class CharTrait, class T>
 inline std::basic_ostream<CharType, CharTrait>&
 operator<<(std::basic_ostream<CharType, CharTrait>& out, optional<T>
 const& v)
 {
   if ( out.good() )
   {
     if ( !v )
          out << "--" ;
     else out << ' ' << *v ;
   }

   return out;
 }
 }}}
 This is the wrong semantics, in my opinion. Example of the problem:
 {{{
 std::string s("--");
 boost::optional<std::string> o;
 std::cout << s << std::endl;
 std::cout << o << std::endl;
 }}}
 prints the same, which is clearly not intended. If the optional is not
 engaged (no value), printing should to nothing, i.e. return the stream
 unmodified. Also, the ' ' character in the code above should be removed.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9603>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC