Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Daniel Krügler<daniel.kruegler@googlemail.com> |
|---|---|
| Newsgroups | comp.std.c++ |
| Subject | Re: Smart pointer comparison - why a difference? |
| Date | 2012-05-29 11:25 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <jq1tsb$uth$1@dont-email.me> (permalink) |
| References | <a2i65qF4eeU1@mid.individual.net> |
On 2012-05-28 23:53, Bo Persson wrote: > In C++11, operator< for unique_ptr [unique.ptr.special] is defined as > > std::less<CT>()(x.get(), y.get()) > > where CT is the common_type of the unique_ptr's internal pointer typedefs. > > > On the other hand, operator< for shared_ptr [util.smartptr.shared.cmp] > is defined as > > std::less<V>()(a.get(), b.get()) > > "where V is the composite pointer type (5.9) of T* and U*." > > > What exactly is the difference, and why? The wording difference exists, because std::unique_ptr can hold both built-in pointers and pointer-like types while std::shared_ptr can only hold pointers. The intention is that unique_ptr's wording has exactly the same effect when it holds a pointer. Currently these definitions are not the same because of a wording defect of std::common_type. An issue has already been raised for this but is not yet visible in the official list. In short words, that defect is because std::common_type<int*, int*>::type evaluates to int*&& and not int*. This was an unintended side-effect because of change of the original definition of the conditional operator in the presence of xvalues. HTH& Greetings from Bremen, Daniel Krügler -- [ comp.std.c++ is moderated. To submit articles, try posting with your ] [ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to comp.std.c++ | Previous | Next — Previous in thread | Find similar
Smart pointer comparison - why a difference? Bo Persson<bop@gmb.dk> - 2012-05-28 14:53 -0700 Re: Smart pointer comparison - why a difference? Daniel Krügler<daniel.kruegler@googlemail.com> - 2012-05-29 11:25 -0700
csiph-web