Debian Codegraph @

yo/advancedtemplates/examples/plainalloc.h

raw
1 #ifndef INCLUDED_PLAINALLOC_H_
2 #define INCLUDED_PLAINALLOC_H_
3
4 #include <ostream>
5
6 template <typename Data>
7 class PlainAlloc: public std::allocator<Data>
8 {
9 template<typename IData>
10 friend std::ostream &operator<<(std::ostream &out,
11 PlainAlloc<IData> const &alloc);
12 Data d_data;
13
14 public:
15 PlainAlloc();
16 PlainAlloc(Data data);
17 PlainAlloc(PlainAlloc<Data> const &other);
18 operator Data &();
19 PlainAlloc &operator=(Data const &data);
20 };
21
22 template <typename Data>
23 PlainAlloc<Data>::PlainAlloc()
24 {}
25
26 template <typename Data>
27 PlainAlloc<Data>::PlainAlloc(Data data)
28 :
29 d_data(data)
30 {}
31
32 template <typename Data>
33 PlainAlloc<Data>::PlainAlloc(PlainAlloc<Data> const &other)
34 :
35 d_data(other.d_data)
36 {}
37
38 template <typename Data>
39 PlainAlloc<Data>::operator Data &()
40 {
41 return d_data;
42 }
43
44 template <typename Data>
45 PlainAlloc<Data> &PlainAlloc<Data>::operator=(Data const &data)
46 {
47 d_data = data;
48 }
49
50 template<typename IData>
51 inline std::ostream &operator<<(std::ostream &out,
52 PlainAlloc<IData> const &alloc)
53 {
54 return out << alloc.d_data;
55 }
56
57
58
59 #endif