Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <string>
- #include <set>
- #include <algorithm>
- #include <typeinfo>
- #include <map>
- #include <iostream>
- #include <fstream>
- using namespace std;
- namespace my
- {
- template<typename T>
- string typestr(T)
- {
- return "undefined";
- }
- string typestr(int)
- {
- return "int";
- }
- string typestr(bool)
- {
- return "bool";
- }
- template<typename T>
- string typestr(const set<T> &);
- template<typename T>
- string typestr(const vector<T> &);
- template<typename A, typename B>
- string typestr(const pair<A, B> &);
- template<typename K, typename V>
- string typestr(const map<K, V> &);
- template<typename T>
- string typestr(const set<T> &s)
- {
- T t;
- return "set<" + typestr(t) + ">";
- }
- template<typename T>
- string typestr(const vector<T> &v)
- {
- T t;
- return "vector<" + typestr(t) + ">";
- }
- template<typename A, typename B>
- string typestr(const pair<A, B> &p)
- {
- return "pair<" + typestr(p.first) + ", " + typestr(p.second) + ">";
- }
- template<typename K, typename V>
- string typestr(const map<K, V> &m)
- {
- K k;
- V v;
- return "map<" + typestr(k) + ", " + typestr(v) + ">";
- }
- template<typename T>
- ostream & operator<<(ostream &ofs, const vector<T> &v)
- {
- ofs << "{" + typestr(v) + ": ";
- for (typename vector<T>::const_iterator it = v.begin(); it != v.end(); ++it)
- {
- ofs << *it << " ";
- }
- ofs << "}";
- return ofs;
- }
- template<typename T>
- ostream & operator<<(ostream &ofs, const set<T> &s)
- {
- ofs << "{" + typestr(s) + ": ";
- for (typename set<T>::const_iterator it = s.begin(); it != s.end(); ++it)
- {
- ofs << *it << " ";
- }
- ofs << "}";
- return ofs;
- }
- template<typename K, typename V>
- ostream & operator<<(ostream &ofs, const map<K, V> &m)
- {
- ofs << "{" + typestr(m) + ": ";
- for (typename map<K, V>::const_iterator it = m.begin(); it != m.end(); ++it)
- {
- ofs << *it << " ";
- }
- ofs << "}";
- return ofs;
- }
- template<typename A, typename B>
- ostream & operator<<(ostream &ofs, const pair<A, B> &p)
- {
- ofs << "{" + typestr(p) + ": ";
- ofs << p.first << ", " << p.second;
- ofs << "}";
- return ofs;
- }
- }
- int main()
- {
- using namespace my;
- pair<set<int>, vector<map<bool, double> > > p;
- cout << p;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement