Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

dinkumware fixes for VC7.1?

6 views
Skip to first unread message

Mycroft Holmes

unread,
Apr 15, 2004, 9:31:36 AM4/15/04
to
Hi to all,

I know there are at least 2 fixes for VC7.1 STL: one for vector<bool>
and the second for prev_permutation. Both were posted here.

1) is there some website where I can download the files?
2) is there any other known bug in the stl?

--
The set of solutions is never empty.
Two solutions together form a new problem.
-- Mycroft Holmes


P.J. Plauger

unread,
Apr 15, 2004, 10:24:25 AM4/15/04
to
"Mycroft Holmes" <m.ho...@nospam.it> wrote in message
news:eWhz73uI...@TK2MSFTNGP12.phx.gbl...

> I know there are at least 2 fixes for VC7.1 STL: one for vector<bool>
> and the second for prev_permutation. Both were posted here.
>
> 1) is there some website where I can download the files?

Not yet.

> 2) is there any other known bug in the stl?

The only other one discussed here is an esoteric one involving
a converting assignment to an auto_ptr.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com


Mycroft Holmes

unread,
Apr 16, 2004, 3:40:58 AM4/16/04
to
> > 2) is there any other known bug in the stl?
>
> The only other one discussed here is an esoteric one involving
> a converting assignment to an auto_ptr.
>

Now I remember: it was a stack overflow in creating an auto_ptr<const int>
from an auto_ptr<int>, but no fix was posted, was it?

P.J. Plauger

unread,
Apr 16, 2004, 6:28:51 AM4/16/04
to
"Mycroft Holmes" <m.ho...@nospam.it> wrote in message
news:eYMQpY4I...@TK2MSFTNGP11.phx.gbl...

> > > 2) is there any other known bug in the stl?
> >
> > The only other one discussed here is an esoteric one involving
> > a converting assignment to an auto_ptr.
> >
>
> Now I remember: it was a stack overflow in creating an auto_ptr<const int>
> from an auto_ptr<int>, but no fix was posted, was it?

No. For the record, the latest version is attached below.
It passes all conformance tests that I know of. (Note
that iterator debugging is not available in any of the
formal Microsoft releases; but the added code should be
harmless.)

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com

------

// TEMPLATE CLASS auto_ptr
template<class _Ty>
class auto_ptr;

template<class _Ty>
struct auto_ptr_ref
{ // proxy reference for auto_ptr copying
auto_ptr_ref(const void **_Right)
: _Ref(_Right)
{ // construct from generic pointer to auto_ptr ptr
}

const void **_Ref; // generic pointer to auto_ptr ptr
};

template<class _Ty>
class auto_ptr
{ // wrap an object pointer to ensure destruction
public:
typedef _Ty element_type;

explicit auto_ptr(_Ty *_Ptr = 0) _THROW0()
: _Myptr(_Ptr)
{ // construct from object pointer
}

auto_ptr(auto_ptr<_Ty>& _Right) _THROW0()
: _Myptr(_Right.release())
{ // construct by assuming pointer from _Right auto_ptr
}

auto_ptr(auto_ptr_ref<_Ty> _Right) _THROW0()
{ // construct by assuming pointer from _Right auto_ptr_ref
_Ty **_Pptr = (_Ty **)_Right._Ref;
_Ty *_Ptr = *_Pptr;
*_Pptr = 0; // release old
_Myptr = _Ptr; // reset this
}

template<class _Other>
operator auto_ptr<_Other>() _THROW0()
{ // convert to compatible auto_ptr
return (auto_ptr<_Other>(*this));
}

template<class _Other>
operator auto_ptr_ref<_Other>() _THROW0()
{ // convert to compatible auto_ptr_ref
_Other *_Testptr = (_Ty *)_Myptr; // test implicit conversion
auto_ptr_ref<_Other> _Ans(&_Myptr);
return (_Testptr != 0 ? _Ans : _Ans);
}

template<class _Other>
auto_ptr<_Ty>& operator=(auto_ptr<_Other>& _Right) _THROW0()
{ // assign compatible _Right (assume pointer)
reset(_Right.release());
return (*this);
}

template<class _Other>
auto_ptr(auto_ptr<_Other>& _Right) _THROW0()
: _Myptr(_Right.release())
{ // construct by assuming pointer from _Right
}

auto_ptr<_Ty>& operator=(auto_ptr<_Ty>& _Right) _THROW0()
{ // assign compatible _Right (assume pointer)
reset(_Right.release());
return (*this);
}

auto_ptr<_Ty>& operator=(auto_ptr_ref<_Ty> _Right) _THROW0()
{ // assign compatible _Right._Ref (assume pointer)
_Ty **_Pptr = (_Ty **)_Right._Ref;
_Ty *_Ptr = *_Pptr;
*_Pptr = 0; // release old
reset(_Ptr); // set new
return (*this);
}

~auto_ptr()
{ // destroy the object
delete (_Ty *)_Myptr;
}

_Ty& operator*() const _THROW0()
{ // return designated value

#if _HAS_ITERATOR_DEBUGGING
if (_Myptr == 0)
_DEBUG_ERROR("auto_ptr not dereferencable");
#endif /* _HAS_ITERATOR_DEBUGGING */

return (*(_Ty *)_Myptr);
}

_Ty *operator->() const _THROW0()
{ // return pointer to class object
return (&**this);
}

_Ty *get() const _THROW0()
{ // return wrapped pointer
return ((_Ty *)_Myptr);
}

_Ty *release() _THROW0()
{ // return wrapped pointer and give up ownership
_Ty *_Tmp = (_Ty *)_Myptr;
_Myptr = 0;
return (_Tmp);
}

void reset(_Ty* _Ptr = 0)
{ // destroy designated object and store new pointer
if (_Ptr != _Myptr)
delete (_Ty *)_Myptr;
_Myptr = _Ptr;
}

private:
const void *_Myptr; // the wrapped object pointer
};


Mycroft Holmes

unread,
Apr 20, 2004, 4:03:13 AM4/20/04
to
Hi again,

I looked at your code, and I have a question:


template<class _Other>
operator auto_ptr_ref<_Other>() _THROW0()
{ // convert to compatible auto_ptr_ref
_Other *_Testptr = (_Ty *)_Myptr; // test implicit conversion
auto_ptr_ref<_Other> _Ans(&_Myptr);

//
// what's the purpose of this line?
//


return (_Testptr != 0 ? _Ans : _Ans);
}

P.J. Plauger

unread,
Apr 20, 2004, 7:35:44 AM4/20/04
to
"Mycroft Holmes" <m.ho...@nospam.it> wrote in message
news:um0wv3qJ...@TK2MSFTNGP10.phx.gbl...

> I looked at your code, and I have a question:
>
>
> template<class _Other>
> operator auto_ptr_ref<_Other>() _THROW0()
> { // convert to compatible auto_ptr_ref
> _Other *_Testptr = (_Ty *)_Myptr; // test implicit conversion
> auto_ptr_ref<_Other> _Ans(&_Myptr);
> //
> // what's the purpose of this line?
> //
> return (_Testptr != 0 ? _Ans : _Ans);
> }

It shuts up a warning that _Testptr is otherwise unused.

0 new messages