From -4046583691309537523
X-Google-Thread: 7894ca11fe,98decb90a5fd464a,start
X-Google-Attributes: gid7894ca11fe,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news2.google.com!news2.google.com!newsfeed.stanford.edu!news.kjsl.com!news.alt.net!frodo.cs.rpi.edu!not-for-mail
From: Scott Meyers <usenet@aristeia.com>
Newsgroups: comp.std.c++
Subject: Inconsistencies in unique_ptr and shared_ptr APIs
Date: Sun,  7 Jun 2009 20:16:49 CST
Organization: unknown
Lines: 30
Sender: cppmods@cs.rpi.edu
Approved: stephen.clamage@sun.com
Message-ID: <PqednU33tObEbrfXnZ2dnUVZ_tadnZ2d@posted.hevanet>
NNTP-Posting-Host: netlab.cs.rpi.edu
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
To: (Usenet)
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
X-Original-Date: Sat, 06 Jun 2009 15:55:06 -0700
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Xref: g2news2.google.com comp.std.c++:823

In September 2005, Joe Gottman posted to this group about inconsistencies in the
interfaces for unique_ptr and shared_ptr that bore no apparent relationship to
their fundamental functionality ( http://tinyurl.com/nmjwuu ). He noted that:
- "Shared_ptr has only operator ==, operator !=, and operator <.  Unique_ptr has
these three plus operator >, operator <=, and operator>=."
- Only unique_ptr has special support for arrays.
- Only shared_ptr supports const_pointer_cast, static_pointer_cast, and
dynamic_ptr_cast.

These discrepancies are also present in the current C++0x draft (N2857), so
presumably there is a reason for them.  Can somebody please explain what is is?

I'd also be interested to know why the type of the deleter is part of the type
of a unique_ptr but is not part of the type of a shared_ptr.

Finally, I'd like to know why unique_ptr gets its own subsection in the standard
(20.8.12) rather than being under "Smart pointers" (20.8.13) with shared_ptr and
weak_ptr.  (Heck, weak_ptr isn't even really a pointer, because it doesn't
overload operator->.)

Thanks for all enlightenment.

Scott

-- 
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



