Skip to content

Commit

Permalink
reuse bool_constant from googletest
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzkry committed Aug 14, 2019
1 parent adb7367 commit b8ca465
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
30 changes: 13 additions & 17 deletions googlemock/include/gmock/gmock-matchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,16 @@ class MatcherCastImpl {
// polymorphic_matcher_or_value to Matcher<T> because it won't trigger
// a user-defined conversion from M to T if one exists (assuming M is
// a value).
return CastImpl(
polymorphic_matcher_or_value,
BooleanConstant<
std::is_convertible<M, Matcher<T> >::value>(),
BooleanConstant<
std::is_convertible<M, T>::value>());
return CastImpl(polymorphic_matcher_or_value,
bool_constant<std::is_convertible<M, Matcher<T>>::value>(),
bool_constant<std::is_convertible<M, T>::value>());
}

private:
template <bool Ignore>
static Matcher<T> CastImpl(const M& polymorphic_matcher_or_value,
BooleanConstant<true> /* convertible_to_matcher */,
BooleanConstant<Ignore>) {
bool_constant<true> /* convertible_to_matcher */,
bool_constant<Ignore>) {
// M is implicitly convertible to Matcher<T>, which means that either
// M is a polymorphic matcher or Matcher<T> has an implicit constructor
// from M. In both cases using the implicit conversion will produce a
Expand All @@ -159,9 +156,9 @@ class MatcherCastImpl {
// M can't be implicitly converted to Matcher<T>, so M isn't a polymorphic
// matcher. It's a value of a type implicitly convertible to T. Use direct
// initialization to create a matcher.
static Matcher<T> CastImpl(
const M& value, BooleanConstant<false> /* convertible_to_matcher */,
BooleanConstant<true> /* convertible_to_T */) {
static Matcher<T> CastImpl(const M& value,
bool_constant<false> /* convertible_to_matcher */,
bool_constant<true> /* convertible_to_T */) {
return Matcher<T>(ImplicitCast_<T>(value));
}

Expand All @@ -175,9 +172,9 @@ class MatcherCastImpl {
// (e.g. std::pair<const int, int> vs. std::pair<int, int>).
//
// We don't define this method inline as we need the declaration of Eq().
static Matcher<T> CastImpl(
const M& value, BooleanConstant<false> /* convertible_to_matcher */,
BooleanConstant<false> /* convertible_to_T */);
static Matcher<T> CastImpl(const M& value,
bool_constant<false> /* convertible_to_matcher */,
bool_constant<false> /* convertible_to_T */);
};

// This more specialized version is used when MatcherCast()'s argument
Expand Down Expand Up @@ -3603,9 +3600,8 @@ inline Matcher<T> An() { return A<T>(); }

template <typename T, typename M>
Matcher<T> internal::MatcherCastImpl<T, M>::CastImpl(
const M& value,
internal::BooleanConstant<false> /* convertible_to_matcher */,
internal::BooleanConstant<false> /* convertible_to_T */) {
const M& value, internal::bool_constant<false> /* convertible_to_matcher */,
internal::bool_constant<false> /* convertible_to_T */) {
return Eq(value);
}

Expand Down
5 changes: 0 additions & 5 deletions googlemock/include/gmock/internal/gmock-internal-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,6 @@ struct RemoveConstFromKey<std::pair<const K, V> > {
typedef std::pair<K, V> type;
};

// Mapping from booleans to types. Similar to boost::bool_<kValue> and
// std::integral_constant<bool, kValue>.
template <bool kValue>
struct BooleanConstant {};

// Emit an assertion failure due to incorrect DoDefault() usage. Out-of-lined to
// reduce code size.
GTEST_API_ void IllegalDoDefault(const char* file, int line);
Expand Down

0 comments on commit b8ca465

Please sign in to comment.