Topic: Add comparison operators between smart pointers


Author: DeadMG <wolfeinstein@gmail.com>
Date: Tue, 24 Sep 2013 07:08:56 -0700 (PDT)
Raw View
------=_Part_136_9990930.1380031736971
Content-Type: text/plain; charset=ISO-8859-1

Heterogenous lookup here for unique_ptr is much more complex than simply
having the appropriate comparison operator. There is already a paper on
this- N3575, if I recall, authored by me. Then there's a bunch of implicit
conversion safety issues. The fact that this doesn't work is very vexing,
but simply throwing an operator at the problem won't fix it.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_136_9990930.1380031736971
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Heterogenous lookup here for unique_ptr is much more compl=
ex than simply having the appropriate comparison operator. There is already=
 a paper on this- N3575, if I recall, authored by me. Then there's a bunch =
of implicit conversion safety issues. The fact that this doesn't work is ve=
ry vexing, but simply throwing an operator at the problem won't fix it.</di=
v>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_136_9990930.1380031736971--

.


Author: MasterT <tom.deseyn@gmail.com>
Date: Tue, 24 Sep 2013 12:36:16 -0700 (PDT)
Raw View
------=_Part_4830_19736462.1380051376647
Content-Type: text/plain; charset=ISO-8859-1

Hi DeadMG,

Can you provide another pointer to the paper you refer to? (N3575 is about
something else)
Also some examples of implicit conversion safety issues would be great as
well.

Thanks!
Wkr,

Tom

Op dinsdag 24 september 2013 16:08:56 UTC+2 schreef DeadMG:
>
> Heterogenous lookup here for unique_ptr is much more complex than simply
> having the appropriate comparison operator. There is already a paper on
> this- N3575, if I recall, authored by me. Then there's a bunch of implicit
> conversion safety issues. The fact that this doesn't work is very vexing,
> but simply throwing an operator at the problem won't fix it.
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_4830_19736462.1380051376647
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi DeadMG,<div><br></div><div>Can you provide another poin=
ter to the paper you refer to? (N3575 is about something else)<br></div><di=
v>Also some examples of implicit conversion safety issues would be great as=
 well.</div><div><br></div><div>Thanks!</div><div>Wkr,</div><div><br></div>=
<div>Tom</div><div><br>Op dinsdag 24 september 2013 16:08:56 UTC+2 schreef =
DeadMG:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Hetero=
genous lookup here for unique_ptr is much more complex than simply having t=
he appropriate comparison operator. There is already a paper on this- N3575=
, if I recall, authored by me. Then there's a bunch of implicit conversion =
safety issues. The fact that this doesn't work is very vexing, but simply t=
hrowing an operator at the problem won't fix it.</div></blockquote></div></=
div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_4830_19736462.1380051376647--

.


Author: DeadMG <wolfeinstein@gmail.com>
Date: Tue, 24 Sep 2013 12:38:24 -0700 (PDT)
Raw View
------=_Part_380_2541950.1380051504962
Content-Type: text/plain; charset=ISO-8859-1

It was N3573.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_380_2541950.1380051504962
Content-Type: text/html; charset=ISO-8859-1

<div dir="ltr">It was N3573.</div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />

------=_Part_380_2541950.1380051504962--

.


Author: MasterT <tom.deseyn@gmail.com>
Date: Wed, 25 Sep 2013 11:33:55 -0700 (PDT)
Raw View
------=_Part_761_23836135.1380134035202
Content-Type: text/plain; charset=ISO-8859-1

Hi DeadMG,

The proposal doesn't talk about comparison operators between smart pointers
and raw pointers. Nor does it show what implicit conversion safety issues
could result from them. Could you clarify this with an example?

Thanks,

Tom

Op dinsdag 24 september 2013 21:38:24 UTC+2 schreef DeadMG:
>
> It was N3573.
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_761_23836135.1380134035202
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi DeadMG,<div><br></div><div>The proposal doesn't talk ab=
out comparison operators between smart pointers and raw pointers. Nor does =
it show what implicit conversion safety issues could result from them. Coul=
d you clarify this with an example?</div><div><br></div><div>Thanks,</div><=
div><br></div><div>Tom<br><br>Op dinsdag 24 september 2013 21:38:24 UTC+2 s=
chreef DeadMG:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"=
>It was N3573.</div></blockquote></div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_761_23836135.1380134035202--

.


