Disabling bounds checking for c++ vectors

前端 未结 8 2284
囚心锁ツ
囚心锁ツ 2021-02-08 06:09

With stl::vector:

vector v(1);
v[0]=1; // No bounds checking
v.at(0)=1; // Bounds checking

Is there a way to disable bounds checking

8条回答
  •  忘了有多久
    2021-02-08 06:43

    Derive your own vector class in your own namespace like "uncheckedvector", and override the at() of the base vector type to use the array index.

    Then use "using uncheckedvector::vector" will let you override all your uses of vector everywhere. This won't work if you're using fully qualified types anywhere though.

提交回复
热议问题