🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2174

Re: Q: auto_ptr

#2174
From: J. Kanze
Date: Fri, 13 Oct 1995 08:26
51 lines
2075 bytes
Jean-Louis Moser (jlm@two-oo-one.fr) wrote:


|> I got the implementation of auto_ptr in the draft standard

|> - Is there a reason why the method operator=(T*) isn't
|>   implemented.

Not that I know of.

|> - Why operator= doesn't respect the classical sementic of
|>   this operator, returning T* to enable: p1 = p2 = p3;

Because returning T* wouldn't work anymore than the classical solution
(returning auto_ptr< T >&).

Returning T* in the above example would result in both p1 and p2 owning
the pointer.

Returning auto_ptr< T >& would cause the above to have strange
semantics.  Since the operator= also modifies the right hand side,  this
would be the equivalent of:

    p1 = p3 ;
    p2 = 0 ;

|> - With this implementation it's not possible to build auto_ptr
|>   on const T*, because constructor takes a T* as argument.

Sure it is, for any given T.  Try it: auto_ptr< int >, T == int;
auto_ptr< const int >, T == const int.

What you cannot do is the following:

    auto_ptr< int >         p( new int ) ;
    auto_ptr< const int >   pc( p ) ;

Unlike real pointers, there is no automatic conversion from pointer to
int to pointer to const int.
-- 
James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils en informatique industrielle--
                             --Beratung in industrieller Datenverarbeitung


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <45ivst$e58@gabi.gabi-soft.fr>
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt
References: <JLM.95Oct11152506@ludo.two-oo-one.fr>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt
From: kanze@gabi-soft.fr (J. Kanze)
Newsgroups: comp.std.c++
Subject: Re: Q: auto_ptr
Date: 13 Oct 1995 08:26:40 GMT
Organization: GABI Software, Sarl.
Approved: Matt@Austern
Message-ID: <45ivst$e58@gabi.gabi-soft.fr>
References: <JLM.95Oct11152506@ludo.two-oo-one.fr>
NNTP-Posting-Host: austern.hip.berkeley.edu