optional_io.hpp
Go to the documentation of this file.
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/libs/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 #include <istream>
16 #include <ostream>
17 
18 #include "boost/none.hpp"
20 
21 
22 namespace boost
23 {
24 
25 template<class CharType, class CharTrait>
26 inline
27 std::basic_ostream<CharType, CharTrait>&
28 operator<<(std::basic_ostream<CharType, CharTrait>& out, none_t)
29 {
30  if (out.good())
31  {
32  out << "--";
33  }
34 
35  return out;
36 }
37 
38 template<class CharType, class CharTrait, class T>
39 inline
40 std::basic_ostream<CharType, CharTrait>&
41 operator<<(std::basic_ostream<CharType, CharTrait>& out, optional<T> const& v)
42 {
43  if (out.good())
44  {
45  if (!v)
46  out << "--" ;
47  else out << ' ' << *v ;
48  }
49 
50  return out;
51 }
52 
53 template<class CharType, class CharTrait, class T>
54 inline
55 std::basic_istream<CharType, CharTrait>&
56 operator>>(std::basic_istream<CharType, CharTrait>& in, optional<T>& v)
57 {
58  if (in.good())
59  {
60  int d = in.get();
61  if (d == ' ')
62  {
63  T x;
64  in >> x;
65 #ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
66  v = boost::move(x);
67 #else
68  v = x;
69 #endif
70  }
71  else
72  {
73  if (d == '-')
74  {
75  d = in.get();
76 
77  if (d == '-')
78  {
79  v = none;
80  return in;
81  }
82  }
83 
84  in.setstate( std::ios::failbit );
85  }
86  }
87 
88  return in;
89 }
90 
91 } // namespace boost
92 
93 #endif
94 
boost::operator<<
std::basic_ostream< CharType, CharTrait > & operator<<(std::basic_ostream< CharType, CharTrait > &os, optional_detail::optional_tag const &)
Definition: optional/optional.hpp:1135
T
T
Definition: mem_fn_cc.hpp:25
boost
BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE.
boost::none_t
Definition: none_t.hpp:29
boost::operator>>
std::basic_istream< CharType, CharTrait > & operator>>(std::basic_istream< CharType, CharTrait > &in, optional< T > &v)
Definition: optional_io.hpp:56
d
d
boost::none
const none_t none((none_t::init_tag()))
none.hpp
optional.hpp
boost::move
BOOST_MOVE_FORCEINLINE ::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
Definition: utility_core.hpp:212
boost::optional
Definition: old_optional_implementation.hpp:646


sick_visionary_ros
Author(s): SICK AG TechSupport 3D Snapshot
autogenerated on Thu Feb 8 2024 03:45:34