diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2016-10-04 10:34:18 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2016-10-04 11:08:06 +0200 |
commit | 7dce175f5d89c9185f4cd7bfbd7626205b122001 (patch) | |
tree | d9799928b98746f7b83f51ec9a43fd36abdd0180 /src | |
parent | a7e5cbb209d4aeb8c2e4c58c92bf214759998056 (diff) | |
parent | f00705ae7ff3c1db805859e3be41e58ac70625b6 (diff) | |
download | bitcoin-7dce175f5d89c9185f4cd7bfbd7626205b122001.tar.xz |
Merge #8850: Implement (begin|end)_ptr in C++11 and add deprecation comment
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)
Diffstat (limited to 'src')
-rw-r--r-- | src/prevector.h | 8 | ||||
-rw-r--r-- | src/serialize.h | 21 |
2 files changed, 18 insertions, 11 deletions
diff --git a/src/prevector.h b/src/prevector.h index a0e1e140b4..25bce522dc 100644 --- a/src/prevector.h +++ b/src/prevector.h @@ -475,6 +475,14 @@ public: 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) diff --git a/src/serialize.h b/src/serialize.h index 04ab9aa2e7..1f51da82ff 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -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(); } /* |