Skip to content

Commit

Permalink
Merge #8850: Implement (begin|end)_ptr in C++11 and add deprecation c…
Browse files Browse the repository at this point in the history
…omment

f00705a serialize: Deprecate `begin_ptr` / `end_ptr` (Wladimir J. van der Laan)
47314e6 prevector: add C++11-like data() method (Wladimir J. van der Laan)
  • Loading branch information
laanwj committed Oct 4, 2016
2 parents a7e5cbb + f00705a commit 7dce175
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
8 changes: 8 additions & 0 deletions src/prevector.h
Expand Up @@ -475,6 +475,14 @@ class prevector {
return ((size_t)(sizeof(T))) * _union.capacity;
}
}

value_type* data() {
return item_ptr(0);
}

const value_type* data() const {
return item_ptr(0);
}
};
#pragma pack(pop)

Expand Down
21 changes: 10 additions & 11 deletions src/serialize.h
Expand Up @@ -44,33 +44,32 @@ inline T* NCONST_PTR(const T* val)
return const_cast<T*>(val);
}

/**
* Get begin pointer of vector (non-const version).
* @note These functions avoid the undefined case of indexing into an empty
* vector, as well as that of indexing after the end of the vector.
/**
* Important: Do not use the following functions in new code, but use v.data()
* and v.data() + v.size() respectively directly. They were once introduced to
* have a compatible, safe way to get the begin and end pointer of a vector.
* However with C++11 the language has built-in functionality for this and it's
* more readable to just use that.
*/
template <typename V>
inline typename V::value_type* begin_ptr(V& v)
{
return v.empty() ? NULL : &v[0];
return v.data();
}
/** Get begin pointer of vector (const version) */
template <typename V>
inline const typename V::value_type* begin_ptr(const V& v)
{
return v.empty() ? NULL : &v[0];
return v.data();
}
/** Get end pointer of vector (non-const version) */
template <typename V>
inline typename V::value_type* end_ptr(V& v)
{
return v.empty() ? NULL : (&v[0] + v.size());
return v.data() + v.size();
}
/** Get end pointer of vector (const version) */
template <typename V>
inline const typename V::value_type* end_ptr(const V& v)
{
return v.empty() ? NULL : (&v[0] + v.size());
return v.data() + v.size();
}

/*
Expand Down

0 comments on commit 7dce175

Please sign in to comment.