Changed Template I for compatibility w/ <complex> (see mod_README.md)

This commit is contained in:
sfgeller18 2024-11-04 21:03:59 -08:00
parent d144031940
commit d766e6d0d7
4 changed files with 50 additions and 36 deletions

View File

@ -788,17 +788,17 @@ template <typename T>
void PrintTupleTo(const T&, std::integral_constant<size_t, 0>, void PrintTupleTo(const T&, std::integral_constant<size_t, 0>,
::std::ostream*) {} ::std::ostream*) {}
template <typename T, size_t I> template <typename T, size_t __I>
void PrintTupleTo(const T& t, std::integral_constant<size_t, I>, void PrintTupleTo(const T& t, std::integral_constant<size_t, __I>,
::std::ostream* os) { ::std::ostream* os) {
PrintTupleTo(t, std::integral_constant<size_t, I - 1>(), os); PrintTupleTo(t, std::integral_constant<size_t, __I - 1>(), os);
GTEST_INTENTIONAL_CONST_COND_PUSH_() GTEST_INTENTIONAL_CONST_COND_PUSH_()
if (I > 1) { if (__I > 1) {
GTEST_INTENTIONAL_CONST_COND_POP_() GTEST_INTENTIONAL_CONST_COND_POP_()
*os << ", "; *os << ", ";
} }
UniversalPrinter<typename std::tuple_element<I - 1, T>::type>::Print( UniversalPrinter<typename std::tuple_element<__I - 1, T>::type>::Print(
std::get<I - 1>(t), os); std::get<__I - 1>(t), os);
} }
template <typename... Types> template <typename... Types>
@ -1155,14 +1155,14 @@ typedef ::std::vector<::std::string> Strings;
template <typename Tuple> template <typename Tuple>
void TersePrintPrefixToStrings(const Tuple&, std::integral_constant<size_t, 0>, void TersePrintPrefixToStrings(const Tuple&, std::integral_constant<size_t, 0>,
Strings*) {} Strings*) {}
template <typename Tuple, size_t I> template <typename Tuple, size_t __I>
void TersePrintPrefixToStrings(const Tuple& t, void TersePrintPrefixToStrings(const Tuple& t,
std::integral_constant<size_t, I>, std::integral_constant<size_t, __I>,
Strings* strings) { Strings* strings) {
TersePrintPrefixToStrings(t, std::integral_constant<size_t, I - 1>(), TersePrintPrefixToStrings(t, std::integral_constant<size_t, __I - 1>(),
strings); strings);
::std::stringstream ss; ::std::stringstream ss;
UniversalTersePrint(std::get<I - 1>(t), &ss); UniversalTersePrint(std::get<__I - 1>(t), &ss);
strings->push_back(ss.str()); strings->push_back(ss.str());
} }

View File

