Skip to content

Commit 334a44e

Browse files
committed
Added forgotten is_empty method
1 parent c651d53 commit 334a44e

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

include/set.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,22 @@ class set
534534
return set();
535535
}
536536

537+
// Returns true if the set is empty
538+
//
539+
// example:
540+
// const fcpp::set<int> numbers({1, 4, 2});
541+
//
542+
// // returns false
543+
// numbers.is_empty();
544+
//
545+
// // returns true
546+
// fcpp::set<int>().is_empty();
547+
[[nodiscard]] bool is_empty() const
548+
{
549+
return m_set.empty();
550+
}
551+
552+
537553
// Returns true if the key is present in the set, otherwise false
538554
//
539555
// example:
@@ -551,9 +567,6 @@ class set
551567
return m_set.size();
552568
}
553569

554-
// clear
555-
// is_empty
556-
557570
// Returns the begin iterator, useful for other standard library algorithms
558571
[[nodiscard]] typename std::set<TKey>::iterator begin()
559572
{

tests/set_test.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,13 @@ TEST(SetTest, Clearing)
510510
EXPECT_EQ(3, numbers.size());
511511
}
512512

513+
TEST(SetTest, IsEmpty)
514+
{
515+
const set<int> numbers({1, 4, 2});
516+
EXPECT_FALSE(numbers.is_empty());
517+
EXPECT_TRUE(set<int>().is_empty());
518+
}
519+
513520
TEST(SetTest, Contains)
514521
{
515522
const set<int> numbers({1, 4, 2});

0 commit comments

Comments
 (0)