From a9a59e06dd7cdfe52c988bf065bc156a7ed96a5c Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 27 Mar 2013 16:14:55 +0000 Subject: Makes WhenSorted() support associative containers (by billydonahue@google.com). --- include/gmock/gmock-matchers.h | 5 ++++- include/gmock/internal/gmock-internal-utils.h | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/gmock/gmock-matchers.h b/include/gmock/gmock-matchers.h index ceb73fdd..962cfde9 100644 --- a/include/gmock/gmock-matchers.h +++ b/include/gmock/gmock-matchers.h @@ -2189,7 +2189,10 @@ class WhenSortedByMatcher { GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView; typedef typename LhsView::type LhsStlContainer; typedef typename LhsView::const_reference LhsStlContainerReference; - typedef typename LhsStlContainer::value_type LhsValue; + // Transforms std::pair into std::pair + // so that we can match associative containers. + typedef typename RemoveConstFromKey< + typename LhsStlContainer::value_type>::type LhsValue; Impl(const Comparator& comparator, const ContainerMatcher& matcher) : comparator_(comparator), matcher_(matcher) {} diff --git a/include/gmock/internal/gmock-internal-utils.h b/include/gmock/internal/gmock-internal-utils.h index f9b6b809..e12b7d7d 100644 --- a/include/gmock/internal/gmock-internal-utils.h +++ b/include/gmock/internal/gmock-internal-utils.h @@ -473,6 +473,20 @@ class StlContainerView< ::std::tr1::tuple > { // StlContainer with a reference type. template class StlContainerView; +// A type transform to remove constness from the first part of a pair. +// Pairs like that are used as the value_type of associative containers, +// and this transform produces a similar but assignable pair. +template +struct RemoveConstFromKey { + typedef T type; +}; + +// Partially specialized to remove constness from std::pair. +template +struct RemoveConstFromKey > { + typedef std::pair type; +}; + // Mapping from booleans to types. Similar to boost::bool_ and // std::integral_constant. template -- cgit v1.2.3