add beginPtr, to make vector address taking safe

This commit is contained in:
tqchen
2014-09-02 11:01:38 -07:00
parent 70219ee1ae
commit 27cabd131e
2 changed files with 20 additions and 14 deletions

View File

@@ -9,6 +9,7 @@
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#ifndef XGBOOST_STRICT_CXX98_
#include <cstdarg>
@@ -153,7 +154,15 @@ inline FILE *FopenCheck(const char *fname, const char *flag) {
Check(fp != NULL, "can not open file \"%s\"\n", fname);
return fp;
}
/*! \brief get the beginning address of a vector */
template<typename T>
inline T *BeginPtr(std::vector<T> &vec) {
if (vec.size() == 0) {
return NULL;
} else {
return &vec[0];
}
}
} // namespace utils
} // namespace xgboost
#endif // XGBOOST_UTILS_UTILS_H_