Skip to content

Commit f00705a

Browse files
committed
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 654a211.
1 parent 47314e6 commit f00705a

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/prevector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ class prevector {
476476
}
477477
}
478478

479-
value_type* data() noexcept {
479+
value_type* data() {
480480
return item_ptr(0);
481481
}
482482

src/serialize.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,32 @@ inline T* NCONST_PTR(const T* val)
4444
return const_cast<T*>(val);
4545
}
4646

47-
/**
48-
* Get begin pointer of vector (non-const version).
49-
* @note These functions avoid the undefined case of indexing into an empty
50-
* vector, as well as that of indexing after the end of the vector.
47+
/**
48+
* Important: Do not use the following functions in new code, but use v.data()
49+
* and v.data() + v.size() respectively directly. They were once introduced to
50+
* have a compatible, safe way to get the begin and end pointer of a vector.
51+
* However with C++11 the language has built-in functionality for this and it's
52+
* more readable to just use that.
5153
*/
5254
template <typename V>
5355
inline typename V::value_type* begin_ptr(V& v)
5456
{
55-
return v.empty() ? NULL : &v[0];
57+
return v.data();
5658
}
57-
/** Get begin pointer of vector (const version) */
5859
template <typename V>
5960
inline const typename V::value_type* begin_ptr(const V& v)
6061
{
61-
return v.empty() ? NULL : &v[0];
62+
return v.data();
6263
}
63-
/** Get end pointer of vector (non-const version) */
6464
template <typename V>
6565
inline typename V::value_type* end_ptr(V& v)
6666
{
67-
return v.empty() ? NULL : (&v[0] + v.size());
67+
return v.data() + v.size();
6868
}
69-
/** Get end pointer of vector (const version) */
7069
template <typename V>
7170
inline const typename V::value_type* end_ptr(const V& v)
7271
{
73-
return v.empty() ? NULL : (&v[0] + v.size());
72+
return v.data() + v.size();
7473
}
7574

7675
/*

0 commit comments

Comments
 (0)