@@ -37,6 +37,34 @@ inline T& REF(const T& val)
37
37
return const_cast <T&>(val);
38
38
}
39
39
40
+ /* * Get begin pointer of vector (non-const version).
41
+ * @note These functions avoid the undefined case of indexing into an empty
42
+ * vector, as well as that of indexing after the end of the vector.
43
+ */
44
+ template <class T , class TAl >
45
+ inline T* begin_ptr (std::vector<T,TAl>& v)
46
+ {
47
+ return v.empty () ? NULL : &v[0 ];
48
+ }
49
+ /* * Get begin pointer of vector (const version) */
50
+ template <class T , class TAl >
51
+ inline const T* begin_ptr (const std::vector<T,TAl>& v)
52
+ {
53
+ return v.empty () ? NULL : &v[0 ];
54
+ }
55
+ /* * Get end pointer of vector (non-const version) */
56
+ template <class T , class TAl >
57
+ inline T* end_ptr (std::vector<T,TAl>& v)
58
+ {
59
+ return v.empty () ? NULL : (&v[0 ] + v.size ());
60
+ }
61
+ /* * Get end pointer of vector (const version) */
62
+ template <class T , class TAl >
63
+ inline const T* end_ptr (const std::vector<T,TAl>& v)
64
+ {
65
+ return v.empty () ? NULL : (&v[0 ] + v.size ());
66
+ }
67
+
40
68
// ///////////////////////////////////////////////////////////////
41
69
//
42
70
// Templates for serializing to anything that looks like a stream,
@@ -318,6 +346,12 @@ class CFlatData
318
346
char * pend;
319
347
public:
320
348
CFlatData (void * pbeginIn, void * pendIn) : pbegin((char *)pbeginIn), pend((char *)pendIn) { }
349
+ template <class T , class TAl >
350
+ explicit CFlatData (std::vector<T,TAl> &v)
351
+ {
352
+ pbegin = (char *)begin_ptr (v);
353
+ pend = (char *)end_ptr (v);
354
+ }
321
355
char * begin () { return pbegin; }
322
356
const char * begin () const { return pbegin; }
323
357
char * end () { return pend; }
0 commit comments