Skip to content

Commit

Permalink
implement empty() function as supported by STL containers
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Voigt authored and Alexander Voigt committed Aug 25, 2016
1 parent ac2fd67 commit ccf73ef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/gsl_vector.cpp
Expand Up @@ -89,6 +89,11 @@ void GSL_vector::assign(const gsl_vector* other)
gsl_vector_memcpy(vec, other);
}

bool GSL_vector::empty() const
{
return size() == 0;
}

const GSL_vector& GSL_vector::operator=(const GSL_vector& rhs)
{
if (this != &rhs)
Expand Down
1 change: 1 addition & 0 deletions src/gsl_vector.hpp
Expand Up @@ -39,6 +39,7 @@ class GSL_vector {
double operator[](std::size_t) const; ///< element read access

void assign(const gsl_vector*); ///< assign from gsl_vector
bool empty() const; ///< check if empty
const gsl_vector* raw() const; ///< get raw pointer
gsl_vector* raw(); ///< get raw pointer
void set_all(double); ///< set all elemets to same value
Expand Down
8 changes: 8 additions & 0 deletions test/test_gsl_vector.cpp
Expand Up @@ -169,6 +169,14 @@ BOOST_AUTO_TEST_CASE( test_move_assign_chain )
BOOST_CHECK_EQUAL(v3[2], 3.);
}

BOOST_AUTO_TEST_CASE( test_empty )
{
GSL_vector v(3), v2;

BOOST_CHECK(!v.empty());
BOOST_CHECK(v2.empty());
}

BOOST_AUTO_TEST_CASE( test_move )
{
GSL_vector v(3);
Expand Down

0 comments on commit ccf73ef

Please sign in to comment.