Skip to content

Commit

Permalink
Add max_size() to deque and vector
Browse files Browse the repository at this point in the history
This improves STL compatibility.
  • Loading branch information
mtnpke committed May 22, 2024
1 parent 05f4b4a commit d9a291a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions include/EASTL/deque.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ namespace eastl

bool empty() const EA_NOEXCEPT;
size_type size() const EA_NOEXCEPT;
size_type max_size() const EA_NOEXCEPT;

void resize(size_type n, const value_type& value);
void resize(size_type n);
Expand Down Expand Up @@ -1476,6 +1477,14 @@ namespace eastl
}


template <typename T, typename Allocator, unsigned kDequeSubarraySize>
typename deque<T, Allocator, kDequeSubarraySize>::size_type
inline deque<T, Allocator, kDequeSubarraySize>::max_size() const EA_NOEXCEPT
{
return base_type::kMaxSize;
}


template <typename T, typename Allocator, unsigned kDequeSubarraySize>
inline void deque<T, Allocator, kDequeSubarraySize>::resize(size_type n, const value_type& value)
{
Expand Down
9 changes: 9 additions & 0 deletions include/EASTL/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ namespace eastl
bool empty() const EA_NOEXCEPT;
size_type size() const EA_NOEXCEPT;
size_type capacity() const EA_NOEXCEPT;
size_type max_size() const EA_NOEXCEPT;

void resize(size_type n, const value_type& value);
void resize(size_type n);
Expand Down Expand Up @@ -813,6 +814,14 @@ namespace eastl
}


template <typename T, typename Allocator>
inline typename vector<T, Allocator>::size_type
vector<T, Allocator>::max_size() const EA_NOEXCEPT
{
return base_type::kMaxSize;
}


template <typename T, typename Allocator>
inline void vector<T, Allocator>::resize(size_type n, const value_type& value)
{
Expand Down
3 changes: 3 additions & 0 deletions test/source/TestDeque.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ int TestDequeConstruction()
dB.clear();
EATEST_VERIFY(dB.size() == 0);
EATEST_VERIFY(dB.empty());

// max_size
EATEST_VERIFY(dB.max_size() == std::numeric_limits<eastl_size_t>::max() - 1u);
}

EATEST_VERIFY(TestObject::sTOCount == 0);
Expand Down
6 changes: 5 additions & 1 deletion test/source/TestVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,8 +1077,12 @@ int TestVector()
{
using namespace eastl;

// reserve / resize / capacity / clear
vector<int> v(10, 17);

// max_size
EATEST_VERIFY(v.max_size() == std::numeric_limits<eastl_size_t>::max() - 1u);

// reserve / resize / capacity / clear
v.reserve(20);
EATEST_VERIFY(v.validate());
EATEST_VERIFY(v.size() == 10);
Expand Down

0 comments on commit d9a291a

Please sign in to comment.