驚いたことに、std::vector::get_allocator()
をコピーできないアロケータで使用しようとするとエラーが発生します。 std::vector::get_allocator()
が参照によってではなく値で返されるのはなぜですか?なぜstd :: vector :: get_allocator()は値によって戻りますか?
template<typename T>
class nc_allocator {
public:
using value_type = T;
nc_allocator(nc_allocator const&) = delete;
nc_allocator& operator=(nc_allocator const&) = delete;
// Other required members.
};
std::vector<int, nc_allocator<int>> v;
// boom: use of deleted function
// 'nc_allocator<T>::nc_allocator(const nc_allocator<T>&) [with T = int]'
v.get_allocator();
私は、アロケータのインスタンスがハンドルのように扱われると考えられます。これの証拠は、2つのアロケータは、他のオブジェクトを削除できる場合にのみ、等しいとみなされるということです。 –