Skip to content

Commit

Permalink
Make xr_vector.h self-contained.
Browse files Browse the repository at this point in the history
  • Loading branch information
tamlin-mike authored and Xottab-DUTY committed Aug 5, 2017
1 parent c31426e commit 5a3b1e4
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/xrCommon/xr_vector.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <vector>
#include "xalloc.h"
#include "xrCore/xrDebug_macros.h"

#ifdef _M_AMD64
#define M_DONTDEFERCLEAR_EXT
Expand Down Expand Up @@ -30,9 +31,9 @@ class xr_vector : public std::vector<T, allocator>
xr_vector() : inherited() {}
xr_vector(size_t _count, const T& _value) : inherited(_count, _value) {}
explicit xr_vector(size_t _count) : inherited(_count) {}
u32 size() const { return (u32)inherited::size(); }
u32 size() const throw() { return (u32)inherited::size(); }

void clear_and_free() { inherited::clear(); }
void clear_and_free() throw() { inherited::clear(); }
void clear_not_free() { erase(begin(), end()); }
void clear_and_reserve()
{
Expand All @@ -52,16 +53,22 @@ class xr_vector : public std::vector<T, allocator>
#endif
const_reference operator[](size_type _Pos) const
{
VERIFY2(_Pos<size(),
make_string("index is out of range: index requested[%d], size of container[%d]", _Pos, size()).c_str());
check_idx(_Pos);
return *(begin()+_Pos);
}
reference operator[](size_type _Pos)
{
VERIFY2(_Pos<size(),
make_string("index is out of range: index requested[%d], size of container[%d]", _Pos, size()).c_str());
check_idx(_Pos);
return *(begin()+_Pos);
}

private:
void check_idx(size_type _Pos) const
{
VERIFY2(_Pos < size(),
make_string("index is out of range: index requested[%d], size of container[%d]",
_Pos, size()).c_str());
}
};

// vector<bool>
Expand Down

0 comments on commit 5a3b1e4

Please sign in to comment.