Author: MasterT <tom.deseyn@gmail.com>
Date: Sat, 28 Sep 2013 05:41:07 -0700 (PDT)
Raw View
------=_Part_155_32168514.1380372067355
Content-Type: text/plain; charset=ISO-8859-1

bump

Op maandag 23 september 2013 21:46:53 UTC+2 schreef MasterT:
>
> Hi all,
>
> There are some questions on stack overflow related using a raw pointer for
> lookup in a unique_ptr container:
> *
> http://stackoverflow.com/questions/17851088/using-a-stdunordered-set-of-stdunique-ptr
> *
> http://stackoverflow.com/questions/18055183/no-standard-way-to-compare-smart-pointer-with-regular-pointer
> *
> http://stackoverflow.com/questions/18939882/raw-pointer-lookup-for-sets-of-unique-ptrs
>
> The second question is by me, and the third question triggered me writing
> down this post to know your thoughts on the following:
>
> Wouldn't it make sense to have comparison operators (==, !=, <, ...)
> between smart pointers and raw pointers?
> Currently the operators require the type to match, and this drags in
> "ownership" into the equation.
> If the pointers are equal, they should have the same idea about ownership
> anyhow.
> When comparing to the raw pointer, you indicate you do not want to take
> the ownership into account.
>
> As smart pointers are ordered/hashed based on raw pointer values, a
> heterogeneous lookup can work.
>
> Thanks for your inputs,
> Wkr,
>
> Tom
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_155_32168514.1380372067355
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">bump<br><br>Op maandag 23 september 2013 21:46:53 UTC+2 sc=
hreef MasterT:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"=
>Hi all,<div><br></div><div>There are some questions on stack overflow rela=
ted using a raw pointer for lookup in a unique_ptr container:</div><div><di=
v>* <a href=3D"http://stackoverflow.com/questions/17851088/using-a-stdunord=
ered-set-of-stdunique-ptr" target=3D"_blank">http://stackoverflow.com/<wbr>=
questions/17851088/using-a-<wbr>stdunordered-set-of-stdunique-<wbr>ptr</a><=
/div><div>* <a href=3D"http://stackoverflow.com/questions/18055183/no-stand=
ard-way-to-compare-smart-pointer-with-regular-pointer" target=3D"_blank">ht=
tp://stackoverflow.com/<wbr>questions/18055183/no-<wbr>standard-way-to-comp=
are-smart-<wbr>pointer-with-regular-pointer</a></div></div><div>*&nbsp;<a h=
ref=3D"http://stackoverflow.com/questions/18939882/raw-pointer-lookup-for-s=
ets-of-unique-ptrs" target=3D"_blank">http://stackoverflow.com/<wbr>questio=
ns/18939882/raw-<wbr>pointer-lookup-for-sets-of-<wbr>unique-ptrs</a></div><=
div><br></div><div>The second question is by me, and the third question tri=
ggered me writing down this post to know your thoughts on the following:</d=
iv><div><br></div><div>Wouldn't it make sense to have comparison operators =
(=3D=3D, !=3D, &lt;, ...) between smart pointers and raw pointers?</div><di=
v>Currently the operators require the type to match, and this drags in "own=
ership" into the equation.</div><div>If the pointers are equal, they should=
 have the same idea about ownership anyhow.</div><div>When comparing to the=
 raw pointer, you indicate you do not want to take the ownership into accou=
nt.<br></div><div><br></div><div>As smart pointers are ordered/hashed based=
 on raw pointer values, a heterogeneous lookup can work.</div><div><br></di=
v><div>Thanks for your inputs,</div><div>Wkr,</div><div><br></div><div>Tom<=
/div></div></blockquote></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_155_32168514.1380372067355--

.


Author: Jo Bates <jbates@jbat.es>
Date: Sun, 29 Sep 2013 07:23:28 -0700 (PDT)
Raw View
------=_Part_1838_5473210.1380464608942
Content-Type: text/plain; charset=ISO-8859-1

Hi all. I'm the original asker of
http://stackoverflow.com/questions/18939882/raw-pointer-lookup-for-sets-of-unique-ptrs.
I agree with MasterT: I would like to know what the safety issues are with
adding the operators in such a way that they get used implicitly, but why
not standardize functors in-place of the operators? Copy-pasting the the
solution from StackOverflow:

