1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2009-2013. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/container for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 //[doc_type_erasure_MyClassHolder_h
12 #include <boost/container/vector.hpp>
16 //We don't need to include "MyClass.h"
17 //to store vector<MyClass>
24 void AddNewObject(const MyClass
&o
);
25 const MyClass
& GetLastObject() const;
28 ::boost::container::vector
<MyClass
> vector_
;
33 //[doc_type_erasure_MyClass_h
43 MyClass(int val
= 0) : value_(val
){}
45 friend bool operator==(const MyClass
&l
, const MyClass
&r
)
46 { return l
.value_
== r
.value_
; }
54 //[doc_type_erasure_main_cpp
58 //=#include "MyClassHolder.h"
59 //=#include "MyClass.h"
66 MyClassHolder myclassholder
;
67 myclassholder
.AddNewObject(mc
);
68 return myclassholder
.GetLastObject() == mc
? 0 : 1;
72 //[doc_type_erasure_MyClassHolder_cpp
76 //=#include "MyClassHolder.h"
78 //In the implementation MyClass must be a complete
79 //type so we include the appropriate header
80 //=#include "MyClass.h"
82 void MyClassHolder::AddNewObject(const MyClass
&o
)
83 { vector_
.push_back(o
); }
85 const MyClass
& MyClassHolder::GetLastObject() const
86 { return vector_
.back(); }