This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Fwd: [GSoC] __enable_shared_from_this_helper
- From: Fan You <youfan dot noey at gmail dot com>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Fri, 1 May 2015 01:57:51 -0400
- Subject: Fwd: [GSoC] __enable_shared_from_this_helper
- Authentication-results: sourceware.org; auth=none
- References: <CALvpekGVZEMtGN5MKVXrArG5cKJhqDQjsfgjdFZYk0=H=7+V_Q at mail dot gmail dot com> <20150428215024 dot GF3618 at redhat dot com> <20150428215349 dot GG3618 at redhat dot com> <CALvpekGhEJfEWdHmtOyco-Ua=sPjk4yhpFFE7Fzffy9cTmnVbA at mail dot gmail dot com> <CAG4ZjN=a9nvQ3CgqRiSze-fbUvh0u69WQQdehS5+mFXsvtSP=A at mail dot gmail dot com> <20150429100344 dot GH3618 at redhat dot com> <CAG4ZjNnFTOtEoSPdzv9Dip8s7O6o4ToL2+N-j_oEuxvrD1spLA at mail dot gmail dot com> <20150430112352 dot GR3618 at redhat dot com> <CAG4ZjNmgtF-7jE17d=e8fK_iMhkDHT783Qv1sYpt6MPKsmLL=A at mail dot gmail dot com> <20150430174827 dot GU3618 at redhat dot com> <CALvpekGSvSvg=WcF4w2r3LQ377azPfsAKfLtA5pFm3OKz6DesA at mail dot gmail dot com>
---------- Forwarded message ----------
From: Fan You <youfan.noey@gmail.com>
Date: 2015-05-01 1:56 GMT-04:00
Subject: Re: [GSoC] __enable_shared_from_this_helper
To: Jonathan Wakely <jwakely@redhat.com>
Cc: Tim Shen <timshen@google.com>, Tim Shen <timshen91@gmail.com>,
libstdc++ <libstdc++@gcc.gnu.org>
To conclude:
1. What should I do is to create a new class _Sp_counted_array by
merging _Sp_counted_ptr and _Sp_counted_deleter.
So, some design like this?
template<typename _Ptr, typename _Deleter, typename _Alloc>
class _Sp_counted_array : public _Sp_counted_base {
public:
// implement here
using _Tp = typename std::remove_pointer<_Ptr>::type;
private:
_Tp _array[]; // do init in ctor
size_t _size;
_Alloc _alloc;
_Deleter _del; // may use ebo to reduce size
};
Then, change __shared_count accordingly, others can remain unchanged.
2. Usage you mentioned
>
> shared_ptr<int[]> p(new int[3]);
>
> The shared_count only needs to allocate/deallocate a
>
> _Sp_counted_array<int> in both cases, and that has a known size.
How can _Sp_counted_array<int> get the size when user didn't even pass one?
3. Actually it reminds me that user can use current std::shared_ptr
with array as long as the right deleter are provided.
>
> #include <memory>
>
> int main()
> {
> int array[3];
> std::shared_ptr<int[3]> p(&array, [](void*){});
> }
This will work because the _Tp = int[3] in original shared_ptr
implementation. But the new implementation, which, _Tp = int; So, I am
still not sure why size is not needed to be pass to _Sp_counted_array.
>
> shared_ptr<int[3]> p(new int[3]);
Didn't specify the size but it do tell you by using int[3] as template
parameter.
2015-04-30 13:48 GMT-04:00 Jonathan Wakely <jwakely@redhat.com>:
> On 30/04/15 10:41 -0700, Tim Shen wrote:
>>
>> This is why I was asking "still as usable". This feature actually
>> requires more from the user, since standard didn't specify more.
>>
>> Anyway, we don't need to worry about this for now.
>
>
> No, we don't have to worry about it ever. Period.
>
> Allocators that only support allocating some types cannot be used in
> arbitrary places in the library. That is already true for all the
> node-based containers and for std::allocate_shared and lots of other
> places that rely on rebinding allocators.
>
> We do not have to (and *cannot*) support allocators that can't be
> rebound to arbitrary types. That's not a problem that needs to be
> solved!