Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #68420

Re: Why allocator<T>::rebind<U> was removed with C++20`

From Bo Persson <bo@bo-persson.se>
Newsgroups comp.lang.c++
Subject Re: Why allocator<T>::rebind<U> was removed with C++20`
Date 2019-09-14 22:49 +0200
Message-ID <gu523cFllipU1@mid.individual.net> (permalink)
References <qlj9gc$d1h$1@news.albasani.net> <qljcn0$7a2$1@news.albasani.net>

Show all headers | View raw


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

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web