Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #68415 > unrolled thread
| Started by | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| First post | 2019-09-14 19:54 +0200 |
| Last post | 2019-09-15 03:00 +0200 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.c++
Why allocator<T>::rebind<U> was removed with C++20` Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-14 19:54 +0200
Re: Why allocator<T>::rebind<U> was removed with C++20` Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-14 20:49 +0200
Re: Why allocator<T>::rebind<U> was removed with C++20` Bo Persson <bo@bo-persson.se> - 2019-09-14 22:49 +0200
Re: Why allocator<T>::rebind<U> was removed with C++20` Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-15 03:00 +0200
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2019-09-14 19:54 +0200 |
| Subject | Why allocator<T>::rebind<U> was removed with C++20` |
| Message-ID | <qlj9gc$d1h$1@news.albasani.net> |
Does anyone know why allocator<T>::rebind<U> was removed with C++20? I think it's rather convenient for initializing an allocator from a "base"-allocator, i.e. you could for example do this: #include <memory> using my_allocator = std::allocator<char>; using derived_allocator = my_allocator::rebind<int>::other; my_allocator ma; derived_allocator da( ma ); This might not make much sense for std:allocator, but imagine you have a class which needs allocators for different types and you don't want to declare each allocator-type as a templae-parameter. I need something like this for a special kind of NUMA-allocator where there's only a single allocator-type given through a tem- plate-parameter and all other allocators are derived from that in the above manner. But how can I do this with C++20?
[toc] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2019-09-14 20:49 +0200 |
| Message-ID | <qljcn0$7a2$1@news.albasani.net> |
| In reply to | #68415 |
> #include <memory> > > using my_allocator = std::allocator<char>; > using derived_allocator = my_allocator::rebind<int>::other; > my_allocator ma; > derived_allocator da( ma ); I've got it; now it works like this: #include <memory> using my_allocator = std::allocator<char>; using derived_allocator = std::allocator_traits<my_allocator>::rebind_alloc<int>; my_allocator ma; derived_allocator da( ma ); This unfortunately means that I've to specialize std::allocator_traits for my NUMA-allocator. That's more work than simply implementing rebind for my NUMA-allocator-class.
[toc] | [prev] | [next] | [standalone]
| From | Bo Persson <bo@bo-persson.se> |
|---|---|
| Date | 2019-09-14 22:49 +0200 |
| Message-ID | <gu523cFllipU1@mid.individual.net> |
| In reply to | #68418 |
On 2019-09-14 at 20:49, Bonita Montero wrote:
>> #include <memory>
>>
>> using my_allocator = std::allocator<char>;
>> using derived_allocator = my_allocator::rebind<int>::other;
>> my_allocator ma;
>> derived_allocator da( ma );
>
> I've got it; now it works like this:
>
> #include <memory>
>
> using my_allocator = std::allocator<char>;
> using derived_allocator =
> std::allocator_traits<my_allocator>::rebind_alloc<int>;
> my_allocator ma;
> derived_allocator da( ma );
>
> This unfortunately means that I've to specialize std::allocator_traits
> for my NUMA-allocator. That's more work than simply implementing rebind
> for my NUMA-allocator-class.
No, you don't really have to do all the extra work.
std::allocator_traits is supposed to be smart enough to use the
allocator's rebind member, if there is one. Or otherwise provide a default.
http://eel.is/c++draft/allocator.traits.types#11
Bo Persson
[toc] | [prev] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2019-09-15 03:00 +0200 |
| Message-ID | <qlk2fm$kmv$1@news.albasani.net> |
| In reply to | #68418 |
Now I had something like this:
#include <memory>
using namespace std;
template<typename Alloc = allocator<char>>
struct S
{
struct A
{
};
using a_alloc = typename allocator_traits<Alloc>::template
rebind_alloc<A>;
};
So why is this "template" in:
using a_alloc = typename allocator_traits<Alloc>::template rebind_alloc<A>;
necessary?
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web