У меня очень простой распределитель:
template<typename T>
struct Allocator : public std::allocator<T> {
inline typename std::allocator<T>::pointer allocate(typename std::allocator<T>::size_type n, typename std::allocator<void>::const_pointer = 0) {
std::cout << "Allocating: " << n << " itens." << std::endl;
return reinterpret_cast<typename std::allocator<T>::pointer>(::operator new(n * sizeof (T)));
}
inline void deallocate(typename std::allocator<T>::pointer p, typename std::allocator<T>::size_type n) {
std::cout << "Dealloc: " << n << " itens." << std::endl;
::operator delete(p);
}
template<typename U>
struct rebind {
typedef Allocator<U> other;
};
};
который работает хорошо, когда я использую его с: "std :: vector>", однако, когда я пытаюсь использовать его с std :: map, например:
int main(int, char**) {
std::map<int, int, Allocator< std::pair<const int, int> > > map;
for (int i(0); i < 100; ++i) {
std::cout << "Inserting the " << i << " item. " << std::endl;
map.insert(std::make_pair(i*i, 2*i));
}
return 0;
}
Он не может скомпилировать (gcc 4.6), давая очень длинную ошибку, заканчивающуюся на: /usr/lib/gcc/x86_64-redhat-linux/4.6.0 /../../../../ include / c ++ / 4.6.0 / bits / stl_tree.h: 959: 25: ошибка : нет совпадения для вызова '(Allocator