-
Notifications
You must be signed in to change notification settings - Fork 0
/
rom_stream.h
46 lines (38 loc) · 1.36 KB
/
rom_stream.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef rom_stream_h
#define rom_stream_h
#include <vector>
#include <list>
/////////////////////////////////////////////////////////////////////////////////////////////////////////
template <class T> //let's teach the compiler how to print out an std::vector
std::ostream& operator << (std::ostream& os, const std::vector<T>& v) {
os << "std::vector{";
for (auto &ii : v){os << " (" << ii<<")";}
os << " }";
return os;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
template <class T> //print std::list to stream std::list
std::ostream& operator << (std::ostream& os, const std::list<T>& v) {
os << "std::list{";
for (auto &ii : v){os << " (" << ii<<")";}
os << " }";
return os;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#endif //rom_stream.h
/*example:
#include "rom_stream.h"
int main (void) {
std::vector<float> testval{0.0,1.7,7.4,0.004};
std::cout << testval <<std::endl;
std::list<float> tl{0.0,1.7,7.4,0.004};
std::cout << tl <<std::endl;
std::list<float> empty_list{};
std::cout << empty_list <<std::endl;
}
output should look like:
std::vector{ (0) (1.7) (7.4) (0.004) }
std::list{ (0) (1.7) (7.4) (0.004) }
std::list{ }
*/