Disabling bounds checking for c++ vectors

前端 未结 8 2280
囚心锁ツ
囚心锁ツ 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:25

    If you have reasonably consistent access patterns (ie/ not random access), rather than using at() or [], one approach to avoid range checking is to use iterators, using begin(), end(), and advance() or even better, through the use of the standard algorithms.

    Although this doesn't solve the underlying problem of correcting at() doing range checking some implementations of the standard library (MSVC) have checked iterators for some types of builds

提交回复
热议问题