CASM  1.1.0
A Clusters Approach to Statistical Mechanics
stream_io.hh
Go to the documentation of this file.
1 #ifndef CASM_support_container_stream_io
2 #define CASM_support_container_stream_io
3 
4 #include <iostream>
5 #include <sstream>
6 #include <vector>
7 
8 namespace CASM {
9 template <class T>
10 std::istream &operator>>(std::istream &_in, std::vector<T> &vec) {
11  std::string line;
12  std::getline(_in, line, '\n');
13  std::stringstream tss(line);
14  T tval;
15  while (_in) {
16  _in >> tval;
17  vec.push_back(tval);
18  }
19 
20  return _in;
21 }
22 } // namespace CASM
23 
24 namespace std {
25 template <class T>
26 ostream &operator<<(ostream &out, const vector<T> &vec) {
27  if (vec.size() == 0) out << "[empty] ";
28  for (auto it = vec.cbegin(); it != vec.cend(); ++it) {
29  out << *it << " ";
30  }
31  return out;
32 }
33 } // namespace std
34 
35 #endif
Main CASM namespace.
Definition: APICommand.hh:8
std::istream & operator>>(std::istream &_in, std::vector< T > &vec)
Definition: stream_io.hh:10
Definition: stream_io.hh:24
ostream & operator<<(ostream &out, const vector< T > &vec)
Definition: stream_io.hh:26