Dlaczego nie kompiluje się this code?Niestandardowy przydział i domyślny użytkownik
#include <cstdlib>
#include <list>
template < typename Type >
class Allocator {
public:
using value_type = Type;
public:
template < typename Other >
struct rebind { using other = Allocator<Other>; };
public:
Type * allocate(std::size_t n) { return std::malloc(n); }
void deallocate(Type * p, std::size_t) throw () { std::free(p); }
};
int main(void) {
std::list< void *, Allocator< void * > > list;
return 0;
}
Wydaje trzeba wskaźnik, odniesienie, pointer_const & rodzajów reference_const. Jednakże, zgodnie z cppreference, wszyscy członkowie są opcjami. Wygląda na to, że jeśli STL nie używają allocator_trait (kompiluję z -std = C++ 11, więc powinno być dobrze).
Każdy pomysł?
[edytuj] Z brzękiem, błędy są:
[email protected]/tmp > clang++ -std=c++11 test.cc
In file included from test.cc:2:
In file included from /usr/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/list:63:
/usr/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/stl_list.h:449:40: error: no type named 'pointer' in 'Allocator<void *>'
typedef typename _Tp_alloc_type::pointer pointer;
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
test.cc:17:46: note: in instantiation of template class 'std::list<void *, Allocator<void *> >' requested here
std::list< void *, Allocator< void * > > list;
^
In file included from test.cc:2:
In file included from /usr/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/list:63:
/usr/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/stl_list.h:450:40: error: no type named 'const_pointer' in 'Allocator<void *>'
typedef typename _Tp_alloc_type::const_pointer const_pointer;
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
/usr/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/stl_list.h:451:40: error: no type named 'reference' in 'Allocator<void *>'
typedef typename _Tp_alloc_type::reference reference;
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
/usr/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/stl_list.h:452:40: error: no type named 'const_reference' in 'Allocator<void *>'
typedef typename _Tp_alloc_type::const_reference const_reference;
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
4 errors generated.
Jaki jest błąd? – Nick
@Nick Mam zaktualizowane moje pytanie z wyjściem clang (gcc też się nie udaje) –
Należy zauważyć, że obsługa C++ 11 dla zasadniczo wszystkich kompilatorów jest nadal eksperymentalna/niekompletna. Dlatego może to być po prostu błąd implementacji (nie można teraz wyszukać odpowiednich części standardu, więc jest to tylko przypuszczenie, jeśli te elementy są rzeczywiście opcjonalne) – Grizzly