File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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+
513520TEST (SetTest, Contains)
514521{
515522 const set<int > numbers ({1 , 4 , 2 });
You can’t perform that action at this time.
0 commit comments