Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/boost/optional/optional_io.hpp @ 47

Last change on this file since 47 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 1.8 KB
Line 
1// Copyright (C) 2005, Fernando Luis Cacciola Carballal.
2//
3// Use, modification, and distribution is subject to the Boost Software
4// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6//
7// See http://www.boost.org/lib/optional for documentation.
8//
9// You are welcome to contact the author at:
10//  fernando_cacciola@hotmail.com
11//
12#ifndef BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP
13#define BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP
14
15#if defined __GNUC__
16#  if (__GNUC__ == 2 && __GNUC_MINOR__ <= 97)
17#    define BOOST_OPTIONAL_NO_TEMPLATED_STREAMS
18#  endif
19#endif // __GNUC__
20
21#if defined BOOST_OPTIONAL_NO_TEMPLATED_STREAMS
22#  include <iostream>
23#else
24#  include <istream>
25#  include <ostream>
26#endif 
27
28
29#include "boost/optional/optional.hpp"
30#include "boost/utility/value_init.hpp"
31
32namespace boost
33{
34
35#if defined (BOOST_NO_TEMPLATED_STREAMS)
36template<class T>
37inline std::ostream& operator<<(std::ostream& out, optional<T> const& v)
38#else
39template<class CharType, class CharTrait, class T>
40inline
41std::basic_ostream<CharType, CharTrait>&
42operator<<(std::basic_ostream<CharType, CharTrait>& out, optional<T> const& v)
43#endif
44{
45  if ( out.good() )
46  {
47    if ( !v )
48         out << "--" ;
49    else out << ' ' << *v ;
50  }
51
52  return out;
53}
54
55#if defined (BOOST_NO_TEMPLATED_STREAMS)
56template<class T>
57inline std::istream& operator>>(std::istream& in, optional<T>& v)
58#else
59template<class CharType, class CharTrait, class T>
60inline
61std::basic_istream<CharType, CharTrait>&
62operator>>(std::basic_istream<CharType, CharTrait>& in, optional<T>& v)
63#endif
64{
65  if ( in.good() )
66  {
67    int d = in.get();
68    if ( d == ' ' )
69    {
70      T x ;
71      in >> x;
72      v = x ;
73    }
74    else
75      v = optional<T>() ;
76  }
77
78  return in;
79}
80
81} // namespace boost
82
83#endif
84
Note: See TracBrowser for help on using the repository browser.