Good luck!
Tested for 1,2,3-d vectors.
template<typename T>
ostream& operator<< (ostream& out, const vector<T>& vec) {
out << "{ ";
size_t last = vec.size() - 1;
for(size_t i = 0; i < vec.size(); ++i) {
out << vec[i];
if (i != last)
out << ", ";
}
out << " }\n";
return out;
}
Tested only for 1-d vector. Each line seen as source of the 1-d vector.
template<typename T>
istream& operator>> (istream& in, vector<T>& vec) {
T item;
while (true) {
in >> item;
vec.push_back(item);
while (!in.eof() && (in.peek() == ' ' || in.peek() == '\t')) {
in.get();
}
if (in.eof() || in.peek() == '\n') {
break;
}
}
return in;
}
#ifdef QUICKTEST
#define cin testIStream
string test;
istringstream testIStream;
void genTest() {
// come on
}
#endif
// in main func
int main() {
// ...
#ifdef QUICKTEST
genTest();
testIStream = istringstream(test);
#endif
// ...
}
Helpful for avoiding use of global variables or parameters passing, the former dangerous and the latter clumsy.
type funcMaybeWithBugs() {
int n = 2;
// ...
auto localDebug = [=]() {
cout << n << endl;
// ...
};
// ...
localDebug();
// ...
localDebug();
}
Safe than brackets
cat xxx.cpp | perl -pe 's|\[([^\[]*?)]|.at(\1)|g' > xxx.tmp.cpp && mv xxx.tmp.cpp xxx.cpp
cat xxx.cpp | perl -pe 's|\.at\(([^\(]*?)\)|\[\1]|g' > xxx.rev.cpp && mv xxx.rev.cpp xxx.cpp