Fix tuple compilation for VS2017.

VS2017 doesn't like deducing alias types, leading to a bunch of compile
errors for functions involving the `tuple` alias.  Replacing with
`TupleImpl` seems to solve this, allowing the test to compile/pass.
This commit is contained in:
Antonio Sanchez 2021-09-29 20:34:03 -07:00 committed by Rasmus Munk Larsen
parent d0d34524a1
commit fd5f48e465
2 changed files with 14 additions and 14 deletions

View File

@ -217,12 +217,6 @@ struct unwrap_decay {
using type = typename unwrap_reference_wrapper<typename std::decay<T>::type>::type; using type = typename unwrap_reference_wrapper<typename std::decay<T>::type>::type;
}; };
/**
* Alternative to std::tuple that can be used on device.
*/
template<typename... Types>
using tuple = TupleImpl<sizeof...(Types), Types...>;
/** /**
* Utility for determining a tuple's size. * Utility for determining a tuple's size.
*/ */
@ -230,7 +224,7 @@ template<typename Tuple>
struct tuple_size; struct tuple_size;
template<typename... Types > template<typename... Types >
struct tuple_size< tuple<Types...> > : std::integral_constant<size_t, sizeof...(Types)> {}; struct tuple_size< TupleImpl<sizeof...(Types), Types...> > : std::integral_constant<size_t, sizeof...(Types)> {};
/** /**
* Gets an element of a tuple. * Gets an element of a tuple.
@ -242,14 +236,14 @@ struct tuple_size< tuple<Types...> > : std::integral_constant<size_t, sizeof...(
template<size_t Idx, typename... Types> template<size_t Idx, typename... Types>
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const typename tuple_get_impl<Idx, Types...>::ReturnType& const typename tuple_get_impl<Idx, Types...>::ReturnType&
get(const tuple<Types...>& tuple) { get(const TupleImpl<sizeof...(Types), Types...>& tuple) {
return tuple_get_impl<Idx, Types...>::run(tuple); return tuple_get_impl<Idx, Types...>::run(tuple);
} }
template<size_t Idx, typename... Types> template<size_t Idx, typename... Types>
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
typename tuple_get_impl<Idx, Types...>::ReturnType& typename tuple_get_impl<Idx, Types...>::ReturnType&
get(tuple<Types...>& tuple) { get(TupleImpl<sizeof...(Types), Types...>& tuple) {
return tuple_get_impl<Idx, Types...>::run(tuple); return tuple_get_impl<Idx, Types...>::run(tuple);
} }
@ -271,7 +265,7 @@ tuple_cat(Tuples&&... tuples) {
/** /**
* Tie arguments together into a tuple. * Tie arguments together into a tuple.
*/ */
template <typename... Args, typename ReturnType = tuple<Args&...> > template <typename... Args, typename ReturnType = TupleImpl<sizeof...(Args), Args&...> >
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
ReturnType tie(Args&... args) EIGEN_NOEXCEPT { ReturnType tie(Args&... args) EIGEN_NOEXCEPT {
return ReturnType{args...}; return ReturnType{args...};
@ -280,7 +274,7 @@ ReturnType tie(Args&... args) EIGEN_NOEXCEPT {
/** /**
* Create a tuple of l-values with the supplied arguments. * Create a tuple of l-values with the supplied arguments.
*/ */
template <typename... Args, typename ReturnType = tuple<typename unwrap_decay<Args>::type...> > template <typename... Args, typename ReturnType = TupleImpl<sizeof...(Args), typename unwrap_decay<Args>::type...> >
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
ReturnType make_tuple(Args&&... args) { ReturnType make_tuple(Args&&... args) {
return ReturnType{std::forward<Args>(args)...}; return ReturnType{std::forward<Args>(args)...};
@ -291,10 +285,16 @@ ReturnType make_tuple(Args&&... args) {
*/ */
template <typename... Args> template <typename... Args>
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
tuple<Args...> forward_as_tuple(Args&&... args) { TupleImpl<sizeof...(Args), Args...> forward_as_tuple(Args&&... args) {
return tuple<Args...>(std::forward<Args>(args)...); return TupleImpl<sizeof...(Args), Args...>(std::forward<Args>(args)...);
} }
/**
* Alternative to std::tuple that can be used on device.
*/
template<typename... Types>
using tuple = TupleImpl<sizeof...(Types), Types...>;
} // namespace tuple_impl } // namespace tuple_impl
} // namespace internal } // namespace internal
} // namespace Eigen } // namespace Eigen

View File

@ -99,7 +99,7 @@ void basic_tuple_test() {
VERIFY_IS_EQUAL(x, tuple_impl::get<0>(tuple3)); VERIFY_IS_EQUAL(x, tuple_impl::get<0>(tuple3));
VERIFY_IS_EQUAL(y, tuple_impl::get<1>(tuple3)); VERIFY_IS_EQUAL(y, tuple_impl::get<1>(tuple3));
VERIFY_IS_EQUAL(z, tuple_impl::get<2>(tuple3)); VERIFY_IS_EQUAL(z, tuple_impl::get<2>(tuple3));
tuple<int, float, double> tuple3c(-2, -2, -2); tuple<int, float, double> tuple3c(-2, -2.0f, -2.0);
tuple3c = std::move(tuple3b); tuple3c = std::move(tuple3b);
VERIFY_IS_EQUAL(tuple_impl::get<0>(tuple3c), tuple_impl::get<0>(tuple3)); VERIFY_IS_EQUAL(tuple_impl::get<0>(tuple3c), tuple_impl::get<0>(tuple3));
VERIFY_IS_EQUAL(tuple_impl::get<1>(tuple3c), tuple_impl::get<1>(tuple3)); VERIFY_IS_EQUAL(tuple_impl::get<1>(tuple3c), tuple_impl::get<1>(tuple3));