![]() |
Home | Libraries | People | FAQ | More |
The I/O operators: <<
and >>
work generically
on all Fusion sequences. The global operator<<
has been overloaded for generic
output streams such that _sequence_s
are output by recursively calling operator<<
for each element. Analogously,
the global operator>>
has been overloaded to extract _sequence_s
from generic input streams by recursively calling operator>>
for each element.
The default delimiter between the elements is space, and the Sequence is enclosed in parenthesis. For Example:
vector
<float, int, std::string> a(1.0f, 2, std::string("Howdy folks!");
cout << a;
outputs the vector
as: (1.0 2 Howdy folks!)
The library defines three manipulators for changing the default behavior:
Manipulators
tuple_open(arg)
tuple_close(arg)
tuple_delimiter(arg)
The argument to tuple_open
,
tuple_close
and tuple_delimiter
may be a char
, wchar_t
,
a C-string, or a wide C-string.
Example:
std::cout << tuple_open('[') << tuple_close(']') << tuple_delimiter(", ") << a;
outputs the same vector
, a
as: [1.0, 2, Howdy folks!]
The same manipulators work with operator>>
and istream
as well. Suppose the std::cin
stream contains the following data:
(1 2 3) [4:5]
The code:
vector
<int, int, int> i;vector
<int, int> j; std::cin >> i; std::cin >> set_open('[') >> set_close(']') >> set_delimiter(':'); std::cin >> j;
reads the data into the _vector_s
i
and j
.
Note that extracting _sequence_s
with std::string
or C-style string elements does
not generally work, since the streamed Sequence
representation may not be unambiguously parseable.
#include <boost/fusion/sequence/io.hpp>
Copyright © 2001-2007 Joel de Guzman, Dan Marsden, Tobias Schwinger |