我开始学习std::array
并找到了使用.at(index of element)
访问数组的函数。array.[index of element]
风格有什么理由吗?(例如速度、异常或其他(。
考虑(链接(
const_reference operator[](size_type pos) const;
和(链接(
const_reference at(size_type pos) const;
它们都返回对指定位置的元素的引用:pos
。但是,前者不执行边界检查,而后者执行边界检查。 如果!(pos < size())
后者将引发std::out_of_range
异常。