Googletest export
Remove bool_constant in favor of std::integral_constant<bool, ...>; The one non-trivial use of bool_constant has been changed to have significantly fewer template specializations. PiperOrigin-RevId: 275842490
This commit is contained in:
parent
a5216dd1a9
commit
611a321a6e
@ -142,7 +142,7 @@ class MatcherCastImpl {
|
|||||||
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,
|
||||||
std::true_type /* convertible_to_matcher */,
|
std::true_type /* convertible_to_matcher */,
|
||||||
bool_constant<Ignore>) {
|
std::integral_constant<bool, 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
|
||||||
|
@ -157,9 +157,6 @@ GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
|
|||||||
static_cast< ::testing::internal::TypeKind>( \
|
static_cast< ::testing::internal::TypeKind>( \
|
||||||
::testing::internal::KindOf<type>::value)
|
::testing::internal::KindOf<type>::value)
|
||||||
|
|
||||||
// Evaluates to true if and only if integer type T is signed.
|
|
||||||
#define GMOCK_IS_SIGNED_(T) (static_cast<T>(-1) < 0)
|
|
||||||
|
|
||||||
// LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value
|
// LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value
|
||||||
// is true if and only if arithmetic type From can be losslessly converted to
|
// is true if and only if arithmetic type From can be losslessly converted to
|
||||||
// arithmetic type To.
|
// arithmetic type To.
|
||||||
@ -170,65 +167,30 @@ 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 std::false_type {};
|
using LosslessArithmeticConvertibleImpl = std::integral_constant<
|
||||||
|
bool,
|
||||||
// Converting bool to bool is lossless.
|
// clang-format off
|
||||||
template <>
|
// Converting from bool is always lossless
|
||||||
struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool>
|
(kFromKind == kBool) ? true
|
||||||
: public std::true_type {};
|
// Converting between any other type kinds will be lossy if the type
|
||||||
|
// kinds are not the same.
|
||||||
// Converting bool to any integer type is lossless.
|
: (kFromKind != kToKind) ? false
|
||||||
template <typename To>
|
: (kFromKind == kInteger &&
|
||||||
struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To>
|
// Converting between integers of different widths is allowed so long
|
||||||
: public std::true_type {};
|
// as the conversion does not go from signed to unsigned.
|
||||||
|
(((sizeof(From) < sizeof(To)) &&
|
||||||
// Converting bool to any floating-point type is lossless.
|
!(std::is_signed<From>::value && !std::is_signed<To>::value)) ||
|
||||||
template <typename To>
|
// Converting between integers of the same width only requires the
|
||||||
struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To>
|
// two types to have the same signedness.
|
||||||
: public std::true_type {};
|
((sizeof(From) == sizeof(To)) &&
|
||||||
|
(std::is_signed<From>::value == std::is_signed<To>::value)))
|
||||||
// Converting an integer to bool is lossy.
|
) ? true
|
||||||
template <typename From>
|
// Floating point conversions are lossless if and only if `To` is at least
|
||||||
struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool>
|
// as wide as `From`.
|
||||||
: public std::false_type {};
|
: (kFromKind == kFloatingPoint && (sizeof(From) <= sizeof(To))) ? true
|
||||||
|
: false
|
||||||
// Converting an integer to another non-bool integer is lossless
|
// clang-format on
|
||||||
// if and only if the target type's range encloses the source type's range.
|
>;
|
||||||
template <typename From, typename To>
|
|
||||||
struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To>
|
|
||||||
: public bool_constant<
|
|
||||||
// When converting from a smaller size to a larger size, we are
|
|
||||||
// fine as long as we are not converting from signed to unsigned.
|
|
||||||
((sizeof(From) < sizeof(To)) &&
|
|
||||||
(!GMOCK_IS_SIGNED_(From) || GMOCK_IS_SIGNED_(To))) ||
|
|
||||||
// When converting between the same size, the signedness must match.
|
|
||||||
((sizeof(From) == sizeof(To)) &&
|
|
||||||
(GMOCK_IS_SIGNED_(From) == GMOCK_IS_SIGNED_(To)))> {}; // NOLINT
|
|
||||||
|
|
||||||
#undef GMOCK_IS_SIGNED_
|
|
||||||
|
|
||||||
// Converting an integer to a floating-point type may be lossy, since
|
|
||||||
// the format of a floating-point number is implementation-defined.
|
|
||||||
template <typename From, typename To>
|
|
||||||
struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To>
|
|
||||||
: public std::false_type {};
|
|
||||||
|
|
||||||
// Converting a floating-point to bool is lossy.
|
|
||||||
template <typename From>
|
|
||||||
struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool>
|
|
||||||
: public std::false_type {};
|
|
||||||
|
|
||||||
// Converting a floating-point to an integer is lossy.
|
|
||||||
template <typename From, typename To>
|
|
||||||
struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To>
|
|
||||||
: public std::false_type {};
|
|
||||||
|
|
||||||
// Converting a floating-point to another floating-point is lossless
|
|
||||||
// if and only if the target type is at least as big as the source type.
|
|
||||||
template <typename From, typename To>
|
|
||||||
struct LosslessArithmeticConvertibleImpl<
|
|
||||||
kFloatingPoint, From, kFloatingPoint, To>
|
|
||||||
: public bool_constant<sizeof(From) <= sizeof(To)> {}; // NOLINT
|
|
||||||
|
|
||||||
// LosslessArithmeticConvertible<From, To>::value is true if and only if
|
// LosslessArithmeticConvertible<From, To>::value is true if and only if
|
||||||
// arithmetic type From can be losslessly converted to arithmetic type To.
|
// arithmetic type From can be losslessly converted to arithmetic type To.
|
||||||
@ -238,9 +200,9 @@ struct LosslessArithmeticConvertibleImpl<
|
|||||||
// reference) built-in arithmetic types; the value is
|
// reference) built-in arithmetic types; the value is
|
||||||
// implementation-defined when the above pre-condition is violated.
|
// implementation-defined when the above pre-condition is violated.
|
||||||
template <typename From, typename To>
|
template <typename From, typename To>
|
||||||
struct LosslessArithmeticConvertible
|
using LosslessArithmeticConvertible =
|
||||||
: public LosslessArithmeticConvertibleImpl<
|
LosslessArithmeticConvertibleImpl<GMOCK_KIND_OF_(From), From,
|
||||||
GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {}; // NOLINT
|
GMOCK_KIND_OF_(To), To>;
|
||||||
|
|
||||||
// This interface knows how to report a Google Mock failure (either
|
// This interface knows how to report a Google Mock failure (either
|
||||||
// non-fatal or fatal).
|
// non-fatal or fatal).
|
||||||
|
@ -855,8 +855,7 @@ class GTEST_API_ Random {
|
|||||||
// true if and only if T is type proto2::Message or a subclass of it.
|
// true if and only if T is type proto2::Message or a subclass of it.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct IsAProtocolMessage
|
struct IsAProtocolMessage
|
||||||
: public bool_constant<
|
: public std::is_convertible<const T*, const ::proto2::Message*> {};
|
||||||
std::is_convertible<const T*, const ::proto2::Message*>::value> {};
|
|
||||||
|
|
||||||
// When the compiler sees expression IsContainerTest<C>(0), if C is an
|
// When the compiler sees expression IsContainerTest<C>(0), if C is an
|
||||||
// STL-style container class, the first overload of IsContainerTest
|
// STL-style container class, the first overload of IsContainerTest
|
||||||
|
@ -1875,9 +1875,6 @@ class GTEST_API_ ThreadLocal {
|
|||||||
// we cannot detect it.
|
// we cannot detect it.
|
||||||
GTEST_API_ size_t GetThreadCount();
|
GTEST_API_ size_t GetThreadCount();
|
||||||
|
|
||||||
template <bool B>
|
|
||||||
using bool_constant = std::integral_constant<bool, B>;
|
|
||||||
|
|
||||||
#if GTEST_OS_WINDOWS
|
#if GTEST_OS_WINDOWS
|
||||||
# define GTEST_PATH_SEP_ "\\"
|
# define GTEST_PATH_SEP_ "\\"
|
||||||
# define GTEST_HAS_ALT_PATH_SEP_ 1
|
# define GTEST_HAS_ALT_PATH_SEP_ 1
|
||||||
|
Loading…
Reference in New Issue
Block a user