template<typename T>struct pointer_comp {
  typedef std::true_type is_transparent;
  // helper does some magic in order to reduce the number of
  // pairs of types we need to know how to compare: it turns
  // everything into a pointer, and then uses `std::less<T*>`
  // to do the comparison:
  struct helper {
    T* ptr;
    helper():ptr(nullptr) {}
    helper(helper const&) = default;
    helper(T* p):ptr(p) {}
    template<typename U>
    helper( std::shared_ptr<U> const& sp ):ptr(sp.get()) {}
    template<typename U>
    helper( std::unique_ptr<U> const& sp ):ptr(sp.get()) {}
    bool operator<()( helper o ) const {
      return std::less<T*>()( ptr, o.ptr );
    }
  };
  // without helper, we'd need 2^n different overloads, where
  // n is the number of types we want to support (so, 8 with
  // raw pointers, unique pointers, and shared pointers).  That
  // seems silly:
  bool operator()( helper lhs, helper rhs ) const {
    return lhs < rhs;
  }};


I would have called it ptr_less. Similar functors like std::ptr_equal_to,
etc. could be defined as well. They would be useful alongside the new
heterogenous lookup for associative containers, e.g., searching for a
member of an std::set<std::unique_ptr> using a raw pointer.

On Saturday, September 28, 2013 7:41:07 AM UTC-5, MasterT wrote:
>
> bump
>
> Op maandag 23 september 2013 21:46:53 UTC+2 schreef MasterT:
>>
>> Hi all,
>>
>> There are some questions on stack overflow related using a raw pointer
>> for lookup in a unique_ptr container:
>> *
>> http://stackoverflow.com/questions/17851088/using-a-stdunordered-set-of-stdunique-ptr
>> *
>> http://stackoverflow.com/questions/18055183/no-standard-way-to-compare-smart-pointer-with-regular-pointer
>> *
>> http://stackoverflow.com/questions/18939882/raw-pointer-lookup-for-sets-of-unique-ptrs
>>
>> The second question is by me, and the third question triggered me writing
>> down this post to know your thoughts on the following:
>>
>> Wouldn't it make sense to have comparison operators (==, !=, <, ...)
>> between smart pointers and raw pointers?
>> Currently the operators require the type to match, and this drags in
>> "ownership" into the equation.
>> If the pointers are equal, they should have the same idea about ownership
>> anyhow.
>> When comparing to the raw pointer, you indicate you do not want to take
>> the ownership into account.
>>
>> As smart pointers are ordered/hashed based on raw pointer values, a
>> heterogeneous lookup can work.
>>
>> Thanks for your inputs,
>> Wkr,
>>
>> Tom
>>
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_1838_5473210.1380464608942
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi all. I'm the original asker of <a href=3D"http://stacko=
verflow.com/questions/18939882/raw-pointer-lookup-for-sets-of-unique-ptrs" =
target=3D"_blank">http://stackoverflow.com/<wbr>questions/18939882/raw-<wbr=
>pointer-lookup-for-sets-of-<wbr>unique-ptrs</a>. I agree with MasterT: I w=
ould like to know what the safety issues are with adding the operators in s=
uch a way that they get used implicitly, but why not standardize functors i=
n-place of the operators? Copy-pasting the the solution from StackOverflow:=
<br><br><pre style=3D"" class=3D"default prettyprint prettyprinted"><code><=
span class=3D"kwd">template</span><span class=3D"pun">&lt;</span><span clas=
s=3D"kwd">typename</span><span class=3D"pln"> T</span><span class=3D"pun">&=
gt;</span><span class=3D"pln">
</span><span class=3D"kwd">struct</span><span class=3D"pln"> pointer_comp <=
/span><span class=3D"pun">{</span><span class=3D"pln">
  </span><span class=3D"kwd">typedef</span><span class=3D"pln"> std</span><=
span class=3D"pun">::</span><span class=3D"pln">true_type is_transparent</s=
pan><span class=3D"pun">;</span><span class=3D"pln">
  </span><span class=3D"com">// helper does some magic in order to reduce t=
he number of</span><span class=3D"pln">
  </span><span class=3D"com">// pairs of types we need to know how to compa=
re: it turns</span><span class=3D"pln">
  </span><span class=3D"com">// everything into a pointer, and then uses `s=
td::less&lt;T*&gt;`</span><span class=3D"pln">
  </span><span class=3D"com">// to do the comparison:</span><span class=3D"=
pln">
  </span><span class=3D"kwd">struct</span><span class=3D"pln"> helper </spa=
n><span class=3D"pun">{</span><span class=3D"pln">
    T</span><span class=3D"pun">*</span><span class=3D"pln"> ptr</span><spa=
n class=3D"pun">;</span><span class=3D"pln">
    helper</span><span class=3D"pun">():</span><span class=3D"pln">ptr</spa=
n><span class=3D"pun">(</span><span class=3D"kwd">nullptr</span><span class=
=3D"pun">)</span><span class=3D"pln"> </span><span class=3D"pun">{}</span><=
span class=3D"pln">
    helper</span><span class=3D"pun">(</span><span class=3D"pln">helper </s=
pan><span class=3D"kwd">const</span><span class=3D"pun">&amp;)</span><span =
class=3D"pln"> </span><span class=3D"pun">=3D</span><span class=3D"pln"> </=
span><span class=3D"kwd">default</span><span class=3D"pun">;</span><span cl=
ass=3D"pln">
    helper</span><span class=3D"pun">(</span><span class=3D"pln">T</span><s=
pan class=3D"pun">*</span><span class=3D"pln"> p</span><span class=3D"pun">=
):</span><span class=3D"pln">ptr</span><span class=3D"pun">(</span><span cl=
ass=3D"pln">p</span><span class=3D"pun">)</span><span class=3D"pln"> </span=
><span class=3D"pun">{}</span><span class=3D"pln">
    </span><span class=3D"kwd">template</span><span class=3D"pun">&lt;</spa=
n><span class=3D"kwd">typename</span><span class=3D"pln"> U</span><span cla=
ss=3D"pun">&gt;</span><span class=3D"pln">
    helper</span><span class=3D"pun">(</span><span class=3D"pln"> std</span=
><span class=3D"pun">::</span><span class=3D"pln">shared_ptr</span><span cl=
ass=3D"pun">&lt;</span><span class=3D"pln">U</span><span class=3D"pun">&gt;=
</span><span class=3D"pln"> </span><span class=3D"kwd">const</span><span cl=
ass=3D"pun">&amp;</span><span class=3D"pln"> sp </span><span class=3D"pun">=
):</span><span class=3D"pln">ptr</span><span class=3D"pun">(</span><span cl=
ass=3D"pln">sp</span><span class=3D"pun">.</span><span class=3D"kwd">get</s=
pan><span class=3D"pun">())</span><span class=3D"pln"> </span><span class=
=3D"pun">{}</span><span class=3D"pln">
    </span><span class=3D"kwd">template</span><span class=3D"pun">&lt;</spa=
n><span class=3D"kwd">typename</span><span class=3D"pln"> U</span><span cla=
ss=3D"pun">&gt;</span><span class=3D"pln">
    helper</span><span class=3D"pun">(</span><span class=3D"pln"> std</span=
><span class=3D"pun">::</span><span class=3D"pln">unique_ptr</span><span cl=
ass=3D"pun">&lt;</span><span class=3D"pln">U</span><span class=3D"pun">&gt;=
</span><span class=3D"pln"> </span><span class=3D"kwd">const</span><span cl=
ass=3D"pun">&amp;</span><span class=3D"pln"> sp </span><span class=3D"pun">=
):</span><span class=3D"pln">ptr</span><span class=3D"pun">(</span><span cl=
ass=3D"pln">sp</span><span class=3D"pun">.</span><span class=3D"kwd">get</s=
pan><span class=3D"pun">())</span><span class=3D"pln"> </span><span class=
=3D"pun">{}</span><span class=3D"pln">
    </span><span class=3D"kwd">bool</span><span class=3D"pln"> </span><span=
 class=3D"kwd">operator</span><span class=3D"pun">&lt;()(</span><span class=
=3D"pln"> helper o </span><span class=3D"pun">)</span><span class=3D"pln"> =
</span><span class=3D"kwd">const</span><span class=3D"pln"> </span><span cl=
ass=3D"pun">{</span><span class=3D"pln">
      </span><span class=3D"kwd">return</span><span class=3D"pln"> std</spa=
n><span class=3D"pun">::</span><span class=3D"pln">less</span><span class=
=3D"pun">&lt;</span><span class=3D"pln">T</span><span class=3D"pun">*&gt;()=
(</span><span class=3D"pln"> ptr</span><span class=3D"pun">,</span><span cl=
ass=3D"pln"> o</span><span class=3D"pun">.</span><span class=3D"pln">ptr </=
span><span class=3D"pun">);</span><span class=3D"pln">
    </span><span class=3D"pun">}</span><span class=3D"pln">
  </span><span class=3D"pun">};</span><span class=3D"pln">
  </span><span class=3D"com">// without helper, we'd need 2^n different ove=
rloads, where</span><span class=3D"pln">
  </span><span class=3D"com">// n is the number of types we want to support=
 (so, 8 with</span><span class=3D"pln">
  </span><span class=3D"com">// raw pointers, unique pointers, and shared p=
ointers).  That</span><span class=3D"pln">
  </span><span class=3D"com">// seems silly:</span><span class=3D"pln">
  </span><span class=3D"kwd">bool</span><span class=3D"pln"> </span><span c=
lass=3D"kwd">operator</span><span class=3D"pun">()(</span><span class=3D"pl=
n"> helper lhs</span><span class=3D"pun">,</span><span class=3D"pln"> helpe=
r rhs </span><span class=3D"pun">)</span><span class=3D"pln"> </span><span =
class=3D"kwd">const</span><span class=3D"pln"> </span><span class=3D"pun">{=
</span><span class=3D"pln">
    </span><span class=3D"kwd">return</span><span class=3D"pln"> lhs </span=
><span class=3D"pun">&lt;</span><span class=3D"pln"> rhs</span><span class=
=3D"pun">;</span><span class=3D"pln">
  </span><span class=3D"pun">}</span><span class=3D"pln">
</span><span class=3D"pun">};<br></span></code></pre><br>I would have calle=
d it ptr_less. Similar functors like std::ptr_equal_to, etc. could be defin=
ed as well. They would be useful alongside the new heterogenous lookup for =
associative containers, e.g., searching for a member of an std::set&lt;std:=
:unique_ptr&gt; using a raw pointer.<br><br>On Saturday, September 28, 2013=
 7:41:07 AM UTC-5, MasterT wrote:<blockquote class=3D"gmail_quote" style=3D=
"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex=
;"><div dir=3D"ltr">bump<br><br>Op maandag 23 september 2013 21:46:53 UTC+2=
 schreef MasterT:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin=
-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">H=
i all,<div><br></div><div>There are some questions on stack overflow relate=
d using a raw pointer for lookup in a unique_ptr container:</div><div><div>=
* <a href=3D"http://stackoverflow.com/questions/17851088/using-a-stdunorder=
ed-set-of-stdunique-ptr" target=3D"_blank">http://stackoverflow.com/<wbr>qu=
estions/17851088/using-a-<wbr>stdunordered-set-of-stdunique-<wbr>ptr</a></d=
iv><div>* <a href=3D"http://stackoverflow.com/questions/18055183/no-standar=
d-way-to-compare-smart-pointer-with-regular-pointer" target=3D"_blank">http=
://stackoverflow.com/<wbr>questions/18055183/no-<wbr>standard-way-to-compar=
e-smart-<wbr>pointer-with-regular-pointer</a></div></div><div>*&nbsp;<a hre=
f=3D"http://stackoverflow.com/questions/18939882/raw-pointer-lookup-for-set=
s-of-unique-ptrs" target=3D"_blank">http://stackoverflow.com/<wbr>questions=
/18939882/raw-<wbr>pointer-lookup-for-sets-of-<wbr>unique-ptrs</a></div><di=
v><br></div><div>The second question is by me, and the third question trigg=
ered me writing down this post to know your thoughts on the following:</div=
><div><br></div><div>Wouldn't it make sense to have comparison operators (=
=3D=3D, !=3D, &lt;, ...) between smart pointers and raw pointers?</div><div=
>Currently the operators require the type to match, and this drags in "owne=
rship" into the equation.</div><div>If the pointers are equal, they should =
have the same idea about ownership anyhow.</div><div>When comparing to the =
raw pointer, you indicate you do not want to take the ownership into accoun=
t.<br></div><div><br></div><div>As smart pointers are ordered/hashed based =
on raw pointer values, a heterogeneous lookup can work.</div><div><br></div=
><div>Thanks for your inputs,</div><div>Wkr,</div><div><br></div><div>Tom</=
div></div></blockquote></div></blockquote></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_1838_5473210.1380464608942--

.


Author: jbates@jbat.es
Date: Fri, 27 Sep 2013 13:35:37 -0700 (PDT)
Raw View
------=_Part_718_12914307.1380314137224
Content-Type: text/plain; charset=ISO-8859-1

I was the asker of
http://stackoverflow.com/questions/18939882/raw-pointer-lookup-for-sets-of-unique-ptrs.
I agree we should do *something* about this issue, but adding the operators
in such a place that they get implicitly used might be dangerous. Why not
standardize comparator functors instead, e.g., something like Yakk on
StackOverFLow proposed:

template<typename T>struct pointer_comp {
  typedef std::true_type is_transparent;
  // helper does some magic in order to reduce the number of
  // pairs of types we need to know how to compare: it turns
  // everything into a pointer, and then uses `std::less<T*>`
  // to do the comparison:
  struct helper {
    T* ptr;
    helper():ptr(nullptr) {}
    helper(helper const&) = default;
    helper(T* p):ptr(p) {}
    template<typename U>
    helper( std::shared_ptr<U> const& sp ):ptr(sp.get()) {}
    template<typename U>
    helper( std::unique_ptr<U> const& sp ):ptr(sp.get()) {}
    bool operator<()( helper o ) const {
      return std::less<T*>()( ptr, o.ptr );
    }
  };
  // without helper, we'd need 2^n different overloads, where
  // n is the number of types we want to support (so, 8 with
  // raw pointers, unique pointers, and shared pointers).  That
  // seems silly:
  bool operator()( helper lhs, helper rhs ) const {
    return lhs < rhs;
  }};


I'm just copy-pasting what he wrote. I'd prefer the name ptr_less or
similar. I think it would go nicely with the new heterogenous comparison
lookup for associative containers.

As a side note: I think it would be awesome if we need something similar
with std::hash for unordered_maps and unordered_sets, but that's another
topic for another day. I'll probably start a new thread about it sometime
this weekend.

On Monday, September 23, 2013 2:46:53 PM UTC-5, MasterT wrote:
>
> Hi all,
>
> There are some questions on stack overflow related using a raw pointer for
> lookup in a unique_ptr container:
> *
> http://stackoverflow.com/questions/17851088/using-a-stdunordered-set-of-stdunique-ptr
> *
> http://stackoverflow.com/questions/18055183/no-standard-way-to-compare-smart-pointer-with-regular-pointer
> *
> http://stackoverflow.com/questions/18939882/raw-pointer-lookup-for-sets-of-unique-ptrs
>
> The second question is by me, and the third question triggered me writing
> down this post to know your thoughts on the following:
>
> Wouldn't it make sense to have comparison operators (==, !=, <, ...)
> between smart pointers and raw pointers?
> Currently the operators require the type to match, and this drags in
> "ownership" into the equation.
> If the pointers are equal, they should have the same idea about ownership
> anyhow.
> When comparing to the raw pointer, you indicate you do not want to take
> the ownership into account.
>
> As smart pointers are ordered/hashed based on raw pointer values, a
> heterogeneous lookup can work.
>
> Thanks for your inputs,
> Wkr,
>
> Tom
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_718_12914307.1380314137224
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I was the asker of <a href=3D"http://stackoverflow.com/que=
stions/18939882/raw-pointer-lookup-for-sets-of-unique-ptrs" target=3D"_blan=
k">http://stackoverflow.com/<wbr>questions/18939882/raw-<wbr>pointer-lookup=
-for-sets-of-<wbr>unique-ptrs</a>. I agree we should do <i>something</i> ab=
out this issue, but adding the operators in such a place that they get impl=
icitly used might be dangerous. Why not standardize comparator functors ins=
tead, e.g., something like Yakk on StackOverFLow proposed:<br><br><pre styl=
e=3D"" class=3D"default prettyprint prettyprinted"><code><span class=3D"kwd=
">template</span><span class=3D"pun">&lt;</span><span class=3D"kwd">typenam=
e</span><span class=3D"pln"> T</span><span class=3D"pun">&gt;</span><span c=
lass=3D"pln">
</span><span class=3D"kwd">struct</span><span class=3D"pln"> pointer_comp <=
/span><span class=3D"pun">{</span><span class=3D"pln">
  </span><span class=3D"kwd">typedef</span><span class=3D"pln"> std</span><=
span class=3D"pun">::</span><span class=3D"pln">true_type is_transparent</s=
pan><span class=3D"pun">;</span><span class=3D"pln">
  </span><span class=3D"com">// helper does some magic in order to reduce t=
he number of</span><span class=3D"pln">
  </span><span class=3D"com">// pairs of types we need to know how to compa=
re: it turns</span><span class=3D"pln">
  </span><span class=3D"com">// everything into a pointer, and then uses `s=
td::less&lt;T*&gt;`</span><span class=3D"pln">
  </span><span class=3D"com">// to do the comparison:</span><span class=3D"=
pln">
  </span><span class=3D"kwd">struct</span><span class=3D"pln"> helper </spa=
n><span class=3D"pun">{</span><span class=3D"pln">
    T</span><span class=3D"pun">*</span><span class=3D"pln"> ptr</span><spa=
n class=3D"pun">;</span><span class=3D"pln">
    helper</span><span class=3D"pun">():</span><span class=3D"pln">ptr</spa=
n><span class=3D"pun">(</span><span class=3D"kwd">nullptr</span><span class=
=3D"pun">)</span><span class=3D"pln"> </span><span class=3D"pun">{}</span><=
span class=3D"pln">
    helper</span><span class=3D"pun">(</span><span class=3D"pln">helper </s=
pan><span class=3D"kwd">const</span><span class=3D"pun">&amp;)</span><span =
class=3D"pln"> </span><span class=3D"pun">=3D</span><span class=3D"pln"> </=
span><span class=3D"kwd">default</span><span class=3D"pun">;</span><span cl=
ass=3D"pln">
    helper</span><span class=3D"pun">(</span><span class=3D"pln">T</span><s=
pan class=3D"pun">*</span><span class=3D"pln"> p</span><span class=3D"pun">=
):</span><span class=3D"pln">ptr</span><span class=3D"pun">(</span><span cl=
ass=3D"pln">p</span><span class=3D"pun">)</span><span class=3D"pln"> </span=
><span class=3D"pun">{}</span><span class=3D"pln">
    </span><span class=3D"kwd">template</span><span class=3D"pun">&lt;</spa=
n><span class=3D"kwd">typename</span><span class=3D"pln"> U</span><span cla=
ss=3D"pun">&gt;</span><span class=3D"pln">
    helper</span><span class=3D"pun">(</span><span class=3D"pln"> std</span=
><span class=3D"pun">::</span><span class=3D"pln">shared_ptr</span><span cl=
ass=3D"pun">&lt;</span><span class=3D"pln">U</span><span class=3D"pun">&gt;=
</span><span class=3D"pln"> </span><span class=3D"kwd">const</span><span cl=
ass=3D"pun">&amp;</span><span class=3D"pln"> sp </span><span class=3D"pun">=
):</span><span class=3D"pln">ptr</span><span class=3D"pun">(</span><span cl=
ass=3D"pln">sp</span><span class=3D"pun">.</span><span class=3D"kwd">get</s=
pan><span class=3D"pun">())</span><span class=3D"pln"> </span><span class=
=3D"pun">{}</span><span class=3D"pln">
    </span><span class=3D"kwd">template</span><span class=3D"pun">&lt;</spa=
n><span class=3D"kwd">typename</span><span class=3D"pln"> U</span><span cla=
ss=3D"pun">&gt;</span><span class=3D"pln">
    helper</span><span class=3D"pun">(</span><span class=3D"pln"> std</span=
><span class=3D"pun">::</span><span class=3D"pln">unique_ptr</span><span cl=
ass=3D"pun">&lt;</span><span class=3D"pln">U</span><span class=3D"pun">&gt;=
</span><span class=3D"pln"> </span><span class=3D"kwd">const</span><span cl=
ass=3D"pun">&amp;</span><span class=3D"pln"> sp </span><span class=3D"pun">=
):</span><span class=3D"pln">ptr</span><span class=3D"pun">(</span><span cl=
ass=3D"pln">sp</span><span class=3D"pun">.</span><span class=3D"kwd">get</s=
pan><span class=3D"pun">())</span><span class=3D"pln"> </span><span class=
=3D"pun">{}</span><span class=3D"pln">
    </span><span class=3D"kwd">bool</span><span class=3D"pln"> </span><span=
 class=3D"kwd">operator</span><span class=3D"pun">&lt;()(</span><span class=
=3D"pln"> helper o </span><span class=3D"pun">)</span><span class=3D"pln"> =
</span><span class=3D"kwd">const</span><span class=3D"pln"> </span><span cl=
ass=3D"pun">{</span><span class=3D"pln">
      </span><span class=3D"kwd">return</span><span class=3D"pln"> std</spa=
n><span class=3D"pun">::</span><span class=3D"pln">less</span><span class=
=3D"pun">&lt;</span><span class=3D"pln">T</span><span class=3D"pun">*&gt;()=
(</span><span class=3D"pln"> ptr</span><span class=3D"pun">,</span><span cl=
ass=3D"pln"> o</span><span class=3D"pun">.</span><span class=3D"pln">ptr </=
span><span class=3D"pun">);</span><span class=3D"pln">
    </span><span class=3D"pun">}</span><span class=3D"pln">
  </span><span class=3D"pun">};</span><span class=3D"pln">
  </span><span class=3D"com">// without helper, we'd need 2^n different ove=
rloads, where</span><span class=3D"pln">
  </span><span class=3D"com">// n is the number of types we want to support=
 (so, 8 with</span><span class=3D"pln">
  </span><span class=3D"com">// raw pointers, unique pointers, and shared p=
ointers).  That</span><span class=3D"pln">
  </span><span class=3D"com">// seems silly:</span><span class=3D"pln">
  </span><span class=3D"kwd">bool</span><span class=3D"pln"> </span><span c=
lass=3D"kwd">operator</span><span class=3D"pun">()(</span><span class=3D"pl=
n"> helper lhs</span><span class=3D"pun">,</span><span class=3D"pln"> helpe=
r rhs </span><span class=3D"pun">)</span><span class=3D"pln"> </span><span =
class=3D"kwd">const</span><span class=3D"pln"> </span><span class=3D"pun">{=
</span><span class=3D"pln">
    </span><span class=3D"kwd">return</span><span class=3D"pln"> lhs </span=
><span class=3D"pun">&lt;</span><span class=3D"pln"> rhs</span><span class=
=3D"pun">;</span><span class=3D"pln">
  </span><span class=3D"pun">}</span><span class=3D"pln">
</span><span class=3D"pun">};</span></code></pre><br>I'm just copy-pasting =
what he wrote. I'd prefer the name ptr_less or similar. I think it would go=
 nicely with the new heterogenous comparison lookup for associative contain=
ers.<br><br>As a side note: I think it would be awesome if we need somethin=
g similar with std::hash for unordered_maps and unordered_sets, but that's =
another topic for another day. I'll probably start a new thread about it so=
metime this weekend.<br><br>On Monday, September 23, 2013 2:46:53 PM UTC-5,=
 MasterT wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-=
left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr=
">Hi all,<div><br></div><div>There are some questions on stack overflow rel=
ated using a raw pointer for lookup in a unique_ptr container:</div><div><d=
iv>* <a href=3D"http://stackoverflow.com/questions/17851088/using-a-stdunor=
dered-set-of-stdunique-ptr" target=3D"_blank">http://stackoverflow.com/<wbr=
>questions/17851088/using-a-<wbr>stdunordered-set-of-stdunique-<wbr>ptr</a>=
</div><div>* <a href=3D"http://stackoverflow.com/questions/18055183/no-stan=
dard-way-to-compare-smart-pointer-with-regular-pointer" target=3D"_blank">h=
ttp://stackoverflow.com/<wbr>questions/18055183/no-<wbr>standard-way-to-com=
pare-smart-<wbr>pointer-with-regular-pointer</a></div></div><div>*&nbsp;<a =
href=3D"http://stackoverflow.com/questions/18939882/raw-pointer-lookup-for-=
sets-of-unique-ptrs" target=3D"_blank">http://stackoverflow.com/<wbr>questi=
ons/18939882/raw-<wbr>pointer-lookup-for-sets-of-<wbr>unique-ptrs</a></div>=
<div><br></div><div>The second question is by me, and the third question tr=
iggered me writing down this post to know your thoughts on the following:</=
div><div><br></div><div>Wouldn't it make sense to have comparison operators=
 (=3D=3D, !=3D, &lt;, ...) between smart pointers and raw pointers?</div><d=
iv>Currently the operators require the type to match, and this drags in "ow=
nership" into the equation.</div><div>If the pointers are equal, they shoul=
d have the same idea about ownership anyhow.</div><div>When comparing to th=
e raw pointer, you indicate you do not want to take the ownership into acco=
unt.<br></div><div><br></div><div>As smart pointers are ordered/hashed base=
d on raw pointer values, a heterogeneous lookup can work.</div><div><br></d=
iv><div>Thanks for your inputs,</div><div>Wkr,</div><div><br></div><div>Tom=
</div></div></blockquote></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_718_12914307.1380314137224--

.