blob: af37a3af90875f50de9075cdb8946df0d2151179 (
plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#include <string>
#include <vector>
#include <list>
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <iterator>
template<typename T>
struct V : std::vector<T>
{
V(const T& v) : std::vector<T>(10, v) {}
void anotherone(const T& v)
{
push_back(v);
}
};
template<typename C, typename T>
void test_container(C& v, T x)
{
v.push_back(x);
};
void test_sstream(std::basic_ostringstream<char>& str)
{
str << "Example:\n ";
}
int main()
{
std::string s = "abc";
V<std::string> v(s);
test_container(v, "xyz");
v.anotherone("ABC");
std::vector<bool> vb;
vb.push_back(true);
test_container(vb, false);
vb[0] = vb[1];
std::cout << vb.size() << std::endl;
std::list<int> l;
l.push_front(-88);
test_container(l, 42);
std::cout << l.size() << std::endl;
std::map<std::string,double> m;
m["example"] = 47.11;
m.insert(std::make_pair("kdbg", 3.14));
std::cout << m.size() << std::endl;
std::ostringstream dump;
test_sstream(dump);
std::copy(v.begin(), v.end(), std::ostream_iterator<std::string>(dump, "\n "));
std::cout << dump.str() << std::endl;
}
|