
On 06/20/08 03:36, Phil Bouchard wrote:
Hi,
Upon trying to create the new shifted_allocator class that is instead to be passed as a template parameter on STL containers, I got stuck in a circle or errors. I came to realize there was not way to replace internal pointers used by containers with smart pointers... which is very unfortunate. There are different solution I could take but hopefully I won't need them.
By trying compiling shifted_ptr_test2.cpp in the Sandbox we'll get the following errors. I believe shifted_allocator (in shifted_allocator.hpp) should be represented the way it is but I may likely got something wrong because I haven't followed the verdict on this in previous posts:
...stl_vector.h: In member function `__gnu_cxx::__normal_iterator<typename _Alloc::const_pointer, std::vector<_Tp, _Alloc> > std::vector<_Tp, _Alloc>::begin() const [with _Tp = boost::detail::sh::shifted_ptr<vector>, _Alloc = boost::shifted_allocator<boost::detail::sh::shifted_ptr<vector>
]': ...stl_vector.h:221: instantiated from `std::vector<_Tp,
Hi Phil, Even if you could find some way for your allocator to work for vector, I don't think it would work for other stl containers. These other containers, e.g. std::list<_Tp>, use Allocator<_Tp>::pointer to point to other elements in the container. AFAICT, what's needed for garbage collections is Allocator<_Tp>::root_pointer. This would be a *smart* pointer to the head of the list in the case of std::list<_Tp> and all other pointer would just be _Tp*. In the case of std::vector<_Tp>, I guess the start of the vector would be a *smart* pointer to _Tp[]. The iterators for a GC'ed vector would have to retain a copy of the root_pointer, I guess, in order to keep the whole vector alive if even 1 iterator were still around. Anyway, I encountered a similar problem with the policy_ptr library I worked on years ago. The code used to be in the sandbox; hoever, I can't find it now. However, FWIW, there's this post: http://article.gmane.org/gmane.comp.lib.boost.devel/155407/match=policy_ptr -regards, Larry