Xiaohan Wang | 15 Jun 2012 22:47

Adding element_type in scoped_refptr?

I was trying to use ::testing::IsNull and ::testing::NotNull on
scoped_refptr? I saw in the doc that it's working for both raw and
smart pointers. But I tried and it's not working. I investigated a
little bit and found that GetRawPointer needs element_type to be
defined in the Pointer type:

template <typename Pointer>
inline typename Pointer::element_type* GetRawPointer(const Pointer& p)
{
 return p.get();
}

It turns out that element_type is not defined in scoped_refptr. I
added

typedef T element_type;

in the definition of template <class T> class scoped_refptr and at
least IsNull and NotNull compiled with scoped_refptr for me.

My question is: Is there any reason element_type is not defined in
scoped_refptr? If not, does it worth adding it? This should not break
any existing code, but I wonder if this could cause any possible
misuse in the future.

--

-- 
Chromium Developers mailing list: chromium-dev <at> chromium.org
View archives, change email options, or unsubscribe: 
    http://groups.google.com/a/chromium.org/group/chromium-dev

(Continue reading)

Brett Wilson | 15 Jun 2012 23:02

Re: Adding element_type in scoped_refptr?

On Fri, Jun 15, 2012 at 1:47 PM, Xiaohan Wang <xhwang <at> chromium.org> wrote:
> I was trying to use ::testing::IsNull and ::testing::NotNull on
> scoped_refptr? I saw in the doc that it's working for both raw and
> smart pointers. But I tried and it's not working. I investigated a
> little bit and found that GetRawPointer needs element_type to be
> defined in the Pointer type:
>
> template <typename Pointer>
> inline typename Pointer::element_type* GetRawPointer(const Pointer& p)
> {
>  return p.get();
> }
>
> It turns out that element_type is not defined in scoped_refptr. I
> added
>
> typedef T element_type;
>
> in the definition of template <class T> class scoped_refptr and at
> least IsNull and NotNull compiled with scoped_refptr for me.
>
> My question is: Is there any reason element_type is not defined in
> scoped_refptr? If not, does it worth adding it? This should not break
> any existing code, but I wonder if this could cause any possible
> misuse in the future.

This seems OK to me.

Brett

(Continue reading)


Gmane