intrusive_ptr question

The intrusive_ptr contains two functions that allow comparisons between intrusive_ptr<T> and T *. template<class T> bool operator==(intrusive_ptr<T> const & a, T * b); template<class T> bool operator==(T * b, intrusive_ptr<T> const & b); and similar operator!=() functions. I'm curious why the pointer parameters are of type T* and not T const *. Joe Gottman

"Joe Gottman" <jgottman@carolina.rr.com> wrote in message news:c8jgkb$mc4$1@sea.gmane.org...
[...] I'm curious why the pointer parameters are of type T* and not T const *.
Because that would not allow comparisons between types that are not T const*. Take T == int. With T*, you can compare int*. With T == int const, you get int const*. If you use T const* instead, you won't ever be able to compare int*. Dave --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.683 / Virus Database: 445 - Release Date: 5/12/2004

From: "David B. Held" <dheld@codelogicconsulting.com>
"Joe Gottman" <jgottman@carolina.rr.com> wrote in message
template<class T> bool operator==(intrusive_ptr<T> const & a, T * b);
I'm curious why the pointer parameters are of type T* and not T const *.
Because that would not allow comparisons between types that are not T const*. Take T == int. With T*, you can compare int*. With T == int const, you get int const*. If you use T const* instead, you won't ever be able to compare int*.
int * p1(0); int const * p2(p1); // OK Notice also that T for instrusive_ptr<T> and for T * is one and the same, so you can't compare intrusive_ptr<T> with T const *. You could only compare intrusive_ptr<T const> with T const *. -- Rob Stewart stewart@sig.com Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;

"Rob Stewart" <stewart@sig.com> wrote in message news:200405211437.i4LEb2D05995@lawrencewelk.systems.susq.com...
[...] int * p1(0); int const * p2(p1); // OK
Notice also that T for instrusive_ptr<T> and for T * is one and the same, so you can't compare intrusive_ptr<T> with T const *. You could only compare intrusive_ptr<T const> with T const *.
And the problem with that is? Dave --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.683 / Virus Database: 445 - Release Date: 5/12/2004

From: "David B. Held" <dheld@codelogicconsulting.com>
"Rob Stewart" <stewart@sig.com> wrote in message
[...] int * p1(0); int const * p2(p1); // OK
Notice also that T for instrusive_ptr<T> and for T * is one and the same, so you can't compare intrusive_ptr<T> with T const *. You could only compare intrusive_ptr<T const> with T const *.
And the problem with that is?
The original query was why the second arg wasn't T const *. My point is that comparing with a T * would work because T * can be converted to T const * implicitly. The other point is that if you have an instrusive_ptr<int const>, for example, you cannot compare it with an int *, because the function template expects the second argument to be of type int const *. (Actually, it will just complain about not being able to infer T since neither int nor int const will work.) -- Rob Stewart stewart@sig.com Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;
participants (3)
-
David B. Held
-
Joe Gottman
-
Rob Stewart