@ -1144,14 +1144,14 @@ struct Ignore {
template <typename> template <typename>
struct ElemFromListImpl; struct ElemFromListImpl;
template <size_t... I> template <size_t... __I>
struct ElemFromListImpl<std::index_sequence<I...>> { struct ElemFromListImpl<std::index_sequence<__I...>> {
// We make Ignore a template to solve a problem with MSVC. // We make Ignore a template to solve a problem with MSVC.
// A non-template Ignore would work fine with `decltype(Ignore(I))...`, but // A non-template Ignore would work fine with `decltype(Ignore(I))...`, but
// MSVC doesn't understand how to deal with that pack expansion. // MSVC doesn't understand how to deal with that pack expansion.
// Use `0 * I` to have a single instantiation of Ignore. // Use `0 * I` to have a single instantiation of Ignore.
template <typename R> template <typename R>
static R Apply(Ignore<0 * I>..., R (*)(), ...); static R Apply(Ignore<0 * __I>..., R (*)(), ...);
}; };
template <size_t N, typename... T> template <size_t N, typename... T>
@ -1165,12 +1165,12 @@ struct FlatTupleConstructTag {};
template <typename... T> template <typename... T>
class FlatTuple; class FlatTuple;
template <typename Derived, size_t I> template <typename Derived, size_t __I>
struct FlatTupleElemBase; struct FlatTupleElemBase;
template <typename... T, size_t I> template <typename... T, size_t __I>
struct FlatTupleElemBase<FlatTuple<T...>, I> { struct FlatTupleElemBase<FlatTuple<T...>, __I> {
using value_type = typename ElemFromList<I, T...>::type; using value_type = typename ElemFromList<__I, T...>::type;
FlatTupleElemBase() = default; FlatTupleElemBase() = default;
template <typename Arg> template <typename Arg>
explicit FlatTupleElemBase(FlatTupleConstructTag, Arg&& t) explicit FlatTupleElemBase(FlatTupleConstructTag, Arg&& t)
@ -1191,14 +1191,14 @@ struct FlatTupleBase<FlatTuple<T...>, std::index_sequence<Idx...>>
: FlatTupleElemBase<FlatTuple<T...>, Idx>(FlatTupleConstructTag{}, : FlatTupleElemBase<FlatTuple<T...>, Idx>(FlatTupleConstructTag{},
std::forward<Args>(args))... {} std::forward<Args>(args))... {}
template <size_t I> template <size_t __I>
const typename ElemFromList<I, T...>::type& Get() const { const typename ElemFromList<__I, T...>::type& Get() const {
return FlatTupleElemBase<FlatTuple<T...>, I>::value; return FlatTupleElemBase<FlatTuple<T...>, __I>::value;
} }
template <size_t I> template <size_t __I>
typename ElemFromList<I, T...>::type& Get() { typename ElemFromList<__I, T...>::type& Get() {
return FlatTupleElemBase<FlatTuple<T...>, I>::value; return FlatTupleElemBase<FlatTuple<T...>, __I>::value;
} }
template <typename F> template <typename F>

View File

@ -811,9 +811,9 @@ class ValueArray {
} }
private: private:
template <typename T, size_t... I> template <typename T, size_t... __I>
std::vector<T> MakeVector(std::index_sequence<I...>) const { std::vector<T> MakeVector(std::index_sequence<__I...>) const {
return std::vector<T>{static_cast<T>(v_.template Get<I>())...}; return std::vector<T>{static_cast<T>(v_.template Get<__I>())...};
} }
FlatTuple<Ts...> v_; FlatTuple<Ts...> v_;
@ -838,19 +838,19 @@ class CartesianProductGenerator
return new Iterator(this, generators_, true); return new Iterator(this, generators_, true);
} }
private: private:
template <class I> template <class __I>
class IteratorImpl; class IteratorImpl;
template <size_t... I> template <size_t... __I>
class IteratorImpl<std::index_sequence<I...>> class IteratorImpl<std::index_sequence<__I...>>
: public ParamIteratorInterface<ParamType> { : public ParamIteratorInterface<ParamType> {
public: public:
IteratorImpl(const ParamGeneratorInterface<ParamType>* base, IteratorImpl(const ParamGeneratorInterface<ParamType>* base,
const std::tuple<ParamGenerator<T>...>& generators, const std::tuple<ParamGenerator<T>...>& generators,
bool is_end) bool is_end)
: base_(base), : base_(base),
begin_(std::get<I>(generators).begin()...), begin_(std::get<__I>(generators).begin()...),
end_(std::get<I>(generators).end()...), end_(std::get<__I>(generators).end()...),
current_(is_end ? end_ : begin_) { current_(is_end ? end_ : begin_) {
ComputeCurrentValue(); ComputeCurrentValue();
} }
@ -891,8 +891,8 @@ class CartesianProductGenerator
bool same = true; bool same = true;
bool dummy[] = { bool dummy[] = {
(same = same && std::get<I>(current_) == (same = same && std::get<__I>(current_) ==
std::get<I>(typed_other->current_))...}; std::get<__I>(typed_other->current_))...};
(void)dummy; (void)dummy;
return same; return same;
} }
@ -916,12 +916,12 @@ class CartesianProductGenerator
void ComputeCurrentValue() { void ComputeCurrentValue() {
if (!AtEnd()) if (!AtEnd())
current_value_ = std::make_shared<ParamType>(*std::get<I>(current_)...); current_value_ = std::make_shared<ParamType>(*std::get<__I>(current_)...);
} }
bool AtEnd() const { bool AtEnd() const {
bool at_end = false; bool at_end = false;
bool dummy[] = { bool dummy[] = {
(at_end = at_end || std::get<I>(current_) == std::get<I>(end_))...}; (at_end = at_end || std::get<__I>(current_) == std::get<__I>(end_))...};
(void)dummy; (void)dummy;
return at_end; return at_end;
} }

14
mod_README.md Normal file
View File

@ -0,0 +1,14 @@
**Problem:** Gtest currently interferes w/ std::complex as complex.h uses a define for I already.
**Modifcation:** all **I** template names renamed to **__I** (can use whatever you want, just put a placeholder I figured wouldnt cause interference) at following locations:
**include/internal/gtest-internal.h**:
- lines 1147-1204
**include/gtest-printers.h**:
- PrintTupleTo (l.791-802)
- TersePrintPrefixToStrings (l.1159-1167)
**include/internal/gtest-param-util.h**:
- MakeVector (l.814-817)
- IteratorImpl (l.841-936)