mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-30 05:10:02 +00:00
Changed how vector_data works. (#4467)
In some debug environments using vector[i] does bounds checking even though the standard specifies that it should not. Using *(vector.begin()) sidesteps this though, giving the same result without the bounds checking.
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
f2627e16ac
commit
97face1527
@@ -41,12 +41,14 @@ inline char string_back(const std::string &value) {
|
|||||||
// Helper method that retrieves ::data() from a vector in a way that is
|
// Helper method that retrieves ::data() from a vector in a way that is
|
||||||
// compatible with pre C++11 STLs (e.g stlport).
|
// compatible with pre C++11 STLs (e.g stlport).
|
||||||
template <typename T> inline T *vector_data(std::vector<T> &vector) {
|
template <typename T> inline T *vector_data(std::vector<T> &vector) {
|
||||||
return &(vector[0]);
|
// In some debug environments, operator[] does bounds checking, so &vector[0]
|
||||||
|
// can't be used.
|
||||||
|
return &(*vector.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> inline const T *vector_data(
|
template <typename T> inline const T *vector_data(
|
||||||
const std::vector<T> &vector) {
|
const std::vector<T> &vector) {
|
||||||
return &(vector[0]);
|
return &(*vector.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename V>
|
template <typename T, typename V>
|
||||||
|
|||||||
Reference in New Issue
Block a user