Allocators
-
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview>cl Microsoft (R) C/C++ Optimizing Compiler Version 19.22.27724 for x86
template<typename T> struct node{}; using node_allocator_t = typename std::allocator_traits<Allocator>::template rebind_alloc<node<T>>; using node_ptr_t = typename std::allocator_traits<node_allocator_t>::pointer; Allocator alloc = node_allocator_t{}; // ... node_ptr_t current_node; std::allocator_traits<node_allocator_t>::destroy(alloc, current_node); std::allocator_traits<node_allocator_t>::deallocate(alloc, current_node, 1);
Error C2664 'void std::_Default_allocator_traits<_Alloc>::destroy<my::list<int,std::allocator<int>>::node<T>>(_Alloc &,_Uty *const )': cannot convert argument 1 from 'Allocator' to '_Alloc &' with [ _Alloc=std::allocator<my::list<int,std::allocator<int>>::node<int>>, T=int, _Uty=my::list<int,std::allocator<int>>::node<int> ] and [ Allocator=std::allocator<int> ] and [ _Alloc=std::allocator<my::list<int,std::allocator<int>>::node<int>> ] Source1.cpp Error C2664 'void std::_Default_allocator_traits<_Alloc>::deallocate(_Alloc &,my::list<int,std::allocator<int>>::node<T> *const, const std::_Default_allocator_traits<_Alloc>::size_type)': cannot convert argument 1 from 'Allocator' to '_Alloc &' with [ _Alloc=std::allocator<my::list<int,std::allocator<int>>::node<int>>, T=int ] and [ Allocator=std::allocator<int> ] and [ _Alloc=std::allocator<my::list<int,std::allocator<int>>::node<int>> ] Source1.cpp
wtf?
// edit: Ok, mich lausen gerade die Affen:
Allocator
~>node_allocator_t
und es werkt.
-
Was willst Du mit dem Beitrag sagen?
Stammt der Codeblock von Dir? Falls ja, dann hast Du die allocator_traits inkorrekt genutzt.
-
@john-0 sagte in Allocators:
Was willst Du mit dem Beitrag sagen?
Garnichts. Es dokumentiert nur einen saublöden Fehler. Soll ich's jetzt löschen? Davon bin ich eigentlich kein Fan.