serialize: Deprecate begin_ptr / end_ptr

Implement `begin_ptr` and `end_ptr` in terms of C++11 code,
and add a comment that they are deprecated.

Follow-up to developer notes update in 654a211622.
This commit is contained in:
Wladimir J. van der Laan 2016-09-30 17:21:12 +02:00
parent 47314e6daa
commit f00705ae7f
No known key found for this signature in database
GPG key ID: 74810B012346C9A6
2 changed files with 11 additions and 12 deletions

View file

@ -476,7 +476,7 @@ public:
} }
} }
value_type* data() noexcept { value_type* data() {
return item_ptr(0); return item_ptr(0);
} }

View file

@ -45,32 +45,31 @@ inline T* NCONST_PTR(const T* val)
} }
/** /**
* Get begin pointer of vector (non-const version). * Important: Do not use the following functions in new code, but use v.data()
* @note These functions avoid the undefined case of indexing into an empty * and v.data() + v.size() respectively directly. They were once introduced to
* vector, as well as that of indexing after the end of the vector. * 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> template <typename V>
inline typename V::value_type* begin_ptr(V& 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> template <typename V>
inline const typename V::value_type* begin_ptr(const V& 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> template <typename V>
inline typename V::value_type* end_ptr(V& 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> template <typename V>
inline const typename V::value_type* end_ptr(const V& 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();
} }
/* /*