• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[/
2    Boost.Optional
3
4    Copyright (c) 2003-2007 Fernando Luis Cacciola Carballal
5    Copyright (c) 2015 Andrzej Krzemienski
6
7    Distributed under the Boost Software License, Version 1.0.
8    (See accompanying file LICENSE_1_0.txt or copy at
9    http://www.boost.org/LICENSE_1_0.txt)
10]
11
12[section:io_header Header <boost/optional/optional_io.hpp>]
13
14[section:io_synop Synopsis]
15```
16#include <istream>
17#include <ostream>
18#include <boost/optional/optional.hpp>
19
20namespace boost {
21
22template <class CharType, class CharTrait, class T>
23  std::basic_ostream<CharType, CharTrait>&
24  operator<<(std::basic_ostream<CharType, CharTrait>& out, optional<T> const& v); ``[link reference_operator_ostream __GO_TO__]``
25
26  template <class CharType, class CharTrait>
27  std::basic_ostream<CharType, CharTrait>&
28  operator<<(std::basic_ostream<CharType, CharTrait>& out, none_t const&); ``[link reference_operator_ostream_none __GO_TO__]``
29
30template<class CharType, class CharTrait, class T>
31  std::basic_istream<CharType, CharTrait>&
32  operator>>(std::basic_istream<CharType, CharTrait>& in, optional<T>& v); ``[link reference_operator_istream __GO_TO__]``
33
34} // namespace boost
35```
36
37[endsect]
38
39[section:io_semantics Detailed semantics]
40
41
42[#reference_operator_ostream]
43
44
45`template <class CharType, class CharTrait, class T>` [br]
46\u00A0\u00A0\u00A0\u00A0`std::basic_ostream<CharType, CharTrait>&` [br]
47\u00A0\u00A0\u00A0\u00A0`operator<<(std::basic_ostream<CharType, CharTrait>& out, optional<T> const& v);`
48
49* [*Effect:] Outputs an implementation-defined string. The output contains the information about whether the optional object contains a value or not. If `v` contains a value, the output contains result of calling `out << *v`.
50* [*Returns:] `out`.
51
52__SPACE__
53[#reference_operator_ostream_none]
54
55`template <class CharType, class CharTrait, class T>` [br]
56\u00A0\u00A0\u00A0\u00A0`std::basic_ostream<CharType, CharTrait>&` [br]
57\u00A0\u00A0\u00A0\u00A0`operator<<(std::basic_ostream<CharType, CharTrait>& out, none_t);`
58
59* [*Effect:] Outputs an implementation-defined string.
60* [*Returns:] `out`.
61
62__SPACE__
63[#reference_operator_istream]
64
65`template <class CharType, class CharTrait, class T>` [br]
66\u00A0\u00A0\u00A0\u00A0`std::basic_ostream<CharType, CharTrait>&` [br]
67\u00A0\u00A0\u00A0\u00A0`operator>>(std::basic_istream<CharType, CharTrait>& in, optional<T>& v);`
68
69* [*Requires:] `T` is __SGI_DEFAULT_CONSTRUCTIBLE__ and __MOVE_CONSTRUCTIBLE__.
70* [*Effect:] Reads the value of optional object from `in`. If the string representation indicates that the optional object should contain a value, `v` contains a value and its contained value is obtained as if by default-constructing an object `o` of type `T` and then calling `in >> o`; otherwise `v` does not contain a value, and the previously contained value (if any) has been destroyed.
71* [*Returns:] `out`.
72
73[endsect]
74[endsect]
75