Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:49:46

0001 // Copyright (C) 2005, Fernando Luis Cacciola Carballal.
0002 //
0003 // Use, modification, and distribution is subject to the Boost Software
0004 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0005 // http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/optional for documentation.
0008 //
0009 // You are welcome to contact the author at:
0010 //  fernando_cacciola@hotmail.com
0011 //
0012 #ifndef BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP
0013 #define BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP
0014 
0015 #ifndef BOOST_NO_IOSTREAM
0016 #include <istream>
0017 #include <ostream>
0018 
0019 #include "boost/none.hpp"
0020 #include "boost/optional/optional.hpp"
0021 
0022 
0023 namespace boost
0024 {
0025 
0026 template<class CharType, class CharTrait>
0027 inline
0028 std::basic_ostream<CharType, CharTrait>&
0029 operator<<(std::basic_ostream<CharType, CharTrait>& out, none_t)
0030 {
0031   if (out.good())
0032   {
0033     out << "--";
0034   }
0035 
0036   return out;
0037 }
0038 
0039 template<class CharType, class CharTrait, class T>
0040 inline
0041 std::basic_ostream<CharType, CharTrait>&
0042 operator<<(std::basic_ostream<CharType, CharTrait>& out, optional<T> const& v)
0043 {
0044   if (out.good())
0045   {
0046     if (!v)
0047          out << "--" ;
0048     else out << ' ' << *v ;
0049   }
0050 
0051   return out;
0052 }
0053 
0054 template<class CharType, class CharTrait, class T>
0055 inline
0056 std::basic_istream<CharType, CharTrait>&
0057 operator>>(std::basic_istream<CharType, CharTrait>& in, optional<T>& v)
0058 {
0059   if (in.good())
0060   {
0061     int d = in.get();
0062     if (d == ' ')
0063     {
0064       T x;
0065       in >> x;
0066 #ifndef  BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
0067       v = boost::move(x);
0068 #else
0069       v = x;
0070 #endif
0071     }
0072     else
0073     {
0074       if (d == '-')
0075       {
0076         d = in.get();
0077 
0078         if (d == '-')
0079         {
0080           v = none;
0081           return in;
0082         }
0083       }
0084 
0085       in.setstate( std::ios::failbit );
0086     }
0087   }
0088 
0089   return in;
0090 }
0091 
0092 } // namespace boost
0093 
0094 #endif // BOOST_NO_IOSTREAM
0095 #endif