Commit 7d3b73c8 by Abseil Team Committed by Gennadiy Civil

Unconditionally use std::tuple.

Remove all mention of TR1 tuple and our own implementation of tuple. PiperOrigin-RevId: 216395043
parent 5434989d
...@@ -75,18 +75,6 @@ set(gmock_build_include_dirs ...@@ -75,18 +75,6 @@ set(gmock_build_include_dirs
"${gtest_SOURCE_DIR}") "${gtest_SOURCE_DIR}")
include_directories(${gmock_build_include_dirs}) include_directories(${gmock_build_include_dirs})
# Summary of tuple support for Microsoft Visual Studio:
# Compiler version(MS) version(cmake) Support
# ---------- ----------- -------------- -----------------------------
# <= VS 2010 <= 10 <= 1600 Use Google Tests's own tuple.
# VS 2012 11 1700 std::tr1::tuple + _VARIADIC_MAX=10
# VS 2013 12 1800 std::tr1::tuple
# VS 2015 14 1900 std::tuple
# VS 2017 15 >= 1910 std::tuple
if (MSVC AND MSVC_VERSION EQUAL 1700)
add_definitions(/D _VARIADIC_MAX=10)
endif()
######################################################################## ########################################################################
# #
# Defines the gmock & gmock_main libraries. User tests should link # Defines the gmock & gmock_main libraries. User tests should link
...@@ -199,25 +187,12 @@ $env:Path = \"$project_bin;$env:Path\" ...@@ -199,25 +187,12 @@ $env:Path = \"$project_bin;$env:Path\"
cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
if (MSVC_VERSION LESS 1600) # 1600 is Visual Studio 2010.
# Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that
# conflict with our own definitions. Therefore using our own tuple does not
# work on those compilers.
cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}"
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
cxx_test_with_flags(gmock_use_own_tuple_test "${cxx_use_own_tuple}"
gmock_main_use_own_tuple test/gmock-spec-builders_test.cc)
endif()
else() else()
cxx_library(gmock_main_no_exception "${cxx_no_exception}" src/gmock_main.cc) cxx_library(gmock_main_no_exception "${cxx_no_exception}" src/gmock_main.cc)
target_link_libraries(gmock_main_no_exception PUBLIC gmock) target_link_libraries(gmock_main_no_exception PUBLIC gmock)
cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" src/gmock_main.cc) cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" src/gmock_main.cc)
target_link_libraries(gmock_main_no_rtti PUBLIC gmock) target_link_libraries(gmock_main_no_rtti PUBLIC gmock)
cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}" src/gmock_main.cc)
target_link_libraries(gmock_main_use_own_tuple PUBLIC gmock)
endif() endif()
cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}" cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}"
gmock_main_no_exception test/gmock-more-actions_test.cc) gmock_main_no_exception test/gmock-more-actions_test.cc)
......
...@@ -439,7 +439,7 @@ class Action { ...@@ -439,7 +439,7 @@ class Action {
// template <typename Result, typename ArgumentTuple> // template <typename Result, typename ArgumentTuple>
// Result Perform(const ArgumentTuple& args) const { // Result Perform(const ArgumentTuple& args) const {
// // Processes the arguments and returns a result, using // // Processes the arguments and returns a result, using
// // tr1::get<N>(args) to get the N-th (0-based) argument in the tuple. // // std::get<N>(args) to get the N-th (0-based) argument in the tuple.
// } // }
// ... // ...
// }; // };
...@@ -838,7 +838,7 @@ class SetArgumentPointeeAction { ...@@ -838,7 +838,7 @@ class SetArgumentPointeeAction {
template <typename Result, typename ArgumentTuple> template <typename Result, typename ArgumentTuple>
void Perform(const ArgumentTuple& args) const { void Perform(const ArgumentTuple& args) const {
CompileAssertTypesEqual<void, Result>(); CompileAssertTypesEqual<void, Result>();
*::testing::get<N>(args) = value_; *::std::get<N>(args) = value_;
} }
private: private:
...@@ -861,7 +861,7 @@ class SetArgumentPointeeAction<N, Proto, true> { ...@@ -861,7 +861,7 @@ class SetArgumentPointeeAction<N, Proto, true> {
template <typename Result, typename ArgumentTuple> template <typename Result, typename ArgumentTuple>
void Perform(const ArgumentTuple& args) const { void Perform(const ArgumentTuple& args) const {
CompileAssertTypesEqual<void, Result>(); CompileAssertTypesEqual<void, Result>();
::testing::get<N>(args)->CopyFrom(*proto_); ::std::get<N>(args)->CopyFrom(*proto_);
} }
private: private:
......
...@@ -63,19 +63,19 @@ $range j 1..i ...@@ -63,19 +63,19 @@ $range j 1..i
$var types = [[$for j [[, typename A$j]]]] $var types = [[$for j [[, typename A$j]]]]
$var as = [[$for j, [[A$j]]]] $var as = [[$for j, [[A$j]]]]
$var args = [[$if i==0 [[]] $else [[ args]]]] $var args = [[$if i==0 [[]] $else [[ args]]]]
$var gets = [[$for j, [[get<$(j - 1)>(args)]]]] $var gets = [[$for j, [[std::get<$(j - 1)>(args)]]]]
template <typename R$types> template <typename R$types>
class InvokeHelper<R, ::testing::tuple<$as> > { class InvokeHelper<R, ::std::tuple<$as> > {
public: public:
template <typename Function> template <typename Function>
static R Invoke(Function function, const ::testing::tuple<$as>&$args) { static R Invoke(Function function, const ::std::tuple<$as>&$args) {
return function($gets); return function($gets);
} }
template <class Class, typename MethodPtr> template <class Class, typename MethodPtr>
static R InvokeMethod(Class* obj_ptr, static R InvokeMethod(Class* obj_ptr,
MethodPtr method_ptr, MethodPtr method_ptr,
const ::testing::tuple<$as>&$args) { const ::std::tuple<$as>&$args) {
return (obj_ptr->*method_ptr)($gets); return (obj_ptr->*method_ptr)($gets);
} }
...@@ -83,7 +83,7 @@ class InvokeHelper<R, ::testing::tuple<$as> > { ...@@ -83,7 +83,7 @@ class InvokeHelper<R, ::testing::tuple<$as> > {
$if i <= max_callback_arity [[ $if i <= max_callback_arity [[
template <typename CallbackType> template <typename CallbackType>
static R InvokeCallback(CallbackType* callback, static R InvokeCallback(CallbackType* callback,
const ::testing::tuple<$as>&$args) { const ::std::tuple<$as>&$args) {
return callback->Run($gets); return callback->Run($gets);
} }
]] $else [[ ]] $else [[
...@@ -122,7 +122,7 @@ class InvokeCallbackAction { ...@@ -122,7 +122,7 @@ class InvokeCallbackAction {
// An INTERNAL macro for extracting the type of a tuple field. It's // An INTERNAL macro for extracting the type of a tuple field. It's
// subject to change without notice - DO NOT USE IN USER CODE! // subject to change without notice - DO NOT USE IN USER CODE!
#define GMOCK_FIELD_(Tuple, N) \ #define GMOCK_FIELD_(Tuple, N) \
typename ::testing::tuple_element<N, Tuple>::type typename ::std::tuple_element<N, Tuple>::type
$range i 1..n $range i 1..n
...@@ -130,14 +130,14 @@ $range i 1..n ...@@ -130,14 +130,14 @@ $range i 1..n
// type of an n-ary function whose i-th (1-based) argument type is the // type of an n-ary function whose i-th (1-based) argument type is the
// k{i}-th (0-based) field of ArgumentTuple, which must be a tuple // k{i}-th (0-based) field of ArgumentTuple, which must be a tuple
// type, and whose return type is Result. For example, // type, and whose return type is Result. For example,
// SelectArgs<int, ::testing::tuple<bool, char, double, long>, 0, 3>::type // SelectArgs<int, ::std::tuple<bool, char, double, long>, 0, 3>::type
// is int(bool, long). // is int(bool, long).
// //
// SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args) // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args)
// returns the selected fields (k1, k2, ..., k_n) of args as a tuple. // returns the selected fields (k1, k2, ..., k_n) of args as a tuple.
// For example, // For example,
// SelectArgs<int, tuple<bool, char, double>, 2, 0>::Select( // SelectArgs<int, std::tuple<bool, char, double>, 2, 0>::Select(
// ::testing::make_tuple(true, 'a', 2.5)) // ::std::make_tuple(true, 'a', 2.5))
// returns tuple (2.5, true). // returns tuple (2.5, true).
// //
// The numbers in list k1, k2, ..., k_n must be >= 0, where n can be // The numbers in list k1, k2, ..., k_n must be >= 0, where n can be
...@@ -150,7 +150,7 @@ class SelectArgs { ...@@ -150,7 +150,7 @@ class SelectArgs {
typedef Result type($for i, [[GMOCK_FIELD_(ArgumentTuple, k$i)]]); typedef Result type($for i, [[GMOCK_FIELD_(ArgumentTuple, k$i)]]);
typedef typename Function<type>::ArgumentTuple SelectedArgs; typedef typename Function<type>::ArgumentTuple SelectedArgs;
static SelectedArgs Select(const ArgumentTuple& args) { static SelectedArgs Select(const ArgumentTuple& args) {
return SelectedArgs($for i, [[get<k$i>(args)]]); return SelectedArgs($for i, [[std::get<k$i>(args)]]);
} }
}; };
...@@ -166,7 +166,7 @@ class SelectArgs<Result, ArgumentTuple, ...@@ -166,7 +166,7 @@ class SelectArgs<Result, ArgumentTuple,
typedef typename Function<type>::ArgumentTuple SelectedArgs; typedef typename Function<type>::ArgumentTuple SelectedArgs;
static SelectedArgs Select(const ArgumentTuple& [[]] static SelectedArgs Select(const ArgumentTuple& [[]]
$if i == 1 [[/* args */]] $else [[args]]) { $if i == 1 [[/* args */]] $else [[args]]) {
return SelectedArgs($for j1, [[get<k$j1>(args)]]); return SelectedArgs($for j1, [[std::get<k$j1>(args)]]);
} }
}; };
...@@ -240,12 +240,12 @@ $range j 0..i-1 ...@@ -240,12 +240,12 @@ $range j 0..i-1
]]]] ]]]]
$range j 0..i-1 $range j 0..i-1
$var As = [[$for j, [[A$j]]]] $var As = [[$for j, [[A$j]]]]
$var as = [[$for j, [[get<$j>(args)]]]] $var as = [[$for j, [[std::get<$j>(args)]]]]
$range k 1..n-i $range k 1..n-i
$var eas = [[$for k, [[ExcessiveArg()]]]] $var eas = [[$for k, [[ExcessiveArg()]]]]
$var arg_list = [[$if (i==0) | (i==n) [[$as$eas]] $else [[$as, $eas]]]] $var arg_list = [[$if (i==0) | (i==n) [[$as$eas]] $else [[$as, $eas]]]]
$template $template
static Result Perform(Impl* impl, const ::testing::tuple<$As>& args) { static Result Perform(Impl* impl, const ::std::tuple<$As>& args) {
return impl->template gmock_PerformImpl<$As>(args, $arg_list); return impl->template gmock_PerformImpl<$As>(args, $arg_list);
} }
...@@ -395,8 +395,8 @@ $range j2 2..i ...@@ -395,8 +395,8 @@ $range j2 2..i
// //
// MORE INFORMATION: // MORE INFORMATION:
// //
// To learn more about using these macros, please search for 'ACTION' // To learn more about using these macros, please search for 'ACTION' on
// on https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md // https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md
$range i 0..n $range i 0..n
$range k 0..n-1 $range k 0..n-1
...@@ -432,7 +432,7 @@ $for k [[, \ ...@@ -432,7 +432,7 @@ $for k [[, \
// ACTION_TEMPLATE(DuplicateArg, // ACTION_TEMPLATE(DuplicateArg,
// HAS_2_TEMPLATE_PARAMS(int, k, typename, T), // HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
// AND_1_VALUE_PARAMS(output)) { // AND_1_VALUE_PARAMS(output)) {
// *output = T(::testing::get<k>(args)); // *output = T(::std::get<k>(args));
// } // }
// ... // ...
// int n; // int n;
...@@ -796,7 +796,7 @@ ACTION_TEMPLATE(InvokeArgument, ...@@ -796,7 +796,7 @@ ACTION_TEMPLATE(InvokeArgument,
using internal::invoke_argument::InvokeArgumentAdl; using internal::invoke_argument::InvokeArgumentAdl;
return InvokeArgumentAdl<return_type>( return InvokeArgumentAdl<return_type>(
internal::invoke_argument::AdlTag(), internal::invoke_argument::AdlTag(),
::testing::get<k>(args)$for j [[, p$j]]); ::std::get<k>(args)$for j [[, p$j]]);
} }
]] ]]
......
...@@ -81,7 +81,7 @@ class FunctionMocker<R($As)> : public ...@@ -81,7 +81,7 @@ class FunctionMocker<R($As)> : public
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F> With($matchers) { MockSpec<F> With($matchers) {
return MockSpec<F>(this, ::testing::make_tuple($ms)); return MockSpec<F>(this, ::std::make_tuple($ms));
} }
R Invoke($Aas) { R Invoke($Aas) {
...@@ -194,7 +194,7 @@ $var anything_matchers = [[$for j, \ ...@@ -194,7 +194,7 @@ $var anything_matchers = [[$for j, \
#define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
$arg_as) constness { \ $arg_as) constness { \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GTEST_COMPILE_ASSERT_((::std::tuple_size< \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value == $i), \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value == $i), \
this_method_does_not_take_$i[[]]_argument[[$if i != 1 [[s]]]]); \ this_method_does_not_take_$i[[]]_argument[[$if i != 1 [[s]]]]); \
GMOCK_MOCKER_($i, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_($i, constness, Method).SetOwnerAndName(this, #Method); \
......
...@@ -55,7 +55,7 @@ $range i 0..n-1 ...@@ -55,7 +55,7 @@ $range i 0..n-1
// The type of the i-th (0-based) field of Tuple. // The type of the i-th (0-based) field of Tuple.
#define GMOCK_FIELD_TYPE_(Tuple, i) \ #define GMOCK_FIELD_TYPE_(Tuple, i) \
typename ::testing::tuple_element<i, Tuple>::type typename ::std::tuple_element<i, Tuple>::type
// TupleFields<Tuple, k0, ..., kn> is for selecting fields from a // TupleFields<Tuple, k0, ..., kn> is for selecting fields from a
// tuple of type Tuple. It has two members: // tuple of type Tuple. It has two members:
...@@ -63,10 +63,11 @@ $range i 0..n-1 ...@@ -63,10 +63,11 @@ $range i 0..n-1
// type: a tuple type whose i-th field is the ki-th field of Tuple. // type: a tuple type whose i-th field is the ki-th field of Tuple.
// GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple. // GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple.
// //
// For example, in class TupleFields<tuple<bool, char, int>, 2, 0>, we have: // For example, in class TupleFields<std::tuple<bool, char, int>, 2, 0>,
// we have:
// //
// type is tuple<int, bool>, and // type is std::tuple<int, bool>, and
// GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true). // GetSelectedFields(std::make_tuple(true, 'a', 42)) is (42, true).
template <class Tuple$for i [[, int k$i = -1]]> template <class Tuple$for i [[, int k$i = -1]]>
class TupleFields; class TupleFields;
...@@ -75,9 +76,9 @@ class TupleFields; ...@@ -75,9 +76,9 @@ class TupleFields;
template <class Tuple$for i [[, int k$i]]> template <class Tuple$for i [[, int k$i]]>
class TupleFields { class TupleFields {
public: public:
typedef ::testing::tuple<$for i, [[GMOCK_FIELD_TYPE_(Tuple, k$i)]]> type; typedef ::std::tuple<$for i, [[GMOCK_FIELD_TYPE_(Tuple, k$i)]]> type;
static type GetSelectedFields(const Tuple& t) { static type GetSelectedFields(const Tuple& t) {
return type($for i, [[get<k$i>(t)]]); return type($for i, [[std::get<k$i>(t)]]);
} }
}; };
...@@ -91,9 +92,9 @@ $range k 0..n-1 ...@@ -91,9 +92,9 @@ $range k 0..n-1
template <class Tuple$for j [[, int k$j]]> template <class Tuple$for j [[, int k$j]]>
class TupleFields<Tuple, $for k, [[$if k < i [[k$k]] $else [[-1]]]]> { class TupleFields<Tuple, $for k, [[$if k < i [[k$k]] $else [[-1]]]]> {
public: public:
typedef ::testing::tuple<$for j, [[GMOCK_FIELD_TYPE_(Tuple, k$j)]]> type; typedef ::std::tuple<$for j, [[GMOCK_FIELD_TYPE_(Tuple, k$j)]]> type;
static type GetSelectedFields(const Tuple& $if i==0 [[/* t */]] $else [[t]]) { static type GetSelectedFields(const Tuple& $if i==0 [[/* t */]] $else [[t]]) {
return type($for j, [[get<k$j>(t)]]); return type($for j, [[std::get<k$j>(t)]]);
} }
}; };
...@@ -534,7 +535,7 @@ $var param_field_decls2 = [[$for j ...@@ -534,7 +535,7 @@ $var param_field_decls2 = [[$for j
return ::testing::internal::FormatMatcherDescription(\ return ::testing::internal::FormatMatcherDescription(\
negation, #name, \ negation, #name, \
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::testing::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]])));\ ::std::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]])));\
}\ }\
};\ };\
template <typename arg_type>\ template <typename arg_type>\
......
...@@ -162,7 +162,7 @@ WithArg(const InnerAction& action) { ...@@ -162,7 +162,7 @@ WithArg(const InnerAction& action) {
ACTION_TEMPLATE(ReturnArg, ACTION_TEMPLATE(ReturnArg,
HAS_1_TEMPLATE_PARAMS(int, k), HAS_1_TEMPLATE_PARAMS(int, k),
AND_0_VALUE_PARAMS()) { AND_0_VALUE_PARAMS()) {
return ::testing::get<k>(args); return ::std::get<k>(args);
} }
// Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the // Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the
...@@ -170,7 +170,7 @@ ACTION_TEMPLATE(ReturnArg, ...@@ -170,7 +170,7 @@ ACTION_TEMPLATE(ReturnArg,
ACTION_TEMPLATE(SaveArg, ACTION_TEMPLATE(SaveArg,
HAS_1_TEMPLATE_PARAMS(int, k), HAS_1_TEMPLATE_PARAMS(int, k),
AND_1_VALUE_PARAMS(pointer)) { AND_1_VALUE_PARAMS(pointer)) {
*pointer = ::testing::get<k>(args); *pointer = ::std::get<k>(args);
} }
// Action SaveArgPointee<k>(pointer) saves the value pointed to // Action SaveArgPointee<k>(pointer) saves the value pointed to
...@@ -178,7 +178,7 @@ ACTION_TEMPLATE(SaveArg, ...@@ -178,7 +178,7 @@ ACTION_TEMPLATE(SaveArg,
ACTION_TEMPLATE(SaveArgPointee, ACTION_TEMPLATE(SaveArgPointee,
HAS_1_TEMPLATE_PARAMS(int, k), HAS_1_TEMPLATE_PARAMS(int, k),
AND_1_VALUE_PARAMS(pointer)) { AND_1_VALUE_PARAMS(pointer)) {
*pointer = *::testing::get<k>(args); *pointer = *::std::get<k>(args);
} }
// Action SetArgReferee<k>(value) assigns 'value' to the variable // Action SetArgReferee<k>(value) assigns 'value' to the variable
...@@ -186,13 +186,13 @@ ACTION_TEMPLATE(SaveArgPointee, ...@@ -186,13 +186,13 @@ ACTION_TEMPLATE(SaveArgPointee,
ACTION_TEMPLATE(SetArgReferee, ACTION_TEMPLATE(SetArgReferee,
HAS_1_TEMPLATE_PARAMS(int, k), HAS_1_TEMPLATE_PARAMS(int, k),
AND_1_VALUE_PARAMS(value)) { AND_1_VALUE_PARAMS(value)) {
typedef typename ::testing::tuple_element<k, args_type>::type argk_type; typedef typename ::std::tuple_element<k, args_type>::type argk_type;
// Ensures that argument #k is a reference. If you get a compiler // Ensures that argument #k is a reference. If you get a compiler
// error on the next line, you are using SetArgReferee<k>(value) in // error on the next line, you are using SetArgReferee<k>(value) in
// a mock function whose k-th (0-based) argument is not a reference. // a mock function whose k-th (0-based) argument is not a reference.
GTEST_COMPILE_ASSERT_(internal::is_reference<argk_type>::value, GTEST_COMPILE_ASSERT_(internal::is_reference<argk_type>::value,
SetArgReferee_must_be_used_with_a_reference_argument); SetArgReferee_must_be_used_with_a_reference_argument);
::testing::get<k>(args) = value; ::std::get<k>(args) = value;
} }
// Action SetArrayArgument<k>(first, last) copies the elements in // Action SetArrayArgument<k>(first, last) copies the elements in
...@@ -205,9 +205,9 @@ ACTION_TEMPLATE(SetArrayArgument, ...@@ -205,9 +205,9 @@ ACTION_TEMPLATE(SetArrayArgument,
AND_2_VALUE_PARAMS(first, last)) { AND_2_VALUE_PARAMS(first, last)) {
// Visual Studio deprecates ::std::copy, so we use our own copy in that case. // Visual Studio deprecates ::std::copy, so we use our own copy in that case.
#ifdef _MSC_VER #ifdef _MSC_VER
internal::CopyElements(first, last, ::testing::get<k>(args)); internal::CopyElements(first, last, ::std::get<k>(args));
#else #else
::std::copy(first, last, ::testing::get<k>(args)); ::std::copy(first, last, ::std::get<k>(args));
#endif #endif
} }
...@@ -216,7 +216,7 @@ ACTION_TEMPLATE(SetArrayArgument, ...@@ -216,7 +216,7 @@ ACTION_TEMPLATE(SetArrayArgument,
ACTION_TEMPLATE(DeleteArg, ACTION_TEMPLATE(DeleteArg,
HAS_1_TEMPLATE_PARAMS(int, k), HAS_1_TEMPLATE_PARAMS(int, k),
AND_0_VALUE_PARAMS()) { AND_0_VALUE_PARAMS()) {
delete ::testing::get<k>(args); delete ::std::get<k>(args);
} }
// This action returns the value pointed to by 'pointer'. // This action returns the value pointed to by 'pointer'.
......
...@@ -78,8 +78,8 @@ $var typename_As = [[$for j, [[typename A$j]]]] ...@@ -78,8 +78,8 @@ $var typename_As = [[$for j, [[typename A$j]]]]
$var As = [[$for j, [[A$j]]]] $var As = [[$for j, [[A$j]]]]
$var matcher_As = [[$for j, [[Matcher<A$j>]]]] $var matcher_As = [[$for j, [[Matcher<A$j>]]]]
template <$typename_As> template <$typename_As>
struct MatcherTuple< ::testing::tuple<$As> > { struct MatcherTuple< ::std::tuple<$As> > {
typedef ::testing::tuple<$matcher_As > type; typedef ::std::tuple<$matcher_As > type;
}; };
...@@ -103,7 +103,7 @@ struct Function; ...@@ -103,7 +103,7 @@ struct Function;
template <typename R> template <typename R>
struct Function<R()> { struct Function<R()> {
typedef R Result; typedef R Result;
typedef ::testing::tuple<> ArgumentTuple; typedef ::std::tuple<> ArgumentTuple;
typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
typedef void MakeResultVoid(); typedef void MakeResultVoid();
typedef IgnoredValue MakeResultIgnoredValue(); typedef IgnoredValue MakeResultIgnoredValue();
...@@ -122,7 +122,7 @@ template <typename R$typename_As> ...@@ -122,7 +122,7 @@ template <typename R$typename_As>
struct Function<R($As)> struct Function<R($As)>
: Function<R($prev_As)> { : Function<R($prev_As)> {
typedef A$i Argument$i; typedef A$i Argument$i;
typedef ::testing::tuple<$As> ArgumentTuple; typedef ::std::tuple<$As> ArgumentTuple;
typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
typedef void MakeResultVoid($As); typedef void MakeResultVoid($As);
typedef IgnoredValue MakeResultIgnoredValue($As); typedef IgnoredValue MakeResultIgnoredValue($As);
......
...@@ -493,7 +493,7 @@ class StlContainerView<Element[N]> { ...@@ -493,7 +493,7 @@ class StlContainerView<Element[N]> {
// This specialization is used when RawContainer is a native array // This specialization is used when RawContainer is a native array
// represented as a (pointer, size) tuple. // represented as a (pointer, size) tuple.
template <typename ElementPointer, typename Size> template <typename ElementPointer, typename Size>
class StlContainerView< ::testing::tuple<ElementPointer, Size> > { class StlContainerView< ::std::tuple<ElementPointer, Size> > {
public: public:
typedef GTEST_REMOVE_CONST_( typedef GTEST_REMOVE_CONST_(
typename internal::PointeeOf<ElementPointer>::type) RawElement; typename internal::PointeeOf<ElementPointer>::type) RawElement;
...@@ -501,11 +501,12 @@ class StlContainerView< ::testing::tuple<ElementPointer, Size> > { ...@@ -501,11 +501,12 @@ class StlContainerView< ::testing::tuple<ElementPointer, Size> > {
typedef const type const_reference; typedef const type const_reference;
static const_reference ConstReference( static const_reference ConstReference(
const ::testing::tuple<ElementPointer, Size>& array) { const ::std::tuple<ElementPointer, Size>& array) {
return type(get<0>(array), get<1>(array), RelationToSourceReference()); return type(std::get<0>(array), std::get<1>(array),
RelationToSourceReference());
} }
static type Copy(const ::testing::tuple<ElementPointer, Size>& array) { static type Copy(const ::std::tuple<ElementPointer, Size>& array) {
return type(get<0>(array), get<1>(array), RelationToSourceCopy()); return type(std::get<0>(array), std::get<1>(array), RelationToSourceCopy());
} }
}; };
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
namespace { namespace {
using ::testing::tuple;
using ::testing::Matcher; using ::testing::Matcher;
using ::testing::internal::CompileAssertTypesEqual; using ::testing::internal::CompileAssertTypesEqual;
using ::testing::internal::MatcherTuple; using ::testing::internal::MatcherTuple;
...@@ -48,24 +47,24 @@ using ::testing::internal::IgnoredValue; ...@@ -48,24 +47,24 @@ using ::testing::internal::IgnoredValue;
// Tests the MatcherTuple template struct. // Tests the MatcherTuple template struct.
TEST(MatcherTupleTest, ForSize0) { TEST(MatcherTupleTest, ForSize0) {
CompileAssertTypesEqual<tuple<>, MatcherTuple<tuple<> >::type>(); CompileAssertTypesEqual<std::tuple<>, MatcherTuple<std::tuple<> >::type>();
} }
TEST(MatcherTupleTest, ForSize1) { TEST(MatcherTupleTest, ForSize1) {
CompileAssertTypesEqual<tuple<Matcher<int> >, CompileAssertTypesEqual<std::tuple<Matcher<int> >,
MatcherTuple<tuple<int> >::type>(); MatcherTuple<std::tuple<int> >::type>();
} }
TEST(MatcherTupleTest, ForSize2) { TEST(MatcherTupleTest, ForSize2) {
CompileAssertTypesEqual<tuple<Matcher<int>, Matcher<char> >, CompileAssertTypesEqual<std::tuple<Matcher<int>, Matcher<char> >,
MatcherTuple<tuple<int, char> >::type>(); MatcherTuple<std::tuple<int, char> >::type>();
} }
TEST(MatcherTupleTest, ForSize5) { TEST(MatcherTupleTest, ForSize5) {
CompileAssertTypesEqual< CompileAssertTypesEqual<
tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<double>, std::tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<double>,
Matcher<char*> >, Matcher<char*> >,
MatcherTuple<tuple<int, char, bool, double, char*> >::type>(); MatcherTuple<std::tuple<int, char, bool, double, char*> >::type>();
} }
// Tests the Function template struct. // Tests the Function template struct.
...@@ -73,8 +72,8 @@ TEST(MatcherTupleTest, ForSize5) { ...@@ -73,8 +72,8 @@ TEST(MatcherTupleTest, ForSize5) {
TEST(FunctionTest, Nullary) { TEST(FunctionTest, Nullary) {
typedef Function<int()> F; // NOLINT typedef Function<int()> F; // NOLINT
CompileAssertTypesEqual<int, F::Result>(); CompileAssertTypesEqual<int, F::Result>();
CompileAssertTypesEqual<tuple<>, F::ArgumentTuple>(); CompileAssertTypesEqual<std::tuple<>, F::ArgumentTuple>();
CompileAssertTypesEqual<tuple<>, F::ArgumentMatcherTuple>(); CompileAssertTypesEqual<std::tuple<>, F::ArgumentMatcherTuple>();
CompileAssertTypesEqual<void(), F::MakeResultVoid>(); CompileAssertTypesEqual<void(), F::MakeResultVoid>();
CompileAssertTypesEqual<IgnoredValue(), F::MakeResultIgnoredValue>(); CompileAssertTypesEqual<IgnoredValue(), F::MakeResultIgnoredValue>();
} }
...@@ -83,8 +82,9 @@ TEST(FunctionTest, Unary) { ...@@ -83,8 +82,9 @@ TEST(FunctionTest, Unary) {
typedef Function<int(bool)> F; // NOLINT typedef Function<int(bool)> F; // NOLINT
CompileAssertTypesEqual<int, F::Result>(); CompileAssertTypesEqual<int, F::Result>();
CompileAssertTypesEqual<bool, F::Argument1>(); CompileAssertTypesEqual<bool, F::Argument1>();
CompileAssertTypesEqual<tuple<bool>, F::ArgumentTuple>(); CompileAssertTypesEqual<std::tuple<bool>, F::ArgumentTuple>();
CompileAssertTypesEqual<tuple<Matcher<bool> >, F::ArgumentMatcherTuple>(); CompileAssertTypesEqual<std::tuple<Matcher<bool> >,
F::ArgumentMatcherTuple>();
CompileAssertTypesEqual<void(bool), F::MakeResultVoid>(); // NOLINT CompileAssertTypesEqual<void(bool), F::MakeResultVoid>(); // NOLINT
CompileAssertTypesEqual<IgnoredValue(bool), // NOLINT CompileAssertTypesEqual<IgnoredValue(bool), // NOLINT
F::MakeResultIgnoredValue>(); F::MakeResultIgnoredValue>();
...@@ -95,9 +95,10 @@ TEST(FunctionTest, Binary) { ...@@ -95,9 +95,10 @@ TEST(FunctionTest, Binary) {
CompileAssertTypesEqual<int, F::Result>(); CompileAssertTypesEqual<int, F::Result>();
CompileAssertTypesEqual<bool, F::Argument1>(); CompileAssertTypesEqual<bool, F::Argument1>();
CompileAssertTypesEqual<const long&, F::Argument2>(); // NOLINT CompileAssertTypesEqual<const long&, F::Argument2>(); // NOLINT
CompileAssertTypesEqual<tuple<bool, const long&>, F::ArgumentTuple>(); // NOLINT CompileAssertTypesEqual<std::tuple<bool, const long&>, // NOLINT
F::ArgumentTuple>();
CompileAssertTypesEqual< CompileAssertTypesEqual<
tuple<Matcher<bool>, Matcher<const long&> >, // NOLINT std::tuple<Matcher<bool>, Matcher<const long&> >, // NOLINT
F::ArgumentMatcherTuple>(); F::ArgumentMatcherTuple>();
CompileAssertTypesEqual<void(bool, const long&), F::MakeResultVoid>(); // NOLINT CompileAssertTypesEqual<void(bool, const long&), F::MakeResultVoid>(); // NOLINT
CompileAssertTypesEqual<IgnoredValue(bool, const long&), // NOLINT CompileAssertTypesEqual<IgnoredValue(bool, const long&), // NOLINT
...@@ -112,11 +113,12 @@ TEST(FunctionTest, LongArgumentList) { ...@@ -112,11 +113,12 @@ TEST(FunctionTest, LongArgumentList) {
CompileAssertTypesEqual<char*, F::Argument3>(); CompileAssertTypesEqual<char*, F::Argument3>();
CompileAssertTypesEqual<int&, F::Argument4>(); CompileAssertTypesEqual<int&, F::Argument4>();
CompileAssertTypesEqual<const long&, F::Argument5>(); // NOLINT CompileAssertTypesEqual<const long&, F::Argument5>(); // NOLINT
CompileAssertTypesEqual<tuple<bool, int, char*, int&, const long&>, // NOLINT
F::ArgumentTuple>();
CompileAssertTypesEqual< CompileAssertTypesEqual<
tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, Matcher<int&>, std::tuple<bool, int, char*, int&, const long&>, // NOLINT
Matcher<const long&> >, // NOLINT F::ArgumentTuple>();
CompileAssertTypesEqual<
std::tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, Matcher<int&>,
Matcher<const long&> >, // NOLINT
F::ArgumentMatcherTuple>(); F::ArgumentMatcherTuple>();
CompileAssertTypesEqual<void(bool, int, char*, int&, const long&), // NOLINT CompileAssertTypesEqual<void(bool, int, char*, int&, const long&), // NOLINT
F::MakeResultVoid>(); F::MakeResultVoid>();
......
...@@ -62,9 +62,6 @@ using std::pair; ...@@ -62,9 +62,6 @@ using std::pair;
using std::set; using std::set;
using std::stringstream; using std::stringstream;
using std::vector; using std::vector;
using testing::get;
using testing::make_tuple;
using testing::tuple;
using testing::_; using testing::_;
using testing::AllOf; using testing::AllOf;
using testing::AnyOf; using testing::AnyOf;
...@@ -118,20 +115,20 @@ std::string Explain(const MatcherType& m, const Value& x) { ...@@ -118,20 +115,20 @@ std::string Explain(const MatcherType& m, const Value& x) {
// Tests Args<k0, ..., kn>(m). // Tests Args<k0, ..., kn>(m).
TEST(ArgsTest, AcceptsZeroTemplateArg) { TEST(ArgsTest, AcceptsZeroTemplateArg) {
const tuple<int, bool> t(5, true); const std::tuple<int, bool> t(5, true);
EXPECT_THAT(t, Args<>(Eq(tuple<>()))); EXPECT_THAT(t, Args<>(Eq(std::tuple<>())));
EXPECT_THAT(t, Not(Args<>(Ne(tuple<>())))); EXPECT_THAT(t, Not(Args<>(Ne(std::tuple<>()))));
} }
TEST(ArgsTest, AcceptsOneTemplateArg) { TEST(ArgsTest, AcceptsOneTemplateArg) {
const tuple<int, bool> t(5, true); const std::tuple<int, bool> t(5, true);
EXPECT_THAT(t, Args<0>(Eq(make_tuple(5)))); EXPECT_THAT(t, Args<0>(Eq(std::make_tuple(5))));
EXPECT_THAT(t, Args<1>(Eq(make_tuple(true)))); EXPECT_THAT(t, Args<1>(Eq(std::make_tuple(true))));
EXPECT_THAT(t, Not(Args<1>(Eq(make_tuple(false))))); EXPECT_THAT(t, Not(Args<1>(Eq(std::make_tuple(false)))));
} }
TEST(ArgsTest, AcceptsTwoTemplateArgs) { TEST(ArgsTest, AcceptsTwoTemplateArgs) {
const tuple<short, int, long> t(4, 5, 6L); // NOLINT const std::tuple<short, int, long> t(4, 5, 6L); // NOLINT
EXPECT_THAT(t, (Args<0, 1>(Lt()))); EXPECT_THAT(t, (Args<0, 1>(Lt())));
EXPECT_THAT(t, (Args<1, 2>(Lt()))); EXPECT_THAT(t, (Args<1, 2>(Lt())));
...@@ -139,13 +136,13 @@ TEST(ArgsTest, AcceptsTwoTemplateArgs) { ...@@ -139,13 +136,13 @@ TEST(ArgsTest, AcceptsTwoTemplateArgs) {
} }
TEST(ArgsTest, AcceptsRepeatedTemplateArgs) { TEST(ArgsTest, AcceptsRepeatedTemplateArgs) {
const tuple<short, int, long> t(4, 5, 6L); // NOLINT const std::tuple<short, int, long> t(4, 5, 6L); // NOLINT
EXPECT_THAT(t, (Args<0, 0>(Eq()))); EXPECT_THAT(t, (Args<0, 0>(Eq())));
EXPECT_THAT(t, Not(Args<1, 1>(Ne()))); EXPECT_THAT(t, Not(Args<1, 1>(Ne())));
} }
TEST(ArgsTest, AcceptsDecreasingTemplateArgs) { TEST(ArgsTest, AcceptsDecreasingTemplateArgs) {
const tuple<short, int, long> t(4, 5, 6L); // NOLINT const std::tuple<short, int, long> t(4, 5, 6L); // NOLINT
EXPECT_THAT(t, (Args<2, 0>(Gt()))); EXPECT_THAT(t, (Args<2, 0>(Gt())));
EXPECT_THAT(t, Not(Args<2, 1>(Lt()))); EXPECT_THAT(t, Not(Args<2, 1>(Lt())));
} }
...@@ -161,29 +158,29 @@ TEST(ArgsTest, AcceptsDecreasingTemplateArgs) { ...@@ -161,29 +158,29 @@ TEST(ArgsTest, AcceptsDecreasingTemplateArgs) {
#endif #endif
MATCHER(SumIsZero, "") { MATCHER(SumIsZero, "") {
return get<0>(arg) + get<1>(arg) + get<2>(arg) == 0; return std::get<0>(arg) + std::get<1>(arg) + std::get<2>(arg) == 0;
} }
TEST(ArgsTest, AcceptsMoreTemplateArgsThanArityOfOriginalTuple) { TEST(ArgsTest, AcceptsMoreTemplateArgsThanArityOfOriginalTuple) {
EXPECT_THAT(make_tuple(-1, 2), (Args<0, 0, 1>(SumIsZero()))); EXPECT_THAT(std::make_tuple(-1, 2), (Args<0, 0, 1>(SumIsZero())));
EXPECT_THAT(make_tuple(1, 2), Not(Args<0, 0, 1>(SumIsZero()))); EXPECT_THAT(std::make_tuple(1, 2), Not(Args<0, 0, 1>(SumIsZero())));
} }
TEST(ArgsTest, CanBeNested) { TEST(ArgsTest, CanBeNested) {
const tuple<short, int, long, int> t(4, 5, 6L, 6); // NOLINT const std::tuple<short, int, long, int> t(4, 5, 6L, 6); // NOLINT
EXPECT_THAT(t, (Args<1, 2, 3>(Args<1, 2>(Eq())))); EXPECT_THAT(t, (Args<1, 2, 3>(Args<1, 2>(Eq()))));
EXPECT_THAT(t, (Args<0, 1, 3>(Args<0, 2>(Lt())))); EXPECT_THAT(t, (Args<0, 1, 3>(Args<0, 2>(Lt()))));
} }
TEST(ArgsTest, CanMatchTupleByValue) { TEST(ArgsTest, CanMatchTupleByValue) {
typedef tuple<char, int, int> Tuple3; typedef std::tuple<char, int, int> Tuple3;
const Matcher<Tuple3> m = Args<1, 2>(Lt()); const Matcher<Tuple3> m = Args<1, 2>(Lt());
EXPECT_TRUE(m.Matches(Tuple3('a', 1, 2))); EXPECT_TRUE(m.Matches(Tuple3('a', 1, 2)));
EXPECT_FALSE(m.Matches(Tuple3('b', 2, 2))); EXPECT_FALSE(m.Matches(Tuple3('b', 2, 2)));
} }
TEST(ArgsTest, CanMatchTupleByReference) { TEST(ArgsTest, CanMatchTupleByReference) {
typedef tuple<char, char, int> Tuple3; typedef std::tuple<char, char, int> Tuple3;
const Matcher<const Tuple3&> m = Args<0, 1>(Lt()); const Matcher<const Tuple3&> m = Args<0, 1>(Lt());
EXPECT_TRUE(m.Matches(Tuple3('a', 'b', 2))); EXPECT_TRUE(m.Matches(Tuple3('a', 'b', 2)));
EXPECT_FALSE(m.Matches(Tuple3('b', 'b', 2))); EXPECT_FALSE(m.Matches(Tuple3('b', 'b', 2)));
...@@ -195,23 +192,23 @@ MATCHER_P(PrintsAs, str, "") { ...@@ -195,23 +192,23 @@ MATCHER_P(PrintsAs, str, "") {
} }
TEST(ArgsTest, AcceptsTenTemplateArgs) { TEST(ArgsTest, AcceptsTenTemplateArgs) {
EXPECT_THAT(make_tuple(0, 1L, 2, 3L, 4, 5, 6, 7, 8, 9), EXPECT_THAT(std::make_tuple(0, 1L, 2, 3L, 4, 5, 6, 7, 8, 9),
(Args<9, 8, 7, 6, 5, 4, 3, 2, 1, 0>( (Args<9, 8, 7, 6, 5, 4, 3, 2, 1, 0>(
PrintsAs("(9, 8, 7, 6, 5, 4, 3, 2, 1, 0)")))); PrintsAs("(9, 8, 7, 6, 5, 4, 3, 2, 1, 0)"))));
EXPECT_THAT(make_tuple(0, 1L, 2, 3L, 4, 5, 6, 7, 8, 9), EXPECT_THAT(std::make_tuple(0, 1L, 2, 3L, 4, 5, 6, 7, 8, 9),
Not(Args<9, 8, 7, 6, 5, 4, 3, 2, 1, 0>( Not(Args<9, 8, 7, 6, 5, 4, 3, 2, 1, 0>(
PrintsAs("(0, 8, 7, 6, 5, 4, 3, 2, 1, 0)")))); PrintsAs("(0, 8, 7, 6, 5, 4, 3, 2, 1, 0)"))));
} }
TEST(ArgsTest, DescirbesSelfCorrectly) { TEST(ArgsTest, DescirbesSelfCorrectly) {
const Matcher<tuple<int, bool, char> > m = Args<2, 0>(Lt()); const Matcher<std::tuple<int, bool, char> > m = Args<2, 0>(Lt());
EXPECT_EQ("are a tuple whose fields (#2, #0) are a pair where " EXPECT_EQ("are a tuple whose fields (#2, #0) are a pair where "
"the first < the second", "the first < the second",
Describe(m)); Describe(m));
} }
TEST(ArgsTest, DescirbesNestedArgsCorrectly) { TEST(ArgsTest, DescirbesNestedArgsCorrectly) {
const Matcher<const tuple<int, bool, char, int>&> m = const Matcher<const std::tuple<int, bool, char, int>&> m =
Args<0, 2, 3>(Args<2, 0>(Lt())); Args<0, 2, 3>(Args<2, 0>(Lt()));
EXPECT_EQ("are a tuple whose fields (#0, #2, #3) are a tuple " EXPECT_EQ("are a tuple whose fields (#0, #2, #3) are a tuple "
"whose fields (#2, #0) are a pair where the first < the second", "whose fields (#2, #0) are a pair where the first < the second",
...@@ -219,28 +216,28 @@ TEST(ArgsTest, DescirbesNestedArgsCorrectly) { ...@@ -219,28 +216,28 @@ TEST(ArgsTest, DescirbesNestedArgsCorrectly) {
} }
TEST(ArgsTest, DescribesNegationCorrectly) { TEST(ArgsTest, DescribesNegationCorrectly) {
const Matcher<tuple<int, char> > m = Args<1, 0>(Gt()); const Matcher<std::tuple<int, char> > m = Args<1, 0>(Gt());
EXPECT_EQ("are a tuple whose fields (#1, #0) aren't a pair " EXPECT_EQ("are a tuple whose fields (#1, #0) aren't a pair "
"where the first > the second", "where the first > the second",
DescribeNegation(m)); DescribeNegation(m));
} }
TEST(ArgsTest, ExplainsMatchResultWithoutInnerExplanation) { TEST(ArgsTest, ExplainsMatchResultWithoutInnerExplanation) {
const Matcher<tuple<bool, int, int> > m = Args<1, 2>(Eq()); const Matcher<std::tuple<bool, int, int> > m = Args<1, 2>(Eq());
EXPECT_EQ("whose fields (#1, #2) are (42, 42)", EXPECT_EQ("whose fields (#1, #2) are (42, 42)",
Explain(m, make_tuple(false, 42, 42))); Explain(m, std::make_tuple(false, 42, 42)));
EXPECT_EQ("whose fields (#1, #2) are (42, 43)", EXPECT_EQ("whose fields (#1, #2) are (42, 43)",
Explain(m, make_tuple(false, 42, 43))); Explain(m, std::make_tuple(false, 42, 43)));
} }
// For testing Args<>'s explanation. // For testing Args<>'s explanation.
class LessThanMatcher : public MatcherInterface<tuple<char, int> > { class LessThanMatcher : public MatcherInterface<std::tuple<char, int> > {
public: public:
virtual void DescribeTo(::std::ostream* os) const {} virtual void DescribeTo(::std::ostream* os) const {}
virtual bool MatchAndExplain(tuple<char, int> value, virtual bool MatchAndExplain(std::tuple<char, int> value,
MatchResultListener* listener) const { MatchResultListener* listener) const {
const int diff = get<0>(value) - get<1>(value); const int diff = std::get<0>(value) - std::get<1>(value);
if (diff > 0) { if (diff > 0) {
*listener << "where the first value is " << diff *listener << "where the first value is " << diff
<< " more than the second"; << " more than the second";
...@@ -249,17 +246,18 @@ class LessThanMatcher : public MatcherInterface<tuple<char, int> > { ...@@ -249,17 +246,18 @@ class LessThanMatcher : public MatcherInterface<tuple<char, int> > {
} }
}; };
Matcher<tuple<char, int> > LessThan() { Matcher<std::tuple<char, int> > LessThan() {
return MakeMatcher(new LessThanMatcher); return MakeMatcher(new LessThanMatcher);
} }
TEST(ArgsTest, ExplainsMatchResultWithInnerExplanation) { TEST(ArgsTest, ExplainsMatchResultWithInnerExplanation) {
const Matcher<tuple<char, int, int> > m = Args<0, 2>(LessThan()); const Matcher<std::tuple<char, int, int> > m = Args<0, 2>(LessThan());
EXPECT_EQ("whose fields (#0, #2) are ('a' (97, 0x61), 42), " EXPECT_EQ(
"where the first value is 55 more than the second", "whose fields (#0, #2) are ('a' (97, 0x61), 42), "
Explain(m, make_tuple('a', 42, 42))); "where the first value is 55 more than the second",
Explain(m, std::make_tuple('a', 42, 42)));
EXPECT_EQ("whose fields (#0, #2) are ('\\0', 43)", EXPECT_EQ("whose fields (#0, #2) are ('\\0', 43)",
Explain(m, make_tuple('\0', 42, 43))); Explain(m, std::make_tuple('\0', 42, 43)));
} }
// For testing ExplainMatchResultTo(). // For testing ExplainMatchResultTo().
...@@ -517,7 +515,7 @@ class NativeArrayPassedAsPointerAndSize { ...@@ -517,7 +515,7 @@ class NativeArrayPassedAsPointerAndSize {
TEST(ElementsAreTest, WorksWithNativeArrayPassedAsPointerAndSize) { TEST(ElementsAreTest, WorksWithNativeArrayPassedAsPointerAndSize) {
int array[] = { 0, 1 }; int array[] = { 0, 1 };
::testing::tuple<int*, size_t> array_as_tuple(array, 2); ::std::tuple<int*, size_t> array_as_tuple(array, 2);
EXPECT_THAT(array_as_tuple, ElementsAre(0, 1)); EXPECT_THAT(array_as_tuple, ElementsAre(0, 1));
EXPECT_THAT(array_as_tuple, Not(ElementsAre(0))); EXPECT_THAT(array_as_tuple, Not(ElementsAre(0)));
...@@ -571,8 +569,8 @@ TEST(ElementsAreTest, MakesCopyOfArguments) { ...@@ -571,8 +569,8 @@ TEST(ElementsAreTest, MakesCopyOfArguments) {
int x = 1; int x = 1;
int y = 2; int y = 2;
// This should make a copy of x and y. // This should make a copy of x and y.
::testing::internal::ElementsAreMatcher<testing::tuple<int, int> > ::testing::internal::ElementsAreMatcher<std::tuple<int, int> >
polymorphic_matcher = ElementsAre(x, y); polymorphic_matcher = ElementsAre(x, y);
// Changing x and y now shouldn't affect the meaning of the above matcher. // Changing x and y now shouldn't affect the meaning of the above matcher.
x = y = 0; x = y = 0;
const int array1[] = { 1, 2 }; const int array1[] = { 1, 2 };
...@@ -1235,8 +1233,8 @@ TEST(ContainsTest, AcceptsMatcher) { ...@@ -1235,8 +1233,8 @@ TEST(ContainsTest, AcceptsMatcher) {
TEST(ContainsTest, WorksForNativeArrayAsTuple) { TEST(ContainsTest, WorksForNativeArrayAsTuple) {
const int a[] = { 1, 2 }; const int a[] = { 1, 2 };
const int* const pointer = a; const int* const pointer = a;
EXPECT_THAT(make_tuple(pointer, 2), Contains(1)); EXPECT_THAT(std::make_tuple(pointer, 2), Contains(1));
EXPECT_THAT(make_tuple(pointer, 2), Not(Contains(Gt(3)))); EXPECT_THAT(std::make_tuple(pointer, 2), Not(Contains(Gt(3))));
} }
TEST(ContainsTest, WorksForTwoDimensionalNativeArray) { TEST(ContainsTest, WorksForTwoDimensionalNativeArray) {
......
...@@ -308,26 +308,23 @@ TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) { ...@@ -308,26 +308,23 @@ TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
// Tests the TupleMatches() template function. // Tests the TupleMatches() template function.
TEST(TupleMatchesTest, WorksForSize0) { TEST(TupleMatchesTest, WorksForSize0) {
tuple<> matchers; std::tuple<> matchers;
tuple<> values; std::tuple<> values;
EXPECT_TRUE(TupleMatches(matchers, values)); EXPECT_TRUE(TupleMatches(matchers, values));
} }
TEST(TupleMatchesTest, WorksForSize1) { TEST(TupleMatchesTest, WorksForSize1) {
tuple<Matcher<int> > matchers(Eq(1)); std::tuple<Matcher<int> > matchers(Eq(1));
tuple<int> values1(1), std::tuple<int> values1(1), values2(2);
values2(2);
EXPECT_TRUE(TupleMatches(matchers, values1)); EXPECT_TRUE(TupleMatches(matchers, values1));
EXPECT_FALSE(TupleMatches(matchers, values2)); EXPECT_FALSE(TupleMatches(matchers, values2));
} }
TEST(TupleMatchesTest, WorksForSize2) { TEST(TupleMatchesTest, WorksForSize2) {
tuple<Matcher<int>, Matcher<char> > matchers(Eq(1), Eq('a')); std::tuple<Matcher<int>, Matcher<char> > matchers(Eq(1), Eq('a'));
tuple<int, char> values1(1, 'a'), std::tuple<int, char> values1(1, 'a'), values2(1, 'b'), values3(2, 'a'),
values2(1, 'b'),
values3(2, 'a'),
values4(2, 'b'); values4(2, 'b');
EXPECT_TRUE(TupleMatches(matchers, values1)); EXPECT_TRUE(TupleMatches(matchers, values1));
...@@ -337,10 +334,11 @@ TEST(TupleMatchesTest, WorksForSize2) { ...@@ -337,10 +334,11 @@ TEST(TupleMatchesTest, WorksForSize2) {
} }
TEST(TupleMatchesTest, WorksForSize5) { TEST(TupleMatchesTest, WorksForSize5) {
tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<long>, // NOLINT std::tuple<Matcher<int>, Matcher<char>, Matcher<bool>,
Matcher<std::string> > Matcher<long>, // NOLINT
Matcher<std::string> >
matchers(Eq(1), Eq('a'), Eq(true), Eq(2L), Eq("hi")); matchers(Eq(1), Eq('a'), Eq(true), Eq(2L), Eq("hi"));
tuple<int, char, bool, long, std::string> // NOLINT std::tuple<int, char, bool, long, std::string> // NOLINT
values1(1, 'a', true, 2L, "hi"), values2(1, 'a', true, 2L, "hello"), values1(1, 'a', true, 2L, "hi"), values2(1, 'a', true, 2L, "hello"),
values3(2, 'a', true, 2L, "hi"); values3(2, 'a', true, 2L, "hi");
...@@ -686,22 +684,25 @@ TEST(StlContainerViewTest, WorksForStaticNativeArray) { ...@@ -686,22 +684,25 @@ TEST(StlContainerViewTest, WorksForStaticNativeArray) {
TEST(StlContainerViewTest, WorksForDynamicNativeArray) { TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
StaticAssertTypeEq<NativeArray<int>, StaticAssertTypeEq<NativeArray<int>,
StlContainerView<tuple<const int*, size_t> >::type>(); StlContainerView<std::tuple<const int*, size_t> >::type>();
StaticAssertTypeEq<NativeArray<double>, StaticAssertTypeEq<
StlContainerView<tuple<linked_ptr<double>, int> >::type>(); NativeArray<double>,
StlContainerView<std::tuple<linked_ptr<double>, int> >::type>();
StaticAssertTypeEq<const NativeArray<int>, StaticAssertTypeEq<
StlContainerView<tuple<const int*, int> >::const_reference>(); const NativeArray<int>,
StlContainerView<std::tuple<const int*, int> >::const_reference>();
int a1[3] = { 0, 1, 2 }; int a1[3] = { 0, 1, 2 };
const int* const p1 = a1; const int* const p1 = a1;
NativeArray<int> a2 = StlContainerView<tuple<const int*, int> >:: NativeArray<int> a2 =
ConstReference(make_tuple(p1, 3)); StlContainerView<std::tuple<const int*, int> >::ConstReference(
std::make_tuple(p1, 3));
EXPECT_EQ(3U, a2.size()); EXPECT_EQ(3U, a2.size());
EXPECT_EQ(a1, a2.begin()); EXPECT_EQ(a1, a2.begin());
const NativeArray<int> a3 = StlContainerView<tuple<int*, size_t> >:: const NativeArray<int> a3 = StlContainerView<std::tuple<int*, size_t> >::Copy(
Copy(make_tuple(static_cast<int*>(a1), 3)); std::make_tuple(static_cast<int*>(a1), 3));
ASSERT_EQ(3U, a3.size()); ASSERT_EQ(3U, a3.size());
EXPECT_EQ(0, a3.begin()[0]); EXPECT_EQ(0, a3.begin()[0]);
EXPECT_EQ(1, a3.begin()[1]); EXPECT_EQ(1, a3.begin()[1]);
......
...@@ -110,18 +110,6 @@ set(gtest_build_include_dirs ...@@ -110,18 +110,6 @@ set(gtest_build_include_dirs
"${gtest_SOURCE_DIR}") "${gtest_SOURCE_DIR}")
include_directories(${gtest_build_include_dirs}) include_directories(${gtest_build_include_dirs})
# Summary of tuple support for Microsoft Visual Studio:
# Compiler version(MS) version(cmake) Support
# ---------- ----------- -------------- -----------------------------
# <= VS 2010 <= 10 <= 1600 Use Google Tests's own tuple.
# VS 2012 11 1700 std::tr1::tuple + _VARIADIC_MAX=10
# VS 2013 12 1800 std::tr1::tuple
# VS 2015 14 1900 std::tuple
# VS 2017 15 >= 1910 std::tuple
if (MSVC AND MSVC_VERSION EQUAL 1700)
add_definitions(/D _VARIADIC_MAX=10)
endif()
######################################################################## ########################################################################
# #
# Defines the gtest & gtest_main libraries. User tests should link # Defines the gtest & gtest_main libraries. User tests should link
...@@ -265,21 +253,6 @@ $env:Path = \"$project_bin;$env:Path\" ...@@ -265,21 +253,6 @@ $env:Path = \"$project_bin;$env:Path\"
PROPERTIES PROPERTIES
COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1") COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
if (NOT MSVC OR MSVC_VERSION LESS 1600) # 1600 is Visual Studio 2010.
# Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that
# conflict with our own definitions. Therefore using our own tuple does not
# work on those compilers.
cxx_library(gtest_main_use_own_tuple "${cxx_use_own_tuple}"
src/gtest-all.cc src/gtest_main.cc)
cxx_test_with_flags(googletest-tuple-test "${cxx_use_own_tuple}"
gtest_main_use_own_tuple test/googletest-tuple-test.cc)
cxx_test_with_flags(gtest_use_own_tuple_test "${cxx_use_own_tuple}"
gtest_main_use_own_tuple
test/googletest-param-test-test.cc test/googletest-param-test2-test.cc)
endif()
############################################################ ############################################################
# Python tests. # Python tests.
......
...@@ -148,7 +148,6 @@ macro(config_compiler_and_linker) ...@@ -148,7 +148,6 @@ macro(config_compiler_and_linker)
"${CMAKE_CXX_FLAGS} ${cxx_base_flags} ${cxx_no_exception_flags}") "${CMAKE_CXX_FLAGS} ${cxx_base_flags} ${cxx_no_exception_flags}")
set(cxx_default "${cxx_exception}") set(cxx_default "${cxx_exception}")
set(cxx_no_rtti "${cxx_default} ${cxx_no_rtti_flags}") set(cxx_no_rtti "${cxx_default} ${cxx_no_rtti_flags}")
set(cxx_use_own_tuple "${cxx_default} -DGTEST_USE_OWN_TR1_TUPLE=1")
# For building the gtest libraries. # For building the gtest libraries.
set(cxx_strict "${cxx_default} ${cxx_strict_flags}") set(cxx_strict "${cxx_default} ${cxx_strict_flags}")
......
...@@ -1215,7 +1215,6 @@ inline internal::ParamGenerator<bool> Bool() { ...@@ -1215,7 +1215,6 @@ inline internal::ParamGenerator<bool> Bool() {
return Values(false, true); return Values(false, true);
} }
# if GTEST_HAS_COMBINE
// Combine() allows the user to combine two or more sequences to produce // Combine() allows the user to combine two or more sequences to produce
// values of a Cartesian product of those sequences' elements. // values of a Cartesian product of those sequences' elements.
// //
...@@ -1224,12 +1223,10 @@ inline internal::ParamGenerator<bool> Bool() { ...@@ -1224,12 +1223,10 @@ inline internal::ParamGenerator<bool> Bool() {
// - returns a generator producing sequences with elements coming from // - returns a generator producing sequences with elements coming from
// the Cartesian product of elements from the sequences generated by // the Cartesian product of elements from the sequences generated by
// gen1, gen2, ..., genN. The sequence elements will have a type of // gen1, gen2, ..., genN. The sequence elements will have a type of
// tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types // std::tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types
// of elements from sequences produces by gen1, gen2, ..., genN. // of elements from sequences produces by gen1, gen2, ..., genN.
// //
// Combine can have up to 10 arguments. This number is currently limited // Combine can have up to 10 arguments.
// by the maximum number of elements in the tuple implementation used by Google
// Test.
// //
// Example: // Example:
// //
...@@ -1239,7 +1236,7 @@ inline internal::ParamGenerator<bool> Bool() { ...@@ -1239,7 +1236,7 @@ inline internal::ParamGenerator<bool> Bool() {
// //
// enum Color { BLACK, GRAY, WHITE }; // enum Color { BLACK, GRAY, WHITE };
// class AnimalTest // class AnimalTest
// : public testing::TestWithParam<tuple<const char*, Color> > {...}; // : public testing::TestWithParam<std::tuple<const char*, Color> > {...};
// //
// TEST_P(AnimalTest, AnimalLooksNice) {...} // TEST_P(AnimalTest, AnimalLooksNice) {...}
// //
...@@ -1251,10 +1248,10 @@ inline internal::ParamGenerator<bool> Bool() { ...@@ -1251,10 +1248,10 @@ inline internal::ParamGenerator<bool> Bool() {
// Boolean flags: // Boolean flags:
// //
// class FlagDependentTest // class FlagDependentTest
// : public testing::TestWithParam<tuple<bool, bool> > { // : public testing::TestWithParam<std::tuple<bool, bool> > {
// virtual void SetUp() { // virtual void SetUp() {
// // Assigns external_flag_1 and external_flag_2 values from the tuple. // // Assigns external_flag_1 and external_flag_2 values from the tuple.
// tie(external_flag_1, external_flag_2) = GetParam(); // std::tie(external_flag_1, external_flag_2) = GetParam();
// } // }
// }; // };
// //
...@@ -1367,7 +1364,6 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3, ...@@ -1367,7 +1364,6 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
Generator10>( Generator10>(
g1, g2, g3, g4, g5, g6, g7, g8, g9, g10); g1, g2, g3, g4, g5, g6, g7, g8, g9, g10);
} }
# endif // GTEST_HAS_COMBINE
# define TEST_P(test_case_name, test_name) \ # define TEST_P(test_case_name, test_name) \
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
......
...@@ -372,7 +372,6 @@ inline internal::ParamGenerator<bool> Bool() { ...@@ -372,7 +372,6 @@ inline internal::ParamGenerator<bool> Bool() {
return Values(false, true); return Values(false, true);
} }
# if GTEST_HAS_COMBINE
// Combine() allows the user to combine two or more sequences to produce // Combine() allows the user to combine two or more sequences to produce
// values of a Cartesian product of those sequences' elements. // values of a Cartesian product of those sequences' elements.
// //
...@@ -381,12 +380,10 @@ inline internal::ParamGenerator<bool> Bool() { ...@@ -381,12 +380,10 @@ inline internal::ParamGenerator<bool> Bool() {
// - returns a generator producing sequences with elements coming from // - returns a generator producing sequences with elements coming from
// the Cartesian product of elements from the sequences generated by // the Cartesian product of elements from the sequences generated by
// gen1, gen2, ..., genN. The sequence elements will have a type of // gen1, gen2, ..., genN. The sequence elements will have a type of
// tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types // std::tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types
// of elements from sequences produces by gen1, gen2, ..., genN. // of elements from sequences produces by gen1, gen2, ..., genN.
// //
// Combine can have up to $maxtuple arguments. This number is currently limited // Combine can have up to $maxtuple arguments.
// by the maximum number of elements in the tuple implementation used by Google
// Test.
// //
// Example: // Example:
// //
...@@ -396,7 +393,7 @@ inline internal::ParamGenerator<bool> Bool() { ...@@ -396,7 +393,7 @@ inline internal::ParamGenerator<bool> Bool() {
// //
// enum Color { BLACK, GRAY, WHITE }; // enum Color { BLACK, GRAY, WHITE };
// class AnimalTest // class AnimalTest
// : public testing::TestWithParam<tuple<const char*, Color> > {...}; // : public testing::TestWithParam<std::tuple<const char*, Color> > {...};
// //
// TEST_P(AnimalTest, AnimalLooksNice) {...} // TEST_P(AnimalTest, AnimalLooksNice) {...}
// //
...@@ -408,10 +405,10 @@ inline internal::ParamGenerator<bool> Bool() { ...@@ -408,10 +405,10 @@ inline internal::ParamGenerator<bool> Bool() {
// Boolean flags: // Boolean flags:
// //
// class FlagDependentTest // class FlagDependentTest
// : public testing::TestWithParam<tuple<bool, bool> > { // : public testing::TestWithParam<std::tuple<bool, bool> > {
// virtual void SetUp() { // virtual void SetUp() {
// // Assigns external_flag_1 and external_flag_2 values from the tuple. // // Assigns external_flag_1 and external_flag_2 values from the tuple.
// tie(external_flag_1, external_flag_2) = GetParam(); // std::tie(external_flag_1, external_flag_2) = GetParam();
// } // }
// }; // };
// //
...@@ -433,7 +430,6 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine( ...@@ -433,7 +430,6 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine(
} }
]] ]]
# endif // GTEST_HAS_COMBINE
# define TEST_P(test_case_name, test_name) \ # define TEST_P(test_case_name, test_name) \
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
......
...@@ -104,14 +104,12 @@ ...@@ -104,14 +104,12 @@
#include <ostream> // NOLINT #include <ostream> // NOLINT
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <tuple>
#include <type_traits>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "gtest/internal/gtest-port.h"
#include "gtest/internal/gtest-internal.h" #include "gtest/internal/gtest-internal.h"
#include "gtest/internal/gtest-port.h"
#if GTEST_HAS_STD_TUPLE_
# include <tuple>
#endif
#if GTEST_HAS_ABSL #if GTEST_HAS_ABSL
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
...@@ -643,95 +641,31 @@ void PrintTo(std::reference_wrapper<T> ref, ::std::ostream* os) { ...@@ -643,95 +641,31 @@ void PrintTo(std::reference_wrapper<T> ref, ::std::ostream* os) {
PrintTo(ref.get(), os); PrintTo(ref.get(), os);
} }
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
// Helper function for printing a tuple. T must be instantiated with // Helper function for printing a tuple. T must be instantiated with
// a tuple type. // a tuple type.
template <typename T> template <typename T>
void PrintTupleTo(const T& t, ::std::ostream* os); void PrintTupleTo(const T&, std::integral_constant<size_t, 0>,
#endif // GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_ ::std::ostream*) {}
#if GTEST_HAS_TR1_TUPLE template <typename T, size_t I>
// Overload for ::std::tr1::tuple. Needed for printing function arguments, void PrintTupleTo(const T& t, std::integral_constant<size_t, I>,
// which are packed as tuples. ::std::ostream* os) {
PrintTupleTo(t, std::integral_constant<size_t, I - 1>(), os);
// Overloaded PrintTo() for tuples of various arities. We support GTEST_INTENTIONAL_CONST_COND_PUSH_()
// tuples of up-to 10 fields. The following implementation works if (I > 1) {
// regardless of whether tr1::tuple is implemented using the GTEST_INTENTIONAL_CONST_COND_POP_()
// non-standard variadic template feature or not. *os << ", ";
}
inline void PrintTo(const ::std::tr1::tuple<>& t, ::std::ostream* os) { UniversalPrinter<typename std::tuple_element<I - 1, T>::type>::Print(
PrintTupleTo(t, os); std::get<I - 1>(t), os);
}
template <typename T1>
void PrintTo(const ::std::tr1::tuple<T1>& t, ::std::ostream* os) {
PrintTupleTo(t, os);
}
template <typename T1, typename T2>
void PrintTo(const ::std::tr1::tuple<T1, T2>& t, ::std::ostream* os) {
PrintTupleTo(t, os);
}
template <typename T1, typename T2, typename T3>
void PrintTo(const ::std::tr1::tuple<T1, T2, T3>& t, ::std::ostream* os) {
PrintTupleTo(t, os);
}
template <typename T1, typename T2, typename T3, typename T4>
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4>& t, ::std::ostream* os) {
PrintTupleTo(t, os);
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5>& t,
::std::ostream* os) {
PrintTupleTo(t, os);
}
template <typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6>
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6>& t,
::std::ostream* os) {
PrintTupleTo(t, os);
}
template <typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7>
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7>& t,
::std::ostream* os) {
PrintTupleTo(t, os);
}
template <typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8>
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8>& t,
::std::ostream* os) {
PrintTupleTo(t, os);
}
template <typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9>
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>& t,
::std::ostream* os) {
PrintTupleTo(t, os);
}
template <typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10>
void PrintTo(
const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>& t,
::std::ostream* os) {
PrintTupleTo(t, os);
} }
#endif // GTEST_HAS_TR1_TUPLE
#if GTEST_HAS_STD_TUPLE_
template <typename... Types> template <typename... Types>
void PrintTo(const ::std::tuple<Types...>& t, ::std::ostream* os) { void PrintTo(const ::std::tuple<Types...>& t, ::std::ostream* os) {
PrintTupleTo(t, os); *os << "(";
PrintTupleTo(t, std::integral_constant<size_t, sizeof...(Types)>(), os);
*os << ")";
} }
#endif // GTEST_HAS_STD_TUPLE_
// Overload for std::pair. // Overload for std::pair.
template <typename T1, typename T2> template <typename T1, typename T2>
...@@ -962,109 +896,20 @@ void UniversalPrint(const T& value, ::std::ostream* os) { ...@@ -962,109 +896,20 @@ void UniversalPrint(const T& value, ::std::ostream* os) {
typedef ::std::vector< ::std::string> Strings; typedef ::std::vector< ::std::string> Strings;
// TuplePolicy<TupleT> must provide:
// - tuple_size
// size of tuple TupleT.
// - get<size_t I>(const TupleT& t)
// static function extracting element I of tuple TupleT.
// - tuple_element<size_t I>::type
// type of element I of tuple TupleT.
template <typename TupleT>
struct TuplePolicy;
#if GTEST_HAS_TR1_TUPLE
template <typename TupleT>
struct TuplePolicy {
typedef TupleT Tuple;
static const size_t tuple_size = ::std::tr1::tuple_size<Tuple>::value;
template <size_t I>
struct tuple_element : ::std::tr1::tuple_element<static_cast<int>(I), Tuple> {
};
template <size_t I>
static typename AddReference<const typename ::std::tr1::tuple_element<
static_cast<int>(I), Tuple>::type>::type
get(const Tuple& tuple) {
return ::std::tr1::get<I>(tuple);
}
};
template <typename TupleT>
const size_t TuplePolicy<TupleT>::tuple_size;
#endif // GTEST_HAS_TR1_TUPLE
#if GTEST_HAS_STD_TUPLE_
template <typename... Types>
struct TuplePolicy< ::std::tuple<Types...> > {
typedef ::std::tuple<Types...> Tuple;
static const size_t tuple_size = ::std::tuple_size<Tuple>::value;
template <size_t I>
struct tuple_element : ::std::tuple_element<I, Tuple> {};
template <size_t I>
static const typename ::std::tuple_element<I, Tuple>::type& get(
const Tuple& tuple) {
return ::std::get<I>(tuple);
}
};
template <typename... Types>
const size_t TuplePolicy< ::std::tuple<Types...> >::tuple_size;
#endif // GTEST_HAS_STD_TUPLE_
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
// This helper template allows PrintTo() for tuples and
// UniversalTersePrintTupleFieldsToStrings() to be defined by
// induction on the number of tuple fields. The idea is that
// TuplePrefixPrinter<N>::PrintPrefixTo(t, os) prints the first N
// fields in tuple t, and can be defined in terms of
// TuplePrefixPrinter<N - 1>.
//
// The inductive case.
template <size_t N>
struct TuplePrefixPrinter {
// Prints the first N fields of a tuple.
template <typename Tuple>
static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
GTEST_INTENTIONAL_CONST_COND_PUSH_()
if (N > 1) {
GTEST_INTENTIONAL_CONST_COND_POP_()
*os << ", ";
}
UniversalPrinter<
typename TuplePolicy<Tuple>::template tuple_element<N - 1>::type>
::Print(TuplePolicy<Tuple>::template get<N - 1>(t), os);
}
// Tersely prints the first N fields of a tuple to a string vector, // Tersely prints the first N fields of a tuple to a string vector,
// one element for each field. // one element for each field.
template <typename Tuple>
static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {
TuplePrefixPrinter<N - 1>::TersePrintPrefixToStrings(t, strings);
::std::stringstream ss;
UniversalTersePrint(TuplePolicy<Tuple>::template get<N - 1>(t), &ss);
strings->push_back(ss.str());
}
};
// Base case.
template <>
struct TuplePrefixPrinter<0> {
template <typename Tuple>
static void PrintPrefixTo(const Tuple&, ::std::ostream*) {}
template <typename Tuple>
static void TersePrintPrefixToStrings(const Tuple&, Strings*) {}
};
// Helper function for printing a tuple.
// Tuple must be either std::tr1::tuple or std::tuple type.
template <typename Tuple> template <typename Tuple>
void PrintTupleTo(const Tuple& t, ::std::ostream* os) { void TersePrintPrefixToStrings(const Tuple&, std::integral_constant<size_t, 0>,
*os << "("; Strings*) {}
TuplePrefixPrinter<TuplePolicy<Tuple>::tuple_size>::PrintPrefixTo(t, os); template <typename Tuple, size_t I>
*os << ")"; void TersePrintPrefixToStrings(const Tuple& t,
std::integral_constant<size_t, I>,
Strings* strings) {
TersePrintPrefixToStrings(t, std::integral_constant<size_t, I - 1>(),
strings);
::std::stringstream ss;
UniversalTersePrint(std::get<I - 1>(t), &ss);
strings->push_back(ss.str());
} }
// Prints the fields of a tuple tersely to a string vector, one // Prints the fields of a tuple tersely to a string vector, one
...@@ -1073,11 +918,11 @@ void PrintTupleTo(const Tuple& t, ::std::ostream* os) { ...@@ -1073,11 +918,11 @@ void PrintTupleTo(const Tuple& t, ::std::ostream* os) {
template <typename Tuple> template <typename Tuple>
Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) { Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {
Strings result; Strings result;
TuplePrefixPrinter<TuplePolicy<Tuple>::tuple_size>:: TersePrintPrefixToStrings(
TersePrintPrefixToStrings(value, &result); value, std::integral_constant<size_t, std::tuple_size<Tuple>::value>(),
&result);
return result; return result;
} }
#endif // GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
} // namespace internal } // namespace internal
......
...@@ -98,7 +98,6 @@ $for j [[ ...@@ -98,7 +98,6 @@ $for j [[
]] ]]
# if GTEST_HAS_COMBINE
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
// //
// Generates values from the Cartesian product of values produced // Generates values from the Cartesian product of values produced
...@@ -111,9 +110,9 @@ $range k 2..i ...@@ -111,9 +110,9 @@ $range k 2..i
template <$for j, [[typename T$j]]> template <$for j, [[typename T$j]]>
class CartesianProductGenerator$i class CartesianProductGenerator$i
: public ParamGeneratorInterface< ::testing::tuple<$for j, [[T$j]]> > { : public ParamGeneratorInterface< ::std::tuple<$for j, [[T$j]]> > {
public: public:
typedef ::testing::tuple<$for j, [[T$j]]> ParamType; typedef ::std::tuple<$for j, [[T$j]]> ParamType;
CartesianProductGenerator$i($for j, [[const ParamGenerator<T$j>& g$j]]) CartesianProductGenerator$i($for j, [[const ParamGenerator<T$j>& g$j]])
: $for j, [[g$(j)_(g$j)]] {} : $for j, [[g$(j)_(g$j)]] {}
...@@ -252,8 +251,8 @@ class CartesianProductHolder$i { ...@@ -252,8 +251,8 @@ class CartesianProductHolder$i {
CartesianProductHolder$i($for j, [[const Generator$j& g$j]]) CartesianProductHolder$i($for j, [[const Generator$j& g$j]])
: $for j, [[g$(j)_(g$j)]] {} : $for j, [[g$(j)_(g$j)]] {}
template <$for j, [[typename T$j]]> template <$for j, [[typename T$j]]>
operator ParamGenerator< ::testing::tuple<$for j, [[T$j]]> >() const { operator ParamGenerator< ::std::tuple<$for j, [[T$j]]> >() const {
return ParamGenerator< ::testing::tuple<$for j, [[T$j]]> >( return ParamGenerator< ::std::tuple<$for j, [[T$j]]> >(
new CartesianProductGenerator$i<$for j, [[T$j]]>( new CartesianProductGenerator$i<$for j, [[T$j]]>(
$for j,[[ $for j,[[
...@@ -274,8 +273,6 @@ $for j [[ ...@@ -274,8 +273,6 @@ $for j [[
]] ]]
# endif // GTEST_HAS_COMBINE
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
......
...@@ -85,8 +85,6 @@ ...@@ -85,8 +85,6 @@
// GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that // GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that
// std::wstring does/doesn't work (Google Test can // std::wstring does/doesn't work (Google Test can
// be used where std::wstring is unavailable). // be used where std::wstring is unavailable).
// GTEST_HAS_TR1_TUPLE - Define it to 1/0 to indicate tr1::tuple
// is/isn't available.
// GTEST_HAS_SEH - Define it to 1/0 to indicate whether the // GTEST_HAS_SEH - Define it to 1/0 to indicate whether the
// compiler supports Microsoft's "Structured // compiler supports Microsoft's "Structured
// Exception Handling". // Exception Handling".
...@@ -94,10 +92,6 @@ ...@@ -94,10 +92,6 @@
// - Define it to 1/0 to indicate whether the // - Define it to 1/0 to indicate whether the
// platform supports I/O stream redirection using // platform supports I/O stream redirection using
// dup() and dup2(). // dup() and dup2().
// GTEST_USE_OWN_TR1_TUPLE - Define it to 1/0 to indicate whether Google
// Test's own tr1 tuple implementation should be
// used. Unused when the user sets
// GTEST_HAS_TR1_TUPLE to 0.
// GTEST_LANG_CXX11 - Define it to 1/0 to indicate that Google Test // GTEST_LANG_CXX11 - Define it to 1/0 to indicate that Google Test
// is building in C++11/C++98 mode. // is building in C++11/C++98 mode.
// GTEST_LINKED_AS_SHARED_LIBRARY // GTEST_LINKED_AS_SHARED_LIBRARY
...@@ -172,8 +166,6 @@ ...@@ -172,8 +166,6 @@
// EXPECT_DEATH(DoSomethingDeadly()); // EXPECT_DEATH(DoSomethingDeadly());
// #endif // #endif
// //
// GTEST_HAS_COMBINE - the Combine() function (for value-parameterized
// tests)
// GTEST_HAS_DEATH_TEST - death tests // GTEST_HAS_DEATH_TEST - death tests
// GTEST_HAS_TYPED_TEST - typed tests // GTEST_HAS_TYPED_TEST - typed tests
// GTEST_HAS_TYPED_TEST_P - type-parameterized tests // GTEST_HAS_TYPED_TEST_P - type-parameterized tests
...@@ -280,10 +272,11 @@ ...@@ -280,10 +272,11 @@
// Brings in the definition of HAS_GLOBAL_STRING. This must be done // Brings in the definition of HAS_GLOBAL_STRING. This must be done
// BEFORE we test HAS_GLOBAL_STRING. // BEFORE we test HAS_GLOBAL_STRING.
#include <string> // NOLINT #include <string> // NOLINT
#include <algorithm> // NOLINT #include <algorithm> // NOLINT
#include <iostream> // NOLINT #include <iostream> // NOLINT
#include <sstream> // NOLINT #include <sstream> // NOLINT
#include <tuple>
#include <utility> #include <utility>
#include <vector> // NOLINT #include <vector> // NOLINT
...@@ -381,31 +374,6 @@ ...@@ -381,31 +374,6 @@
# define GTEST_HAS_UNORDERED_SET_ 1 # define GTEST_HAS_UNORDERED_SET_ 1
#endif #endif
// C++11 specifies that <tuple> provides std::tuple.
// Some platforms still might not have it, however.
#if GTEST_LANG_CXX11
# define GTEST_HAS_STD_TUPLE_ 1
# if defined(__clang__)
// Inspired by
// https://clang.llvm.org/docs/LanguageExtensions.html#include-file-checking-macros
# if defined(__has_include) && !__has_include(<tuple>)
# undef GTEST_HAS_STD_TUPLE_
# endif
# elif defined(_MSC_VER)
// Inspired by boost/config/stdlib/dinkumware.hpp
# if defined(_CPPLIB_VER) && _CPPLIB_VER < 520
# undef GTEST_HAS_STD_TUPLE_
# endif
# elif defined(__GLIBCXX__)
// Inspired by boost/config/stdlib/libstdcpp3.hpp,
// http://gcc.gnu.org/gcc-4.2/changes.html and
// https://web.archive.org/web/20140227044429/gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt01ch01.html#manual.intro.status.standard.200x
# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
# undef GTEST_HAS_STD_TUPLE_
# endif
# endif
#endif
// Brings in definitions for functions used in the testing::internal::posix // Brings in definitions for functions used in the testing::internal::posix
// namespace (read, write, close, chdir, isatty, stat). We do not currently // namespace (read, write, close, chdir, isatty, stat). We do not currently
// use them on Windows Mobile. // use them on Windows Mobile.
...@@ -647,127 +615,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -647,127 +615,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
# endif // _MSC_VER # endif // _MSC_VER
#endif // !defined(GTEST_HAS_HASH_MAP_) #endif // !defined(GTEST_HAS_HASH_MAP_)
// Determines whether Google Test can use tr1/tuple. You can define
// this macro to 0 to prevent Google Test from using tuple (any
// feature depending on tuple with be disabled in this mode).
#ifndef GTEST_HAS_TR1_TUPLE
# if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR)
// STLport, provided with the Android NDK, has neither <tr1/tuple> or <tuple>.
# define GTEST_HAS_TR1_TUPLE 0
# elif defined(_MSC_VER) && (_MSC_VER >= 1910)
// Prevent `warning C4996: 'std::tr1': warning STL4002:
// The non-Standard std::tr1 namespace and TR1-only machinery
// are deprecated and will be REMOVED.`
# define GTEST_HAS_TR1_TUPLE 0
# elif GTEST_LANG_CXX11 && defined(_LIBCPP_VERSION)
// libc++ doesn't support TR1.
# define GTEST_HAS_TR1_TUPLE 0
# else
// The user didn't tell us not to do it, so we assume it's OK.
# define GTEST_HAS_TR1_TUPLE 1
# endif
#endif // GTEST_HAS_TR1_TUPLE
// Determines whether Google Test's own tr1 tuple implementation
// should be used.
#ifndef GTEST_USE_OWN_TR1_TUPLE
// We use our own tuple implementation on Symbian.
# if GTEST_OS_SYMBIAN
# define GTEST_USE_OWN_TR1_TUPLE 1
# else
// The user didn't tell us, so we need to figure it out.
// We use our own TR1 tuple if we aren't sure the user has an
// implementation of it already. At this time, libstdc++ 4.0.0+ and
// MSVC 2010 are the only mainstream standard libraries that come
// with a TR1 tuple implementation. NVIDIA's CUDA NVCC compiler
// pretends to be GCC by defining __GNUC__ and friends, but cannot
// compile GCC's tuple implementation. MSVC 2008 (9.0) provides TR1
// tuple in a 323 MB Feature Pack download, which we cannot assume the
// user has. QNX's QCC compiler is a modified GCC but it doesn't
// support TR1 tuple. libc++ only provides std::tuple, in C++11 mode,
// and it can be used with some compilers that define __GNUC__.
# if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000) \
&& !GTEST_OS_QNX && !defined(_LIBCPP_VERSION)) \
|| (_MSC_VER >= 1600 && _MSC_VER < 1900)
# define GTEST_ENV_HAS_TR1_TUPLE_ 1
# endif
// C++11 specifies that <tuple> provides std::tuple. Use that if gtest is used
// in C++11 mode and libstdc++ isn't very old (binaries targeting OS X 10.6
// can build with clang but need to use gcc4.2's libstdc++).
# if GTEST_LANG_CXX11 && (!defined(__GLIBCXX__) || __GLIBCXX__ > 20110325)
# define GTEST_ENV_HAS_STD_TUPLE_ 1
# endif
# if GTEST_ENV_HAS_TR1_TUPLE_ || GTEST_ENV_HAS_STD_TUPLE_
# define GTEST_USE_OWN_TR1_TUPLE 0
# else
# define GTEST_USE_OWN_TR1_TUPLE 1
# endif
# endif // GTEST_OS_SYMBIAN
#endif // GTEST_USE_OWN_TR1_TUPLE
// To avoid conditional compilation we make it gtest-port.h's responsibility
// to #include the header implementing tuple.
#if GTEST_HAS_STD_TUPLE_
# include <tuple> // IWYU pragma: export
# define GTEST_TUPLE_NAMESPACE_ ::std
#endif // GTEST_HAS_STD_TUPLE_
// We include tr1::tuple even if std::tuple is available to define printers for
// them.
#if GTEST_HAS_TR1_TUPLE
# ifndef GTEST_TUPLE_NAMESPACE_
# define GTEST_TUPLE_NAMESPACE_ ::std::tr1
# endif // GTEST_TUPLE_NAMESPACE_
# if GTEST_USE_OWN_TR1_TUPLE
# include "third_party/googletest/googletest/include/gtest/internal/gtest-tuple.h" // IWYU pragma: export // NOLINT
# elif GTEST_OS_SYMBIAN
// On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
// use STLport's tuple implementation, which unfortunately doesn't
// work as the copy of STLport distributed with Symbian is incomplete.
// By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to
// use its own tuple implementation.
# ifdef BOOST_HAS_TR1_TUPLE
# undef BOOST_HAS_TR1_TUPLE
# endif // BOOST_HAS_TR1_TUPLE
// This prevents <boost/tr1/detail/config.hpp>, which defines
// BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>.
# define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
# include <tuple> // IWYU pragma: export // NOLINT
# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
// GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header. This does
// not conform to the TR1 spec, which requires the header to be <tuple>.
# if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
// Until version 4.3.2, gcc has a bug that causes <tr1/functional>,
// which is #included by <tr1/tuple>, to not compile when RTTI is
// disabled. _TR1_FUNCTIONAL is the header guard for
// <tr1/functional>. Hence the following #define is used to prevent
// <tr1/functional> from being included.
# define _TR1_FUNCTIONAL 1
# include <tr1/tuple>
# undef _TR1_FUNCTIONAL // Allows the user to #include
// <tr1/functional> if they choose to.
# else
# include <tr1/tuple> // NOLINT
# endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
// VS 2010 now has tr1 support.
# elif _MSC_VER >= 1600
# include <tuple> // IWYU pragma: export // NOLINT
# else // GTEST_USE_OWN_TR1_TUPLE
# include <tr1/tuple> // IWYU pragma: export // NOLINT
# endif // GTEST_USE_OWN_TR1_TUPLE
#endif // GTEST_HAS_TR1_TUPLE
// Determines whether clone(2) is supported. // Determines whether clone(2) is supported.
// Usually it will only be available on Linux, excluding // Usually it will only be available on Linux, excluding
// Linux on the Itanium architecture. // Linux on the Itanium architecture.
...@@ -832,14 +679,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -832,14 +679,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
# define GTEST_HAS_TYPED_TEST_P 1 # define GTEST_HAS_TYPED_TEST_P 1
#endif #endif
// Determines whether to support Combine(). This only makes sense when
// value-parameterized tests are enabled. The implementation doesn't
// work on Sun Studio since it doesn't understand templated conversion
// operators.
#if (GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_) && !defined(__SUNPRO_CC)
# define GTEST_HAS_COMBINE 1
#endif
// Determines whether the system compiler uses UTF-16 for encoding wide strings. // Determines whether the system compiler uses UTF-16 for encoding wide strings.
#define GTEST_WIDE_STRING_USES_UTF16_ \ #define GTEST_WIDE_STRING_USES_UTF16_ \
(GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX) (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX)
...@@ -1049,16 +888,13 @@ namespace testing { ...@@ -1049,16 +888,13 @@ namespace testing {
class Message; class Message;
#if defined(GTEST_TUPLE_NAMESPACE_) // Legacy imports for backwards compatibility.
// Import tuple and friends into the ::testing namespace. // New code should use std:: names directly.
// It is part of our interface, having them in ::testing allows us to change using std::get;
// their types as needed. using std::make_tuple;
using GTEST_TUPLE_NAMESPACE_::get; using std::tuple;
using GTEST_TUPLE_NAMESPACE_::make_tuple; using std::tuple_element;
using GTEST_TUPLE_NAMESPACE_::tuple; using std::tuple_size;
using GTEST_TUPLE_NAMESPACE_::tuple_size;
using GTEST_TUPLE_NAMESPACE_::tuple_element;
#endif // defined(GTEST_TUPLE_NAMESPACE_)
namespace internal { namespace internal {
......
$$ -*- mode: c++; -*-
$var n = 10 $$ Maximum number of tuple fields we want to support.
$$ This meta comment fixes auto-indentation in Emacs. }}
// Copyright 2009 Google Inc.
// All Rights Reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Implements a subset of TR1 tuple needed by Google Test and Google Mock.
// GOOGLETEST_CM0001 DO NOT DELETE
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
#include <utility> // For ::std::pair.
// The compiler used in Symbian has a bug that prevents us from declaring the
// tuple template as a friend (it complains that tuple is redefined). This
// bypasses the bug by declaring the members that should otherwise be
// private as public.
// Sun Studio versions < 12 also have the above bug.
#if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590)
# define GTEST_DECLARE_TUPLE_AS_FRIEND_ public:
#else
# define GTEST_DECLARE_TUPLE_AS_FRIEND_ \
template <GTEST_$(n)_TYPENAMES_(U)> friend class tuple; \
private:
#endif
// Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that conflict
// with our own definitions. Therefore using our own tuple does not work on
// those compilers.
#if defined(_MSC_VER) && _MSC_VER >= 1600 /* 1600 is Visual Studio 2010 */
# error "gtest's tuple doesn't compile on Visual Studio 2010 or later. \
GTEST_USE_OWN_TR1_TUPLE must be set to 0 on those compilers."
#endif
$range i 0..n-1
$range j 0..n
$range k 1..n
// GTEST_n_TUPLE_(T) is the type of an n-tuple.
#define GTEST_0_TUPLE_(T) tuple<>
$for k [[
$range m 0..k-1
$range m2 k..n-1
#define GTEST_$(k)_TUPLE_(T) tuple<$for m, [[T##$m]]$for m2 [[, void]]>
]]
// GTEST_n_TYPENAMES_(T) declares a list of n typenames.
$for j [[
$range m 0..j-1
#define GTEST_$(j)_TYPENAMES_(T) $for m, [[typename T##$m]]
]]
// In theory, defining stuff in the ::std namespace is undefined
// behavior. We can do this as we are playing the role of a standard
// library vendor.
namespace std {
namespace tr1 {
template <$for i, [[typename T$i = void]]>
class tuple;
// Anything in namespace gtest_internal is Google Test's INTERNAL
// IMPLEMENTATION DETAIL and MUST NOT BE USED DIRECTLY in user code.
namespace gtest_internal {
// ByRef<T>::type is T if T is a reference; otherwise it's const T&.
template <typename T>
struct ByRef { typedef const T& type; }; // NOLINT
template <typename T>
struct ByRef<T&> { typedef T& type; }; // NOLINT
// A handy wrapper for ByRef.
#define GTEST_BY_REF_(T) typename ::std::tr1::gtest_internal::ByRef<T>::type
// AddRef<T>::type is T if T is a reference; otherwise it's T&. This
// is the same as tr1::add_reference<T>::type.
template <typename T>
struct AddRef { typedef T& type; }; // NOLINT
template <typename T>
struct AddRef<T&> { typedef T& type; }; // NOLINT
// A handy wrapper for AddRef.
#define GTEST_ADD_REF_(T) typename ::std::tr1::gtest_internal::AddRef<T>::type
// A helper for implementing get<k>().
template <int k> class Get;
// A helper for implementing tuple_element<k, T>. kIndexValid is true
// iff k < the number of fields in tuple type T.
template <bool kIndexValid, int kIndex, class Tuple>
struct TupleElement;
$for i [[
template <GTEST_$(n)_TYPENAMES_(T)>
struct TupleElement<true, $i, GTEST_$(n)_TUPLE_(T) > {
typedef T$i type;
};
]]
} // namespace gtest_internal
template <>
class tuple<> {
public:
tuple() {}
tuple(const tuple& /* t */) {}
tuple& operator=(const tuple& /* t */) { return *this; }
};
$for k [[
$range m 0..k-1
template <GTEST_$(k)_TYPENAMES_(T)>
class $if k < n [[GTEST_$(k)_TUPLE_(T)]] $else [[tuple]] {
public:
template <int k> friend class gtest_internal::Get;
tuple() : $for m, [[f$(m)_()]] {}
explicit tuple($for m, [[GTEST_BY_REF_(T$m) f$m]]) : [[]]
$for m, [[f$(m)_(f$m)]] {}
tuple(const tuple& t) : $for m, [[f$(m)_(t.f$(m)_)]] {}
template <GTEST_$(k)_TYPENAMES_(U)>
tuple(const GTEST_$(k)_TUPLE_(U)& t) : $for m, [[f$(m)_(t.f$(m)_)]] {}
$if k == 2 [[
template <typename U0, typename U1>
tuple(const ::std::pair<U0, U1>& p) : f0_(p.first), f1_(p.second) {}
]]
tuple& operator=(const tuple& t) { return CopyFrom(t); }
template <GTEST_$(k)_TYPENAMES_(U)>
tuple& operator=(const GTEST_$(k)_TUPLE_(U)& t) {
return CopyFrom(t);
}
$if k == 2 [[
template <typename U0, typename U1>
tuple& operator=(const ::std::pair<U0, U1>& p) {
f0_ = p.first;
f1_ = p.second;
return *this;
}
]]
GTEST_DECLARE_TUPLE_AS_FRIEND_
template <GTEST_$(k)_TYPENAMES_(U)>
tuple& CopyFrom(const GTEST_$(k)_TUPLE_(U)& t) {
$for m [[
f$(m)_ = t.f$(m)_;
]]
return *this;
}
$for m [[
T$m f$(m)_;
]]
};
]]
// 6.1.3.2 Tuple creation functions.
// Known limitations: we don't support passing an
// std::tr1::reference_wrapper<T> to make_tuple(). And we don't
// implement tie().
inline tuple<> make_tuple() { return tuple<>(); }
$for k [[
$range m 0..k-1
template <GTEST_$(k)_TYPENAMES_(T)>
inline GTEST_$(k)_TUPLE_(T) make_tuple($for m, [[const T$m& f$m]]) {
return GTEST_$(k)_TUPLE_(T)($for m, [[f$m]]);
}
]]
// 6.1.3.3 Tuple helper classes.
template <typename Tuple> struct tuple_size;
$for j [[
template <GTEST_$(j)_TYPENAMES_(T)>
struct tuple_size<GTEST_$(j)_TUPLE_(T) > {
static const int value = $j;
};
]]
template <int k, class Tuple>
struct tuple_element {
typedef typename gtest_internal::TupleElement<
k < (tuple_size<Tuple>::value), k, Tuple>::type type;
};
#define GTEST_TUPLE_ELEMENT_(k, Tuple) typename tuple_element<k, Tuple >::type
// 6.1.3.4 Element access.
namespace gtest_internal {
$for i [[
template <>
class Get<$i> {
public:
template <class Tuple>
static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_($i, Tuple))
Field(Tuple& t) { return t.f$(i)_; } // NOLINT
template <class Tuple>
static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_($i, Tuple))
ConstField(const Tuple& t) { return t.f$(i)_; }
};
]]
} // namespace gtest_internal
template <int k, GTEST_$(n)_TYPENAMES_(T)>
GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_$(n)_TUPLE_(T)))
get(GTEST_$(n)_TUPLE_(T)& t) {
return gtest_internal::Get<k>::Field(t);
}
template <int k, GTEST_$(n)_TYPENAMES_(T)>
GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_$(n)_TUPLE_(T)))
get(const GTEST_$(n)_TUPLE_(T)& t) {
return gtest_internal::Get<k>::ConstField(t);
}
// 6.1.3.5 Relational operators
// We only implement == and !=, as we don't have a need for the rest yet.
namespace gtest_internal {
// SameSizeTuplePrefixComparator<k, k>::Eq(t1, t2) returns true if the
// first k fields of t1 equals the first k fields of t2.
// SameSizeTuplePrefixComparator(k1, k2) would be a compiler error if
// k1 != k2.
template <int kSize1, int kSize2>
struct SameSizeTuplePrefixComparator;
template <>
struct SameSizeTuplePrefixComparator<0, 0> {
template <class Tuple1, class Tuple2>
static bool Eq(const Tuple1& /* t1 */, const Tuple2& /* t2 */) {
return true;
}
};
template <int k>
struct SameSizeTuplePrefixComparator<k, k> {
template <class Tuple1, class Tuple2>
static bool Eq(const Tuple1& t1, const Tuple2& t2) {
return SameSizeTuplePrefixComparator<k - 1, k - 1>::Eq(t1, t2) &&
::std::tr1::get<k - 1>(t1) == ::std::tr1::get<k - 1>(t2);
}
};
} // namespace gtest_internal
template <GTEST_$(n)_TYPENAMES_(T), GTEST_$(n)_TYPENAMES_(U)>
inline bool operator==(const GTEST_$(n)_TUPLE_(T)& t,
const GTEST_$(n)_TUPLE_(U)& u) {
return gtest_internal::SameSizeTuplePrefixComparator<
tuple_size<GTEST_$(n)_TUPLE_(T) >::value,
tuple_size<GTEST_$(n)_TUPLE_(U) >::value>::Eq(t, u);
}
template <GTEST_$(n)_TYPENAMES_(T), GTEST_$(n)_TYPENAMES_(U)>
inline bool operator!=(const GTEST_$(n)_TUPLE_(T)& t,
const GTEST_$(n)_TUPLE_(U)& u) { return !(t == u); }
// 6.1.4 Pairs.
// Unimplemented.
} // namespace tr1
} // namespace std
$for j [[
#undef GTEST_$(j)_TUPLE_
]]
$for j [[
#undef GTEST_$(j)_TYPENAMES_
]]
#undef GTEST_DECLARE_TUPLE_AS_FRIEND_
#undef GTEST_BY_REF_
#undef GTEST_ADD_REF_
#undef GTEST_TUPLE_ELEMENT_
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace { namespace {
#if GTEST_HAS_COMBINE
// Suppose we want to introduce a new, improved implementation of PrimeTable // Suppose we want to introduce a new, improved implementation of PrimeTable
// which combines speed of PrecalcPrimeTable and versatility of // which combines speed of PrecalcPrimeTable and versatility of
...@@ -90,19 +89,12 @@ using ::testing::Combine; ...@@ -90,19 +89,12 @@ using ::testing::Combine;
// PreCalculatedPrimeTable disabled. We do this by defining fixture which will // PreCalculatedPrimeTable disabled. We do this by defining fixture which will
// accept different combinations of parameters for instantiating a // accept different combinations of parameters for instantiating a
// HybridPrimeTable instance. // HybridPrimeTable instance.
class PrimeTableTest : public TestWithParam< ::testing::tuple<bool, int> > { class PrimeTableTest : public TestWithParam< ::std::tuple<bool, int> > {
protected: protected:
virtual void SetUp() { virtual void SetUp() {
// This can be written as bool force_on_the_fly;
// int max_precalculated;
// bool force_on_the_fly; std::tie(force_on_the_fly, max_precalculated) = GetParam();
// int max_precalculated;
// tie(force_on_the_fly, max_precalculated) = GetParam();
//
// once the Google C++ Style Guide allows use of ::std::tr1::tie.
//
bool force_on_the_fly = ::testing::get<0>(GetParam());
int max_precalculated = ::testing::get<1>(GetParam());
table_ = new HybridPrimeTable(force_on_the_fly, max_precalculated); table_ = new HybridPrimeTable(force_on_the_fly, max_precalculated);
} }
virtual void TearDown() { virtual void TearDown() {
...@@ -160,15 +152,4 @@ INSTANTIATE_TEST_CASE_P(MeaningfulTestParameters, ...@@ -160,15 +152,4 @@ INSTANTIATE_TEST_CASE_P(MeaningfulTestParameters,
PrimeTableTest, PrimeTableTest,
Combine(Bool(), Values(1, 10))); Combine(Bool(), Values(1, 10)));
#else
// Google Test may not support Combine() with some compilers. If we
// use conditional compilation to compile out all code referring to
// the gtest_main library, MSVC linker will not link that library at
// all and consequently complain about missing entry point defined in
// that library (fatal error LNK1561: entry point must be
// defined). This dummy test keeps gtest_main linked in.
TEST(DummyTest, CombineIsNotSupportedOnThisPlatform) {}
#endif // GTEST_HAS_COMBINE
} // namespace } // namespace
...@@ -49,19 +49,13 @@ using ::std::sort; ...@@ -49,19 +49,13 @@ using ::std::sort;
using ::testing::AddGlobalTestEnvironment; using ::testing::AddGlobalTestEnvironment;
using ::testing::Bool; using ::testing::Bool;
using ::testing::Combine;
using ::testing::Message; using ::testing::Message;
using ::testing::Range; using ::testing::Range;
using ::testing::TestWithParam; using ::testing::TestWithParam;
using ::testing::Values; using ::testing::Values;
using ::testing::ValuesIn; using ::testing::ValuesIn;
# if GTEST_HAS_COMBINE
using ::testing::Combine;
using ::testing::get;
using ::testing::make_tuple;
using ::testing::tuple;
# endif // GTEST_HAS_COMBINE
using ::testing::internal::ParamGenerator; using ::testing::internal::ParamGenerator;
using ::testing::internal::UnitTestOptions; using ::testing::internal::UnitTestOptions;
...@@ -78,8 +72,6 @@ template <typename T> ...@@ -78,8 +72,6 @@ template <typename T>
return stream.str(); return stream.str();
} }
# if GTEST_HAS_COMBINE
// These overloads allow printing tuples in our tests. We cannot // These overloads allow printing tuples in our tests. We cannot
// define an operator<< for tuples, as that definition needs to be in // define an operator<< for tuples, as that definition needs to be in
// the std namespace in order to be picked up by Google Test via // the std namespace in order to be picked up by Google Test via
...@@ -87,35 +79,33 @@ template <typename T> ...@@ -87,35 +79,33 @@ template <typename T>
// namespace in non-STL code is undefined behavior. // namespace in non-STL code is undefined behavior.
template <typename T1, typename T2> template <typename T1, typename T2>
::std::string PrintValue(const tuple<T1, T2>& value) { ::std::string PrintValue(const std::tuple<T1, T2>& value) {
::std::stringstream stream; ::std::stringstream stream;
stream << "(" << get<0>(value) << ", " << get<1>(value) << ")"; stream << "(" << std::get<0>(value) << ", " << std::get<1>(value) << ")";
return stream.str(); return stream.str();
} }
template <typename T1, typename T2, typename T3> template <typename T1, typename T2, typename T3>
::std::string PrintValue(const tuple<T1, T2, T3>& value) { ::std::string PrintValue(const std::tuple<T1, T2, T3>& value) {
::std::stringstream stream; ::std::stringstream stream;
stream << "(" << get<0>(value) << ", " << get<1>(value) stream << "(" << std::get<0>(value) << ", " << std::get<1>(value) << ", "
<< ", "<< get<2>(value) << ")"; << std::get<2>(value) << ")";
return stream.str(); return stream.str();
} }
template <typename T1, typename T2, typename T3, typename T4, typename T5, template <typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10> typename T6, typename T7, typename T8, typename T9, typename T10>
::std::string PrintValue( ::std::string PrintValue(
const tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>& value) { const std::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>& value) {
::std::stringstream stream; ::std::stringstream stream;
stream << "(" << get<0>(value) << ", " << get<1>(value) stream << "(" << std::get<0>(value) << ", " << std::get<1>(value) << ", "
<< ", "<< get<2>(value) << ", " << get<3>(value) << std::get<2>(value) << ", " << std::get<3>(value) << ", "
<< ", "<< get<4>(value) << ", " << get<5>(value) << std::get<4>(value) << ", " << std::get<5>(value) << ", "
<< ", "<< get<6>(value) << ", " << get<7>(value) << std::get<6>(value) << ", " << std::get<7>(value) << ", "
<< ", "<< get<8>(value) << ", " << get<9>(value) << ")"; << std::get<8>(value) << ", " << std::get<9>(value) << ")";
return stream.str(); return stream.str();
} }
# endif // GTEST_HAS_COMBINE
// Verifies that a sequence generated by the generator and accessed // Verifies that a sequence generated by the generator and accessed
// via the iterator object matches the expected one using Google Test // via the iterator object matches the expected one using Google Test
// assertions. // assertions.
...@@ -450,31 +440,28 @@ TEST(BoolTest, BoolWorks) { ...@@ -450,31 +440,28 @@ TEST(BoolTest, BoolWorks) {
VerifyGenerator(gen, expected_values); VerifyGenerator(gen, expected_values);
} }
# if GTEST_HAS_COMBINE
// Tests that Combine() with two parameters generates the expected sequence. // Tests that Combine() with two parameters generates the expected sequence.
TEST(CombineTest, CombineWithTwoParameters) { TEST(CombineTest, CombineWithTwoParameters) {
const char* foo = "foo"; const char* foo = "foo";
const char* bar = "bar"; const char* bar = "bar";
const ParamGenerator<tuple<const char*, int> > gen = const ParamGenerator<std::tuple<const char*, int> > gen =
Combine(Values(foo, bar), Values(3, 4)); Combine(Values(foo, bar), Values(3, 4));
tuple<const char*, int> expected_values[] = { std::tuple<const char*, int> expected_values[] = {
make_tuple(foo, 3), make_tuple(foo, 4), std::make_tuple(foo, 3), std::make_tuple(foo, 4), std::make_tuple(bar, 3),
make_tuple(bar, 3), make_tuple(bar, 4)}; std::make_tuple(bar, 4)};
VerifyGenerator(gen, expected_values); VerifyGenerator(gen, expected_values);
} }
// Tests that Combine() with three parameters generates the expected sequence. // Tests that Combine() with three parameters generates the expected sequence.
TEST(CombineTest, CombineWithThreeParameters) { TEST(CombineTest, CombineWithThreeParameters) {
const ParamGenerator<tuple<int, int, int> > gen = Combine(Values(0, 1), const ParamGenerator<std::tuple<int, int, int> > gen =
Values(3, 4), Combine(Values(0, 1), Values(3, 4), Values(5, 6));
Values(5, 6)); std::tuple<int, int, int> expected_values[] = {
tuple<int, int, int> expected_values[] = { std::make_tuple(0, 3, 5), std::make_tuple(0, 3, 6),
make_tuple(0, 3, 5), make_tuple(0, 3, 6), std::make_tuple(0, 4, 5), std::make_tuple(0, 4, 6),
make_tuple(0, 4, 5), make_tuple(0, 4, 6), std::make_tuple(1, 3, 5), std::make_tuple(1, 3, 6),
make_tuple(1, 3, 5), make_tuple(1, 3, 6), std::make_tuple(1, 4, 5), std::make_tuple(1, 4, 6)};
make_tuple(1, 4, 5), make_tuple(1, 4, 6)};
VerifyGenerator(gen, expected_values); VerifyGenerator(gen, expected_values);
} }
...@@ -482,10 +469,11 @@ TEST(CombineTest, CombineWithThreeParameters) { ...@@ -482,10 +469,11 @@ TEST(CombineTest, CombineWithThreeParameters) {
// sequence generates a sequence with the number of elements equal to the // sequence generates a sequence with the number of elements equal to the
// number of elements in the sequence generated by the second parameter. // number of elements in the sequence generated by the second parameter.
TEST(CombineTest, CombineWithFirstParameterSingleValue) { TEST(CombineTest, CombineWithFirstParameterSingleValue) {
const ParamGenerator<tuple<int, int> > gen = Combine(Values(42), const ParamGenerator<std::tuple<int, int> > gen =
Values(0, 1)); Combine(Values(42), Values(0, 1));
tuple<int, int> expected_values[] = {make_tuple(42, 0), make_tuple(42, 1)}; std::tuple<int, int> expected_values[] = {std::make_tuple(42, 0),
std::make_tuple(42, 1)};
VerifyGenerator(gen, expected_values); VerifyGenerator(gen, expected_values);
} }
...@@ -493,26 +481,27 @@ TEST(CombineTest, CombineWithFirstParameterSingleValue) { ...@@ -493,26 +481,27 @@ TEST(CombineTest, CombineWithFirstParameterSingleValue) {
// sequence generates a sequence with the number of elements equal to the // sequence generates a sequence with the number of elements equal to the
// number of elements in the sequence generated by the first parameter. // number of elements in the sequence generated by the first parameter.
TEST(CombineTest, CombineWithSecondParameterSingleValue) { TEST(CombineTest, CombineWithSecondParameterSingleValue) {
const ParamGenerator<tuple<int, int> > gen = Combine(Values(0, 1), const ParamGenerator<std::tuple<int, int> > gen =
Values(42)); Combine(Values(0, 1), Values(42));
tuple<int, int> expected_values[] = {make_tuple(0, 42), make_tuple(1, 42)}; std::tuple<int, int> expected_values[] = {std::make_tuple(0, 42),
std::make_tuple(1, 42)};
VerifyGenerator(gen, expected_values); VerifyGenerator(gen, expected_values);
} }
// Tests that when the first parameter produces an empty sequence, // Tests that when the first parameter produces an empty sequence,
// Combine() produces an empty sequence, too. // Combine() produces an empty sequence, too.
TEST(CombineTest, CombineWithFirstParameterEmptyRange) { TEST(CombineTest, CombineWithFirstParameterEmptyRange) {
const ParamGenerator<tuple<int, int> > gen = Combine(Range(0, 0), const ParamGenerator<std::tuple<int, int> > gen =
Values(0, 1)); Combine(Range(0, 0), Values(0, 1));
VerifyGeneratorIsEmpty(gen); VerifyGeneratorIsEmpty(gen);
} }
// Tests that when the second parameter produces an empty sequence, // Tests that when the second parameter produces an empty sequence,
// Combine() produces an empty sequence, too. // Combine() produces an empty sequence, too.
TEST(CombineTest, CombineWithSecondParameterEmptyRange) { TEST(CombineTest, CombineWithSecondParameterEmptyRange) {
const ParamGenerator<tuple<int, int> > gen = Combine(Values(0, 1), const ParamGenerator<std::tuple<int, int> > gen =
Range(1, 1)); Combine(Values(0, 1), Range(1, 1));
VerifyGeneratorIsEmpty(gen); VerifyGeneratorIsEmpty(gen);
} }
...@@ -521,17 +510,15 @@ TEST(CombineTest, CombineWithSecondParameterEmptyRange) { ...@@ -521,17 +510,15 @@ TEST(CombineTest, CombineWithSecondParameterEmptyRange) {
TEST(CombineTest, CombineWithMaxNumberOfParameters) { TEST(CombineTest, CombineWithMaxNumberOfParameters) {
const char* foo = "foo"; const char* foo = "foo";
const char* bar = "bar"; const char* bar = "bar";
const ParamGenerator<tuple<const char*, int, int, int, int, int, int, int, const ParamGenerator<
int, int> > gen = Combine(Values(foo, bar), std::tuple<const char*, int, int, int, int, int, int, int, int, int> >
Values(1), Values(2), gen =
Values(3), Values(4), Combine(Values(foo, bar), Values(1), Values(2), Values(3), Values(4),
Values(5), Values(6), Values(5), Values(6), Values(7), Values(8), Values(9));
Values(7), Values(8),
Values(9)); std::tuple<const char*, int, int, int, int, int, int, int, int, int>
expected_values[] = {std::make_tuple(foo, 1, 2, 3, 4, 5, 6, 7, 8, 9),
tuple<const char*, int, int, int, int, int, int, int, int, int> std::make_tuple(bar, 1, 2, 3, 4, 5, 6, 7, 8, 9)};
expected_values[] = {make_tuple(foo, 1, 2, 3, 4, 5, 6, 7, 8, 9),
make_tuple(bar, 1, 2, 3, 4, 5, 6, 7, 8, 9)};
VerifyGenerator(gen, expected_values); VerifyGenerator(gen, expected_values);
} }
...@@ -551,12 +538,12 @@ class NonDefaultConstructAssignString { ...@@ -551,12 +538,12 @@ class NonDefaultConstructAssignString {
}; };
TEST(CombineTest, NonDefaultConstructAssign) { TEST(CombineTest, NonDefaultConstructAssign) {
const ParamGenerator<tuple<int, NonDefaultConstructAssignString> > gen = const ParamGenerator<std::tuple<int, NonDefaultConstructAssignString> > gen =
Combine(Values(0, 1), Values(NonDefaultConstructAssignString("A"), Combine(Values(0, 1), Values(NonDefaultConstructAssignString("A"),
NonDefaultConstructAssignString("B"))); NonDefaultConstructAssignString("B")));
ParamGenerator<tuple<int, NonDefaultConstructAssignString> >::iterator it = ParamGenerator<std::tuple<int, NonDefaultConstructAssignString> >::iterator
gen.begin(); it = gen.begin();
EXPECT_EQ(0, std::get<0>(*it)); EXPECT_EQ(0, std::get<0>(*it));
EXPECT_EQ("A", std::get<1>(*it).str()); EXPECT_EQ("A", std::get<1>(*it).str());
...@@ -577,7 +564,6 @@ TEST(CombineTest, NonDefaultConstructAssign) { ...@@ -577,7 +564,6 @@ TEST(CombineTest, NonDefaultConstructAssign) {
EXPECT_TRUE(it == gen.end()); EXPECT_TRUE(it == gen.end());
} }
# endif // GTEST_HAS_COMBINE
// Tests that an generator produces correct sequence after being // Tests that an generator produces correct sequence after being
// assigned from another generator. // assigned from another generator.
......
...@@ -228,9 +228,7 @@ using ::testing::internal::Strings; ...@@ -228,9 +228,7 @@ using ::testing::internal::Strings;
using ::testing::internal::UniversalPrint; using ::testing::internal::UniversalPrint;
using ::testing::internal::UniversalPrinter; using ::testing::internal::UniversalPrinter;
using ::testing::internal::UniversalTersePrint; using ::testing::internal::UniversalTersePrint;
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
using ::testing::internal::UniversalTersePrintTupleFieldsToStrings; using ::testing::internal::UniversalTersePrintTupleFieldsToStrings;
#endif
// Prints a value to a string using the universal value printer. This // Prints a value to a string using the universal value printer. This
// is a helper for testing UniversalPrinter<T>::Print() for various types. // is a helper for testing UniversalPrinter<T>::Print() for various types.
...@@ -991,67 +989,6 @@ TEST(PrintStlContainerTest, ConstIterator) { ...@@ -991,67 +989,6 @@ TEST(PrintStlContainerTest, ConstIterator) {
EXPECT_EQ("1-byte object <00>", Print(it)); EXPECT_EQ("1-byte object <00>", Print(it));
} }
#if GTEST_HAS_TR1_TUPLE
// Tests printing ::std::tr1::tuples.
// Tuples of various arities.
TEST(PrintTr1TupleTest, VariousSizes) {
::std::tr1::tuple<> t0;
EXPECT_EQ("()", Print(t0));
::std::tr1::tuple<int> t1(5);
EXPECT_EQ("(5)", Print(t1));
::std::tr1::tuple<char, bool> t2('a', true);
EXPECT_EQ("('a' (97, 0x61), true)", Print(t2));
::std::tr1::tuple<bool, int, int> t3(false, 2, 3);
EXPECT_EQ("(false, 2, 3)", Print(t3));
::std::tr1::tuple<bool, int, int, int> t4(false, 2, 3, 4);
EXPECT_EQ("(false, 2, 3, 4)", Print(t4));
::std::tr1::tuple<bool, int, int, int, bool> t5(false, 2, 3, 4, true);
EXPECT_EQ("(false, 2, 3, 4, true)", Print(t5));
::std::tr1::tuple<bool, int, int, int, bool, int> t6(false, 2, 3, 4, true, 6);
EXPECT_EQ("(false, 2, 3, 4, true, 6)", Print(t6));
::std::tr1::tuple<bool, int, int, int, bool, int, int> t7(
false, 2, 3, 4, true, 6, 7);
EXPECT_EQ("(false, 2, 3, 4, true, 6, 7)", Print(t7));
::std::tr1::tuple<bool, int, int, int, bool, int, int, bool> t8(
false, 2, 3, 4, true, 6, 7, true);
EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true)", Print(t8));
::std::tr1::tuple<bool, int, int, int, bool, int, int, bool, int> t9(
false, 2, 3, 4, true, 6, 7, true, 9);
EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true, 9)", Print(t9));
const char* const str = "8";
// VC++ 2010's implementation of tuple of C++0x is deficient, requiring
// an explicit type cast of NULL to be used.
::std::tr1::tuple<bool, char, short, testing::internal::Int32, // NOLINT
testing::internal::Int64, float, double, const char*, void*,
std::string>
t10(false, 'a', static_cast<short>(3), 4, 5, 1.5F, -2.5, str, // NOLINT
ImplicitCast_<void*>(NULL), "10");
EXPECT_EQ("(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, " + PrintPointer(str) +
" pointing to \"8\", NULL, \"10\")",
Print(t10));
}
// Nested tuples.
TEST(PrintTr1TupleTest, NestedTuple) {
::std::tr1::tuple< ::std::tr1::tuple<int, bool>, char> nested(
::std::tr1::make_tuple(5, true), 'a');
EXPECT_EQ("((5, true), 'a' (97, 0x61))", Print(nested));
}
#endif // GTEST_HAS_TR1_TUPLE
#if GTEST_HAS_STD_TUPLE_
// Tests printing ::std::tuples. // Tests printing ::std::tuples.
// Tuples of various arities. // Tuples of various arities.
...@@ -1071,32 +1008,12 @@ TEST(PrintStdTupleTest, VariousSizes) { ...@@ -1071,32 +1008,12 @@ TEST(PrintStdTupleTest, VariousSizes) {
::std::tuple<bool, int, int, int> t4(false, 2, 3, 4); ::std::tuple<bool, int, int, int> t4(false, 2, 3, 4);
EXPECT_EQ("(false, 2, 3, 4)", Print(t4)); EXPECT_EQ("(false, 2, 3, 4)", Print(t4));
::std::tuple<bool, int, int, int, bool> t5(false, 2, 3, 4, true);
EXPECT_EQ("(false, 2, 3, 4, true)", Print(t5));
::std::tuple<bool, int, int, int, bool, int> t6(false, 2, 3, 4, true, 6);
EXPECT_EQ("(false, 2, 3, 4, true, 6)", Print(t6));
::std::tuple<bool, int, int, int, bool, int, int> t7(
false, 2, 3, 4, true, 6, 7);
EXPECT_EQ("(false, 2, 3, 4, true, 6, 7)", Print(t7));
::std::tuple<bool, int, int, int, bool, int, int, bool> t8(
false, 2, 3, 4, true, 6, 7, true);
EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true)", Print(t8));
::std::tuple<bool, int, int, int, bool, int, int, bool, int> t9(
false, 2, 3, 4, true, 6, 7, true, 9);
EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true, 9)", Print(t9));
const char* const str = "8"; const char* const str = "8";
// VC++ 2010's implementation of tuple of C++0x is deficient, requiring
// an explicit type cast of NULL to be used.
::std::tuple<bool, char, short, testing::internal::Int32, // NOLINT ::std::tuple<bool, char, short, testing::internal::Int32, // NOLINT
testing::internal::Int64, float, double, const char*, void*, testing::internal::Int64, float, double, const char*, void*,
std::string> std::string>
t10(false, 'a', static_cast<short>(3), 4, 5, 1.5F, -2.5, str, // NOLINT t10(false, 'a', static_cast<short>(3), 4, 5, 1.5F, -2.5, str, // NOLINT
ImplicitCast_<void*>(NULL), "10"); nullptr, "10");
EXPECT_EQ("(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, " + PrintPointer(str) + EXPECT_EQ("(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, " + PrintPointer(str) +
" pointing to \"8\", NULL, \"10\")", " pointing to \"8\", NULL, \"10\")",
Print(t10)); Print(t10));
...@@ -1109,8 +1026,6 @@ TEST(PrintStdTupleTest, NestedTuple) { ...@@ -1109,8 +1026,6 @@ TEST(PrintStdTupleTest, NestedTuple) {
EXPECT_EQ("((5, true), 'a' (97, 0x61))", Print(nested)); EXPECT_EQ("((5, true), 'a' (97, 0x61))", Print(nested));
} }
#endif // GTEST_HAS_TR1_TUPLE
TEST(PrintNullptrT, Basic) { TEST(PrintNullptrT, Basic) {
EXPECT_EQ("(nullptr)", Print(nullptr)); EXPECT_EQ("(nullptr)", Print(nullptr));
} }
...@@ -1662,42 +1577,6 @@ TEST(UniversalPrintTest, WorksForCharArray) { ...@@ -1662,42 +1577,6 @@ TEST(UniversalPrintTest, WorksForCharArray) {
EXPECT_EQ("\"\\\"Line\\0 1\\\"\\nLine 2\"", ss2.str()); EXPECT_EQ("\"\\\"Line\\0 1\\\"\\nLine 2\"", ss2.str());
} }
#if GTEST_HAS_TR1_TUPLE
TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsEmptyTuple) {
Strings result = UniversalTersePrintTupleFieldsToStrings(
::std::tr1::make_tuple());
EXPECT_EQ(0u, result.size());
}
TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsOneTuple) {
Strings result = UniversalTersePrintTupleFieldsToStrings(
::std::tr1::make_tuple(1));
ASSERT_EQ(1u, result.size());
EXPECT_EQ("1", result[0]);
}
TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsTwoTuple) {
Strings result = UniversalTersePrintTupleFieldsToStrings(
::std::tr1::make_tuple(1, 'a'));
ASSERT_EQ(2u, result.size());
EXPECT_EQ("1", result[0]);
EXPECT_EQ("'a' (97, 0x61)", result[1]);
}
TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsTersely) {
const int n = 1;
Strings result = UniversalTersePrintTupleFieldsToStrings(
::std::tr1::tuple<const int&, const char*>(n, "a"));
ASSERT_EQ(2u, result.size());
EXPECT_EQ("1", result[0]);
EXPECT_EQ("\"a\"", result[1]);
}
#endif // GTEST_HAS_TR1_TUPLE
#if GTEST_HAS_STD_TUPLE_
TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) { TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) {
Strings result = UniversalTersePrintTupleFieldsToStrings(::std::make_tuple()); Strings result = UniversalTersePrintTupleFieldsToStrings(::std::make_tuple());
EXPECT_EQ(0u, result.size()); EXPECT_EQ(0u, result.size());
...@@ -1727,8 +1606,6 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) { ...@@ -1727,8 +1606,6 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
EXPECT_EQ("\"a\"", result[1]); EXPECT_EQ("\"a\"", result[1]);
} }
#endif // GTEST_HAS_STD_TUPLE_
#if GTEST_HAS_ABSL #if GTEST_HAS_ABSL
TEST(PrintOptionalTest, Basic) { TEST(PrintOptionalTest, Basic) {
......
// Copyright 2007, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "gtest/internal/gtest-tuple.h"
#include <utility>
#include "gtest/gtest.h"
namespace {
using ::std::tr1::get;
using ::std::tr1::make_tuple;
using ::std::tr1::tuple;
using ::std::tr1::tuple_element;
using ::std::tr1::tuple_size;
using ::testing::StaticAssertTypeEq;
// Tests that tuple_element<K, tuple<T0, T1, ..., TN> >::type returns TK.
TEST(tuple_element_Test, ReturnsElementType) {
StaticAssertTypeEq<int, tuple_element<0, tuple<int, char> >::type>();
StaticAssertTypeEq<int&, tuple_element<1, tuple<double, int&> >::type>();
StaticAssertTypeEq<bool, tuple_element<2, tuple<double, int, bool> >::type>();
}
// Tests that tuple_size<T>::value gives the number of fields in tuple
// type T.
TEST(tuple_size_Test, ReturnsNumberOfFields) {
EXPECT_EQ(0, +tuple_size<tuple<> >::value);
EXPECT_EQ(1, +tuple_size<tuple<void*> >::value);
EXPECT_EQ(1, +tuple_size<tuple<char> >::value);
EXPECT_EQ(1, +(tuple_size<tuple<tuple<int, double> > >::value));
EXPECT_EQ(2, +(tuple_size<tuple<int&, const char> >::value));
EXPECT_EQ(3, +(tuple_size<tuple<char*, void, const bool&> >::value));
}
// Tests comparing a tuple with itself.
TEST(ComparisonTest, ComparesWithSelf) {
const tuple<int, char, bool> a(5, 'a', false);
EXPECT_TRUE(a == a);
EXPECT_FALSE(a != a);
}
// Tests comparing two tuples with the same value.
TEST(ComparisonTest, ComparesEqualTuples) {
const tuple<int, bool> a(5, true), b(5, true);
EXPECT_TRUE(a == b);
EXPECT_FALSE(a != b);
}
// Tests comparing two different tuples that have no reference fields.
TEST(ComparisonTest, ComparesUnequalTuplesWithoutReferenceFields) {
typedef tuple<const int, char> FooTuple;
const FooTuple a(0, 'x');
const FooTuple b(1, 'a');
EXPECT_TRUE(a != b);
EXPECT_FALSE(a == b);
const FooTuple c(1, 'b');
EXPECT_TRUE(b != c);
EXPECT_FALSE(b == c);
}
// Tests comparing two different tuples that have reference fields.
TEST(ComparisonTest, ComparesUnequalTuplesWithReferenceFields) {
typedef tuple<int&, const char&> FooTuple;
int i = 5;
const char ch = 'a';
const FooTuple a(i, ch);
int j = 6;
const FooTuple b(j, ch);
EXPECT_TRUE(a != b);
EXPECT_FALSE(a == b);
j = 5;
const char ch2 = 'b';
const FooTuple c(j, ch2);
EXPECT_TRUE(b != c);
EXPECT_FALSE(b == c);
}
// Tests that a tuple field with a reference type is an alias of the
// variable it's supposed to reference.
TEST(ReferenceFieldTest, IsAliasOfReferencedVariable) {
int n = 0;
tuple<bool, int&> t(true, n);
n = 1;
EXPECT_EQ(n, get<1>(t))
<< "Changing a underlying variable should update the reference field.";
// Makes sure that the implementation doesn't do anything funny with
// the & operator for the return type of get<>().
EXPECT_EQ(&n, &(get<1>(t)))
<< "The address of a reference field should equal the address of "
<< "the underlying variable.";
get<1>(t) = 2;
EXPECT_EQ(2, n)
<< "Changing a reference field should update the underlying variable.";
}
// Tests that tuple's default constructor default initializes each field.
// This test needs to compile without generating warnings.
TEST(TupleConstructorTest, DefaultConstructorDefaultInitializesEachField) {
// The TR1 report requires that tuple's default constructor default
// initializes each field, even if it's a primitive type. If the
// implementation forgets to do this, this test will catch it by
// generating warnings about using uninitialized variables (assuming
// a decent compiler).
tuple<> empty;
tuple<int> a1, b1;
b1 = a1;
EXPECT_EQ(0, get<0>(b1));
tuple<int, double> a2, b2;
b2 = a2;
EXPECT_EQ(0, get<0>(b2));
EXPECT_EQ(0.0, get<1>(b2));
tuple<double, char, bool*> a3, b3;
b3 = a3;
EXPECT_EQ(0.0, get<0>(b3));
EXPECT_EQ('\0', get<1>(b3));
EXPECT_TRUE(get<2>(b3) == nullptr);
tuple<int, int, int, int, int, int, int, int, int, int> a10, b10;
b10 = a10;
EXPECT_EQ(0, get<0>(b10));
EXPECT_EQ(0, get<1>(b10));
EXPECT_EQ(0, get<2>(b10));
EXPECT_EQ(0, get<3>(b10));
EXPECT_EQ(0, get<4>(b10));
EXPECT_EQ(0, get<5>(b10));
EXPECT_EQ(0, get<6>(b10));
EXPECT_EQ(0, get<7>(b10));
EXPECT_EQ(0, get<8>(b10));
EXPECT_EQ(0, get<9>(b10));
}
// Tests constructing a tuple from its fields.
TEST(TupleConstructorTest, ConstructsFromFields) {
int n = 1;
// Reference field.
tuple<int&> a(n);
EXPECT_EQ(&n, &(get<0>(a)));
// Non-reference fields.
tuple<int, char> b(5, 'a');
EXPECT_EQ(5, get<0>(b));
EXPECT_EQ('a', get<1>(b));
// Const reference field.
const int m = 2;
tuple<bool, const int&> c(true, m);
EXPECT_TRUE(get<0>(c));
EXPECT_EQ(&m, &(get<1>(c)));
}
// Tests tuple's copy constructor.
TEST(TupleConstructorTest, CopyConstructor) {
tuple<double, bool> a(0.0, true);
tuple<double, bool> b(a);
EXPECT_DOUBLE_EQ(0.0, get<0>(b));
EXPECT_TRUE(get<1>(b));
}
// Tests constructing a tuple from another tuple that has a compatible
// but different type.
TEST(TupleConstructorTest, ConstructsFromDifferentTupleType) {
tuple<int, int, char> a(0, 1, 'a');
tuple<double, long, int> b(a);
EXPECT_DOUBLE_EQ(0.0, get<0>(b));
EXPECT_EQ(1, get<1>(b));
EXPECT_EQ('a', get<2>(b));
}
// Tests constructing a 2-tuple from an std::pair.
TEST(TupleConstructorTest, ConstructsFromPair) {
::std::pair<int, char> a(1, 'a');
tuple<int, char> b(a);
tuple<int, const char&> c(a);
}
// Tests assigning a tuple to another tuple with the same type.
TEST(TupleAssignmentTest, AssignsToSameTupleType) {
const tuple<int, long> a(5, 7L);
tuple<int, long> b;
b = a;
EXPECT_EQ(5, get<0>(b));
EXPECT_EQ(7L, get<1>(b));
}
// Tests assigning a tuple to another tuple with a different but
// compatible type.
TEST(TupleAssignmentTest, AssignsToDifferentTupleType) {
const tuple<int, long, bool> a(1, 7L, true);
tuple<long, int, bool> b;
b = a;
EXPECT_EQ(1L, get<0>(b));
EXPECT_EQ(7, get<1>(b));
EXPECT_TRUE(get<2>(b));
}
// Tests assigning an std::pair to a 2-tuple.
TEST(TupleAssignmentTest, AssignsFromPair) {
const ::std::pair<int, bool> a(5, true);
tuple<int, bool> b;
b = a;
EXPECT_EQ(5, get<0>(b));
EXPECT_TRUE(get<1>(b));
tuple<long, bool> c;
c = a;
EXPECT_EQ(5L, get<0>(c));
EXPECT_TRUE(get<1>(c));
}
// A fixture for testing big tuples.
class BigTupleTest : public testing::Test {
protected:
typedef tuple<int, int, int, int, int, int, int, int, int, int> BigTuple;
BigTupleTest() :
a_(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
b_(1, 0, 0, 0, 0, 0, 0, 0, 0, 3) {}
BigTuple a_, b_;
};
// Tests constructing big tuples.
TEST_F(BigTupleTest, Construction) {
BigTuple a;
BigTuple b(b_);
}
// Tests that get<N>(t) returns the N-th (0-based) field of tuple t.
TEST_F(BigTupleTest, get) {
EXPECT_EQ(1, get<0>(a_));
EXPECT_EQ(2, get<9>(a_));
// Tests that get() works on a const tuple too.
const BigTuple a(a_);
EXPECT_EQ(1, get<0>(a));
EXPECT_EQ(2, get<9>(a));
}
// Tests comparing big tuples.
TEST_F(BigTupleTest, Comparisons) {
EXPECT_TRUE(a_ == a_);
EXPECT_FALSE(a_ != a_);
EXPECT_TRUE(a_ != b_);
EXPECT_FALSE(a_ == b_);
}
TEST(MakeTupleTest, WorksForScalarTypes) {
tuple<bool, int> a;
a = make_tuple(true, 5);
EXPECT_TRUE(get<0>(a));
EXPECT_EQ(5, get<1>(a));
tuple<char, int, long> b;
b = make_tuple('a', 'b', 5);
EXPECT_EQ('a', get<0>(b));
EXPECT_EQ('b', get<1>(b));
EXPECT_EQ(5, get<2>(b));
}
TEST(MakeTupleTest, WorksForPointers) {
int a[] = { 1, 2, 3, 4 };
const char* const str = "hi";
int* const p = a;
tuple<const char*, int*> t;
t = make_tuple(str, p);
EXPECT_EQ(str, get<0>(t));
EXPECT_EQ(p, get<1>(t));
}
} // namespace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment