Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using std::cout;
- using std::endl;
- using std::vector;
- using std::string;
- template <class T>
- void print_size_and_contents(T v, string vn) {
- cout << "Size of " << vn << " " << v.size() << endl;
- cout << "Contents:";
- for (decltype(v.size()) i : v)
- cout << i << endl;
- }
- int main(void) {
- vector<int> v1;
- vector<int> v2(10);
- vector<int> v3(10, 42);
- vector<int> v4{10};
- vector<int> v5{10,42};
- vector<string> v6{10};
- vector<string> v7{10,"hi"};
- print_size_and_contents(v1, "v1");
- print_size_and_contents(v2, "v2");
- print_size_and_contents(v3, "v3");
- print_size_and_contents(v4, "v4");
- print_size_and_contents(v5, "v5");
- print_size_and_contents (v6, "v6");
- print_size_and_contents (v7, "v7");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement