-// Defines a matcher that matches an empty container. The container must
-// support both size() and empty(), which all STL-like containers provide.
-MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") {
- if (arg.empty()) {
- return true;
+namespace internal {
+
+// Implements the polymorphic IsEmpty matcher, which
+// can be used as a Matcher<T> as long as T is either a container that defines
+// empty() and size() (e.g. std::vector or std::string), or a C-style string.
+class IsEmptyMatcher {
+ public:
+ // Matches anything that defines empty() and size().
+ template <typename MatcheeContainerType>
+ bool MatchAndExplain(const MatcheeContainerType& c,
+ MatchResultListener* listener) const {
+ if (c.empty()) {
+ return true;
+ }
+ *listener << "whose size is " << c.size();
+ return false;
+ }
+
+ // Matches C-style strings.
+ bool MatchAndExplain(const char* s, MatchResultListener* listener) const {
+ return MatchAndExplain(std::string(s), listener);