Thread View: comp.std.c++
3 messages
3 total messages
Started by Greg Colvin
Sat, 30 Mar 1996 06:08
sample auto_ptr template
Author: Greg Colvin
Date: Sat, 30 Mar 1996 06:08
Date: Sat, 30 Mar 1996 06:08
41 lines
2242 bytes
2242 bytes
In Santa Cruz we decided to change the auto_ptr copy semantics to
allow returns of auto_ptr from functions. Following is a simple
implementation. It (almost) compiles with the latest Edison Design
Group front end (the template friend declaration choked it). Note
that on most architectures the owner bit can be overlayed with the
pointer for a smaller footprint, but the following is portable.
template<class X>
class auto_ptr {
mutable bool owner;
X* px;
template<class Y> friend class auto_ptr;
public:
explicit auto_ptr(X* p=0)
: owner(p), px(p) {}
template<class Y>
auto_ptr(const auto_ptr<Y>& r)
: owner(r.owner), px(r.release()) {}
template<class Y>
auto_ptr& operator=(const auto_ptr<Y>& r) {
if ((void*)&r != (void*)this) {
if (owner)
delete px;
owner = r.owner;
px = r.release();
}
return *this;
}
~auto_ptr() { if (owner) delete px; }
X& operator*() const { return *px; }
X* operator->() const { return px; }
X* get() const { return px; }
X* release() const { owner = 0; return px; }
};
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Re: sample auto_ptr template
Author: Nathan Myers, http://www.cantrip...
Date: Fri, 29 Mar 1996 18:22
Date: Fri, 29 Mar 1996 18:22
19 lines
1661 bytes
1661 bytes
Greg Colvin wrote: > In Santa Cruz we decided to change the auto_ptr copy semantics to > allow returns of auto_ptr from functions. Following is a simple > implementation. It (almost) compiles with the latest Edison Design > Group front end (the template friend declaration choked it). I hasten to add, in defense of John Spicer's sterling reputation, that this was not a released EDG front end, but John's pre-alpha working copy (i.e., only as reliable as other peoples' released versions :-). Nathan Myers ncm@cantrip.org --- [ comp.std.c++ is moderated. To submit articles: try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ] [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ] [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Re: sample auto_ptr template
Author: Greg Colvin
Date: Thu, 04 Apr 1996 18:15
Date: Thu, 04 Apr 1996 18:15
32 lines
2289 bytes
2289 bytes
In article <315D79CD.4F28E83E@cantrip.org> "Nathan Myers, http://www.cantrip.org/" <ncm@cantrip.org> writes:
>Greg Colvin wrote:
>> In Santa Cruz we decided to change the auto_ptr copy semantics to
>> allow returns of auto_ptr from functions. Following is a simple
>> implementation. It (almost) compiles with the latest Edison Design
>> Group front end (the template friend declaration choked it).
>
>I hasten to add, in defense of John Spicer's sterling reputation,
>that this was not a released EDG front end, but John's pre-alpha
>working copy (i.e., only as reliable as other peoples' released
>versions :-).
Yes, and I was most pleased to be able (at last) to compile auto_ptr.
Greg Colvin
gregor@netcom.com
>
>Nathan Myers
>ncm@cantrip.org
>---
>[ comp.std.c++ is moderated. To submit articles: try just posting with ]
>[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
>[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
>[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
>[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads