C++ – How to create a std::vector with 64 bit indexes

64-bitallocatorcstlvisual-studio-2008

I want to create a big std::vector so operator[] should receive long long rather than unsigned int, I tried writing my own allocator:

template <typename T>
struct allocator64 : std::allocator<T> {
    typedef long long difference_type;
    typedef unsigned long long size_type;
};

But when I try the following:

long long n = 5;
std::vector<int, allocator64<int> > vec(n);
vec[n-1] = 2;

I get the following warning for the second and third line:

warning C4244: 'argument' : conversion from '__int64' to 'unsigned int', possible loss of data

What am I missing? I thought the type for operator[] and for the size constructor should come from allocator::size_type.

I'm using VS9 (2008).

Best Answer

Maybe the STXXL library can help:

STXXL provides an STL replacement using an abstraction layer to storage devices to allow for the optimal layout of data structures. This allows for multi-terabyte datasets to be held and manipulated in standard C++ data structures, whilst abstracting the complexity of managing this behaviour efficiently. STXXL utilises multi-disk I/O to speed up I/O bound calculations. STXXL has been developed at the University of Karlsruhe.