From 2fc4e17e3188085a3c0c91dd8366d07919d9d1ea Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 21 Sep 2017 11:34:41 +0200 Subject: [PATCH] Utils: Add Utils::SmallStringView::empty It is required by many template function because it is used in the STL. Change-Id: I5a2b9266d0c9d79bdc37cbbc4e7b62fac7a82b8b Reviewed-by: Tim Jenssen --- src/libs/utils/smallstringview.h | 6 ++++++ tests/unit/unittest/smallstring-test.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/libs/utils/smallstringview.h b/src/libs/utils/smallstringview.h index 2320ef99b6b..3d479195f17 100644 --- a/src/libs/utils/smallstringview.h +++ b/src/libs/utils/smallstringview.h @@ -97,6 +97,12 @@ public: return m_size == 0; } + constexpr + size_type empty() const noexcept + { + return m_size == 0; + } + constexpr const_iterator begin() const noexcept { diff --git a/tests/unit/unittest/smallstring-test.cpp b/tests/unit/unittest/smallstring-test.cpp index 64273c45b2e..345480182bc 100644 --- a/tests/unit/unittest/smallstring-test.cpp +++ b/tests/unit/unittest/smallstring-test.cpp @@ -1004,6 +1004,12 @@ TEST(SmallString, StringViewIsEmpty) ASSERT_TRUE(SmallStringView("").isEmpty()); } +TEST(SmallString, StringViewEmpty) +{ + ASSERT_FALSE(SmallStringView("text").empty()); + ASSERT_TRUE(SmallStringView("").empty()); +} + TEST(SmallString, HasContent) { ASSERT_TRUE(SmallString("text").hasContent());