Googletest export
Merge b8ca465e73ac0954a0c9eec2a84bdd8913d5763b into 90a443f9c2
Closes #2396
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/googletest/pull/2396 from kuzkry:custom-type-traits-true/false_type-and-bool_constant b8ca465e73ac0954a0c9eec2a84bdd8913d5763b
PiperOrigin-RevId: 265064856
			
			
This commit is contained in:
		@@ -132,19 +132,16 @@ class MatcherCastImpl {
 | 
				
			|||||||
    // polymorphic_matcher_or_value to Matcher<T> because it won't trigger
 | 
					    // 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 user-defined conversion from M to T if one exists (assuming M is
 | 
				
			||||||
    // a value).
 | 
					    // a value).
 | 
				
			||||||
    return CastImpl(
 | 
					    return CastImpl(polymorphic_matcher_or_value,
 | 
				
			||||||
        polymorphic_matcher_or_value,
 | 
					                    bool_constant<std::is_convertible<M, Matcher<T>>::value>(),
 | 
				
			||||||
        BooleanConstant<
 | 
					                    bool_constant<std::is_convertible<M, T>::value>());
 | 
				
			||||||
            std::is_convertible<M, Matcher<T> >::value>(),
 | 
					 | 
				
			||||||
        BooleanConstant<
 | 
					 | 
				
			||||||
            std::is_convertible<M, T>::value>());
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 private:
 | 
					 private:
 | 
				
			||||||
  template <bool Ignore>
 | 
					  template <bool Ignore>
 | 
				
			||||||
  static Matcher<T> CastImpl(const M& polymorphic_matcher_or_value,
 | 
					  static Matcher<T> CastImpl(const M& polymorphic_matcher_or_value,
 | 
				
			||||||
                             BooleanConstant<true> /* convertible_to_matcher */,
 | 
					                             bool_constant<true> /* convertible_to_matcher */,
 | 
				
			||||||
                             BooleanConstant<Ignore>) {
 | 
					                             bool_constant<Ignore>) {
 | 
				
			||||||
    // M is implicitly convertible to Matcher<T>, which means that either
 | 
					    // M is implicitly convertible to Matcher<T>, which means that either
 | 
				
			||||||
    // M is a polymorphic matcher or Matcher<T> has an implicit constructor
 | 
					    // M is a polymorphic matcher or Matcher<T> has an implicit constructor
 | 
				
			||||||
    // from M.  In both cases using the implicit conversion will produce a
 | 
					    // from M.  In both cases using the implicit conversion will produce a
 | 
				
			||||||
@@ -159,9 +156,9 @@ class MatcherCastImpl {
 | 
				
			|||||||
  // M can't be implicitly converted to Matcher<T>, so M isn't a polymorphic
 | 
					  // 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
 | 
					  // matcher. It's a value of a type implicitly convertible to T. Use direct
 | 
				
			||||||
  // initialization to create a matcher.
 | 
					  // initialization to create a matcher.
 | 
				
			||||||
  static Matcher<T> CastImpl(
 | 
					  static Matcher<T> CastImpl(const M& value,
 | 
				
			||||||
      const M& value, BooleanConstant<false> /* convertible_to_matcher */,
 | 
					                             bool_constant<false> /* convertible_to_matcher */,
 | 
				
			||||||
      BooleanConstant<true> /* convertible_to_T */) {
 | 
					                             bool_constant<true> /* convertible_to_T */) {
 | 
				
			||||||
    return Matcher<T>(ImplicitCast_<T>(value));
 | 
					    return Matcher<T>(ImplicitCast_<T>(value));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -175,9 +172,9 @@ class MatcherCastImpl {
 | 
				
			|||||||
  // (e.g. std::pair<const int, int> vs. std::pair<int, int>).
 | 
					  // (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().
 | 
					  // We don't define this method inline as we need the declaration of Eq().
 | 
				
			||||||
  static Matcher<T> CastImpl(
 | 
					  static Matcher<T> CastImpl(const M& value,
 | 
				
			||||||
      const M& value, BooleanConstant<false> /* convertible_to_matcher */,
 | 
					                             bool_constant<false> /* convertible_to_matcher */,
 | 
				
			||||||
      BooleanConstant<false> /* convertible_to_T */);
 | 
					                             bool_constant<false> /* convertible_to_T */);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// This more specialized version is used when MatcherCast()'s argument
 | 
					// This more specialized version is used when MatcherCast()'s argument
 | 
				
			||||||
@@ -3603,9 +3600,8 @@ inline Matcher<T> An() { return A<T>(); }
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
template <typename T, typename M>
 | 
					template <typename T, typename M>
 | 
				
			||||||
Matcher<T> internal::MatcherCastImpl<T, M>::CastImpl(
 | 
					Matcher<T> internal::MatcherCastImpl<T, M>::CastImpl(
 | 
				
			||||||
    const M& value,
 | 
					    const M& value, internal::bool_constant<false> /* convertible_to_matcher */,
 | 
				
			||||||
    internal::BooleanConstant<false> /* convertible_to_matcher */,
 | 
					    internal::bool_constant<false> /* convertible_to_T */) {
 | 
				
			||||||
    internal::BooleanConstant<false> /* convertible_to_T */) {
 | 
					 | 
				
			||||||
  return Eq(value);
 | 
					  return Eq(value);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -170,27 +170,27 @@ GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
 | 
				
			|||||||
// From, and kToKind is the kind of To; the value is
 | 
					// From, and kToKind is the kind of To; the value is
 | 
				
			||||||
// implementation-defined when the above pre-condition is violated.
 | 
					// implementation-defined when the above pre-condition is violated.
 | 
				
			||||||
template <TypeKind kFromKind, typename From, TypeKind kToKind, typename To>
 | 
					template <TypeKind kFromKind, typename From, TypeKind kToKind, typename To>
 | 
				
			||||||
struct LosslessArithmeticConvertibleImpl : public false_type {};
 | 
					struct LosslessArithmeticConvertibleImpl : public std::false_type {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Converting bool to bool is lossless.
 | 
					// Converting bool to bool is lossless.
 | 
				
			||||||
template <>
 | 
					template <>
 | 
				
			||||||
struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool>
 | 
					struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool>
 | 
				
			||||||
    : public true_type {};  // NOLINT
 | 
					    : public std::true_type {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Converting bool to any integer type is lossless.
 | 
					// Converting bool to any integer type is lossless.
 | 
				
			||||||
template <typename To>
 | 
					template <typename To>
 | 
				
			||||||
struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To>
 | 
					struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To>
 | 
				
			||||||
    : public true_type {};  // NOLINT
 | 
					    : public std::true_type {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Converting bool to any floating-point type is lossless.
 | 
					// Converting bool to any floating-point type is lossless.
 | 
				
			||||||
template <typename To>
 | 
					template <typename To>
 | 
				
			||||||
struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To>
 | 
					struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To>
 | 
				
			||||||
    : public true_type {};  // NOLINT
 | 
					    : public std::true_type {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Converting an integer to bool is lossy.
 | 
					// Converting an integer to bool is lossy.
 | 
				
			||||||
template <typename From>
 | 
					template <typename From>
 | 
				
			||||||
struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool>
 | 
					struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool>
 | 
				
			||||||
    : public false_type {};  // NOLINT
 | 
					    : public std::false_type {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Converting an integer to another non-bool integer is lossless if
 | 
					// Converting an integer to another non-bool integer is lossless if
 | 
				
			||||||
// the target type's range encloses the source type's range.
 | 
					// the target type's range encloses the source type's range.
 | 
				
			||||||
@@ -211,17 +211,17 @@ struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To>
 | 
				
			|||||||
// the format of a floating-point number is implementation-defined.
 | 
					// the format of a floating-point number is implementation-defined.
 | 
				
			||||||
template <typename From, typename To>
 | 
					template <typename From, typename To>
 | 
				
			||||||
struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To>
 | 
					struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To>
 | 
				
			||||||
    : public false_type {};  // NOLINT
 | 
					    : public std::false_type {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Converting a floating-point to bool is lossy.
 | 
					// Converting a floating-point to bool is lossy.
 | 
				
			||||||
template <typename From>
 | 
					template <typename From>
 | 
				
			||||||
struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool>
 | 
					struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool>
 | 
				
			||||||
    : public false_type {};  // NOLINT
 | 
					    : public std::false_type {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Converting a floating-point to an integer is lossy.
 | 
					// Converting a floating-point to an integer is lossy.
 | 
				
			||||||
template <typename From, typename To>
 | 
					template <typename From, typename To>
 | 
				
			||||||
struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To>
 | 
					struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To>
 | 
				
			||||||
    : public false_type {};  // NOLINT
 | 
					    : public std::false_type {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Converting a floating-point to another floating-point is lossless
 | 
					// Converting a floating-point to another floating-point is lossless
 | 
				
			||||||
// if the target type is at least as big as the source type.
 | 
					// if the target type is at least as big as the source type.
 | 
				
			||||||
@@ -470,11 +470,6 @@ struct RemoveConstFromKey<std::pair<const K, V> > {
 | 
				
			|||||||
  typedef std::pair<K, V> type;
 | 
					  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
 | 
					// Emit an assertion failure due to incorrect DoDefault() usage. Out-of-lined to
 | 
				
			||||||
// reduce code size.
 | 
					// reduce code size.
 | 
				
			||||||
GTEST_API_ void IllegalDoDefault(const char* file, int line);
 | 
					GTEST_API_ void IllegalDoDefault(const char* file, int line);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,17 +33,20 @@
 | 
				
			|||||||
// This file tests the internal utilities.
 | 
					// This file tests the internal utilities.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "gmock/internal/gmock-internal-utils.h"
 | 
					#include "gmock/internal/gmock-internal-utils.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <map>
 | 
					#include <map>
 | 
				
			||||||
#include <memory>
 | 
					#include <memory>
 | 
				
			||||||
#include <string>
 | 
					 | 
				
			||||||
#include <sstream>
 | 
					#include <sstream>
 | 
				
			||||||
 | 
					#include <string>
 | 
				
			||||||
#include <type_traits>
 | 
					#include <type_traits>
 | 
				
			||||||
#include <vector>
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "gmock/gmock.h"
 | 
					#include "gmock/gmock.h"
 | 
				
			||||||
#include "gmock/internal/gmock-port.h"
 | 
					#include "gmock/internal/gmock-port.h"
 | 
				
			||||||
#include "gtest/gtest.h"
 | 
					 | 
				
			||||||
#include "gtest/gtest-spi.h"
 | 
					#include "gtest/gtest-spi.h"
 | 
				
			||||||
 | 
					#include "gtest/gtest.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Indicates that this translation unit is part of Google Test's
 | 
					// Indicates that this translation unit is part of Google Test's
 | 
				
			||||||
// implementation.  It must come before gtest-internal-inl.h is
 | 
					// implementation.  It must come before gtest-internal-inl.h is
 | 
				
			||||||
@@ -505,14 +508,6 @@ TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#endif  // GTEST_HAS_STREAM_REDIRECTION
 | 
					#endif  // GTEST_HAS_STREAM_REDIRECTION
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(TypeTraitsTest, true_type) {
 | 
					 | 
				
			||||||
  EXPECT_TRUE(true_type::value);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
TEST(TypeTraitsTest, false_type) {
 | 
					 | 
				
			||||||
  EXPECT_FALSE(false_type::value);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
TEST(TypeTraitsTest, remove_reference) {
 | 
					TEST(TypeTraitsTest, remove_reference) {
 | 
				
			||||||
  EXPECT_TRUE((std::is_same<char, remove_reference<char&>::type>::value));
 | 
					  EXPECT_TRUE((std::is_same<char, remove_reference<char&>::type>::value));
 | 
				
			||||||
  EXPECT_TRUE(
 | 
					  EXPECT_TRUE(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -946,7 +946,7 @@ template <typename C,
 | 
				
			|||||||
struct IsRecursiveContainerImpl;
 | 
					struct IsRecursiveContainerImpl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template <typename C>
 | 
					template <typename C>
 | 
				
			||||||
struct IsRecursiveContainerImpl<C, false> : public false_type {};
 | 
					struct IsRecursiveContainerImpl<C, false> : public std::false_type {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Since the IsRecursiveContainerImpl depends on the IsContainerTest we need to
 | 
					// Since the IsRecursiveContainerImpl depends on the IsContainerTest we need to
 | 
				
			||||||
// obey the same inconsistencies as the IsContainerTest, namely check if
 | 
					// obey the same inconsistencies as the IsContainerTest, namely check if
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1898,15 +1898,8 @@ class GTEST_API_ ThreadLocal {
 | 
				
			|||||||
// we cannot detect it.
 | 
					// we cannot detect it.
 | 
				
			||||||
GTEST_API_ size_t GetThreadCount();
 | 
					GTEST_API_ size_t GetThreadCount();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template <bool bool_value>
 | 
					template <bool B>
 | 
				
			||||||
struct bool_constant {
 | 
					using bool_constant = std::integral_constant<bool, B>;
 | 
				
			||||||
  typedef bool_constant<bool_value> type;
 | 
					 | 
				
			||||||
  static const bool value = bool_value;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
template <bool bool_value> const bool bool_constant<bool_value>::value;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef bool_constant<false> false_type;
 | 
					 | 
				
			||||||
typedef bool_constant<true> true_type;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
template <typename Iterator>
 | 
					template <typename Iterator>
 | 
				
			||||||
struct IteratorTraits {
 | 
					struct IteratorTraits {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user