Sign in to follow this  
Ryan_001

custom allocator error

Recommended Posts

Ryan_001    3476
I've been working on a very simple custom stl allocator and came across a funny error. I'm using VS2012 with the new CTP compiler. Now I was under the impression that with the new allocator_traits an allocator didn't need to supply a construct and destroy function (pg. 417 of n3337 states that default implementations of these functions are supplied by allocator_traits) but attempting to use the allocator with a std::vector caused a compile error stating these functions were missing. So I added them in, using the definitions from the standard and I got another peculiar error in the destroy function. The error I get is:
[CODE]error C2039: '˜T' : is not a member of 'std::_Container_proxy'[/CODE]

the function being:
[CODE]template <typename T, size_t N> void fixed_allocator<T,N>::destroy (pointer p) { p->˜T(); }[/CODE]

Now perhaps this is just a silly error on my part (in which case I apologize in advance), but there's 3 problems here:

1st is why do I even need to define construct()/destroy()? The standard seems pretty clear that these are not required. Is this a shortcoming of the VS2012 stl implementation or did I read the standard wrong?

2nd how is it even possible for a type not to have a destructor? I know you can declare a destructor private but that gives an access error, not an 'is not a member' error. I imagine that something like '~T() = delete;' might produce this error, but the declaration of 'std::_Container_proxy' is:
[CODE]
// CLASS _Container_proxy
struct _Container_proxy
{ // store head of iterator chain and back pointer
_Container_proxy()
: _Mycont(0), _Myfirstiter(0)
{ // construct from pointers
}
const _Container_base12 *_Mycont;
_Iterator_base12 *_Myfirstiter;
};
[/CODE]
Which has nothing of the sort. So this seems to be a really strange error.

3rd how would one go about fixing this?

Share this post


Link to post
Share on other sites
Ryan_001    3476
Ok figured out problem #2 and #3 (#1 still stands though). I had copied/pasted the p->~T(); from the standard pdf. Except that the ~ wasn't actually a tilde, but a similar looking unicode character of some kinda. Look nearly identical, but wasn't.... Ahh well, if I didn't make mistakes I wouldn't learn.

As far as #1 is concerned, I think its just the VS2012 library hasn't caught up, as the boost::container::vector works fine without construct and destroy.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this