If you know the size at compile time, maybe using a std::tr1::array (or boost::array) would be a better choice. It keeps a fixed size and check access like std::vector.
If however you know it only at runtime, as said others here, you should encapsulate your vector in a class with specific functions that will check the conditions you want (via assertions for example).
In this last approach, I would suggest, if you can know the maximum size at the vector creation, to reserve ( std::vector::reserve() ) the maximum size of the vector in your encapsulating class constructor (or initialization function). That way, there will be no more memory manipulations by the vector itself (only if the vector elements constructor/destructor do such manipulations). Then, adding a simple assertion that checks that the vector capacity ( std::vector::capacity() ) never changed at the start and end of all the functions of your class will help you make sure it's memory don't move.
For example (assuming DATA_MAX_SIZE is a default max size defined somewhere) :
template< typename MyType >
class MyData
{
public:
MyData( unsigned long max_size = DATA_MAX_SIZE )
: m_max_size( max_size )
{ m_data.reserve( m_max_size ); }
void add( const MyType& value ) { check_capacity(); m_data.push_back( value ); check_capacity(); }
private:
std::vector< MyType > m_data;
const unsigned long m_max_size;
void check_capacity() { if( m_data.capacity() != m_max_size ) throw Exception("Useful error message here!" ); }
};
Or something like that...