Skip to content

Commit

Permalink
Add emplace_back, move_assignment to BoundedVector
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ho <christopherj.ho@gmail.com>
  • Loading branch information
cho3 authored and christopherho-ApexAI committed Jun 5, 2019
1 parent 66f9a0e commit b6b8ac7
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,14 @@ class BoundedVector
BoundedVector &
operator=(const BoundedVector & __x)
{
reinterpret_cast<std::vector<_Tp, _Alloc> *>(this)->operator=(
*reinterpret_cast<const std::vector<_Tp, _Alloc> *>(&__x));
(void)_Base::operator=(__x);
return *this;
}
/// %BoundedVector move assignment operator
BoundedVector &
operator=(BoundedVector && __x)
{
(void)_Base::operator=(std::forward<_Base &&>(__x));
return *this;
}

Expand Down Expand Up @@ -454,6 +460,16 @@ class BoundedVector
_Base::push_back(__x);
}

template<typename ... Args>
void
emplace_back(Args && ... args)
{
if (size() >= _UpperBound) {
throw std::length_error("Exceeded upper bound");
}
_Base::emplace_back(std::forward<Args>(args)...);
}

/// Insert an object in %BoundedVector before specified iterator.
/**
* This function will insert an object of type T constructed with
Expand Down Expand Up @@ -607,6 +623,13 @@ class BoundedVector
using _Base::erase;
using _Base::pop_back;
using _Base::clear;

private:
/// Cast to base type, to make it easier to dispatch to base implementations
operator _Base&()
{
return *this;
}
};

/// Vector equality comparison.
Expand Down

0 comments on commit b6b8ac7

Please sign in to comment.