mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Cleanup
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
81c928ba55
commit
970640519b
@@ -165,8 +165,8 @@ struct tuple_cat_impl<NTuples, TupleImpl<N1, Args1...>, TupleImpl<N2, Args2...>,
|
||||
// then recursively calls again.
|
||||
template<typename Tuple1, size_t... I1s, typename Tuple2, size_t... I2s, typename... MoreTuples>
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
ReturnType run(Tuple1&& tuple1, index_sequence<I1s...>,
|
||||
Tuple2&& tuple2, index_sequence<I2s...>,
|
||||
ReturnType run(Tuple1&& tuple1, std::index_sequence<I1s...>,
|
||||
Tuple2&& tuple2, std::index_sequence<I2s...>,
|
||||
MoreTuples&&... tuples) {
|
||||
return tuple_cat_impl<NTuples-1, MergedTupleType, Tuples...>::run(
|
||||
MergedTupleType(tuple_get_impl<I1s, Args1...>::run(std::forward<Tuple1>(tuple1))...,
|
||||
@@ -178,8 +178,8 @@ struct tuple_cat_impl<NTuples, TupleImpl<N1, Args1...>, TupleImpl<N2, Args2...>,
|
||||
template<typename Tuple1, typename Tuple2, typename... MoreTuples>
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
ReturnType run(Tuple1&& tuple1, Tuple2&& tuple2, MoreTuples&&... tuples) {
|
||||
return run(std::forward<Tuple1>(tuple1), make_index_sequence<N1>{},
|
||||
std::forward<Tuple2>(tuple2), make_index_sequence<N2>{},
|
||||
return run(std::forward<Tuple1>(tuple1), std::make_index_sequence<N1>{},
|
||||
std::forward<Tuple2>(tuple2), std::make_index_sequence<N2>{},
|
||||
std::forward<MoreTuples>(tuples)...);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -681,16 +681,6 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Does the compiler support result_of?
|
||||
// result_of was deprecated in c++17 and removed in c++ 20
|
||||
#ifndef EIGEN_HAS_STD_RESULT_OF
|
||||
#if EIGEN_COMP_CXXVER < 17
|
||||
#define EIGEN_HAS_STD_RESULT_OF 1
|
||||
#else
|
||||
#define EIGEN_HAS_STD_RESULT_OF 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Does the compiler support std::hash?
|
||||
#ifndef EIGEN_HAS_STD_HASH
|
||||
// The std::hash struct is defined in C++11 but is not labelled as a __device__
|
||||
@@ -710,28 +700,7 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Does the compiler fully support const expressions? (as in c++14)
|
||||
#ifndef EIGEN_HAS_CONSTEXPR
|
||||
#if defined(EIGEN_CUDACC)
|
||||
// Const expressions are supported provided that c++11 is enabled and we're using either clang or nvcc 7.5 or above
|
||||
#if (EIGEN_COMP_CLANG || EIGEN_COMP_NVCC >= 70500)
|
||||
#define EIGEN_HAS_CONSTEXPR 1
|
||||
#endif
|
||||
#else
|
||||
#define EIGEN_HAS_CONSTEXPR 1
|
||||
#endif
|
||||
|
||||
#ifndef EIGEN_HAS_CONSTEXPR
|
||||
#define EIGEN_HAS_CONSTEXPR 0
|
||||
#endif
|
||||
|
||||
#endif // EIGEN_HAS_CONSTEXPR
|
||||
|
||||
#if EIGEN_HAS_CONSTEXPR
|
||||
#define EIGEN_CONSTEXPR constexpr
|
||||
#else
|
||||
#define EIGEN_CONSTEXPR
|
||||
#endif
|
||||
|
||||
// Does the compiler support C++11 math?
|
||||
// Let's be conservative and enable the default C++11 implementation only if we are sure it exists
|
||||
@@ -760,7 +729,7 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(EIGEN_CUDACC) && EIGEN_HAS_CONSTEXPR
|
||||
#if defined(EIGEN_CUDACC)
|
||||
// While available already with c++11, this is useful mostly starting with c++14 and relaxed constexpr rules
|
||||
#if defined(__NVCC__)
|
||||
// nvcc considers constexpr functions as __host__ __device__ with the option --expt-relaxed-constexpr
|
||||
|
||||
@@ -243,17 +243,12 @@ EIGEN_CONSTEXPR auto index_list_size(T&& x) {
|
||||
/** \internal
|
||||
* Convenient struct to get the result type of a nullary, unary, binary, or
|
||||
* ternary functor.
|
||||
*
|
||||
* Pre C++11:
|
||||
* Supports both a Func::result_type member and templated
|
||||
* Func::result<Func(ArgTypes...)>::type member.
|
||||
*
|
||||
* If none of these members is provided, then the type of the first
|
||||
* argument is returned.
|
||||
*
|
||||
* Post C++11:
|
||||
*
|
||||
* Pre C++17:
|
||||
* This uses std::result_of. However, note the `type` member removes
|
||||
* const and converts references/pointers to their corresponding value type.
|
||||
*
|
||||
* Post C++17: Uses std::invoke_result
|
||||
*/
|
||||
#if EIGEN_HAS_STD_INVOKE_RESULT
|
||||
template<typename T> struct result_of;
|
||||
@@ -263,179 +258,34 @@ struct result_of<F(ArgTypes...)> {
|
||||
typedef typename std::invoke_result<F, ArgTypes...>::type type1;
|
||||
typedef typename remove_all<type1>::type type;
|
||||
};
|
||||
#elif EIGEN_HAS_STD_RESULT_OF
|
||||
template<typename T> struct result_of {
|
||||
typedef typename std::result_of<T>::type type1;
|
||||
typedef typename remove_all<type1>::type type;
|
||||
};
|
||||
#else
|
||||
template<typename T> struct result_of { };
|
||||
|
||||
struct has_none {int a[1];};
|
||||
struct has_std_result_type {int a[2];};
|
||||
struct has_tr1_result {int a[3];};
|
||||
|
||||
template<typename Func, int SizeOf>
|
||||
struct nullary_result_of_select {};
|
||||
|
||||
template<typename Func>
|
||||
struct nullary_result_of_select<Func, sizeof(has_std_result_type)> {typedef typename Func::result_type type;};
|
||||
|
||||
template<typename Func>
|
||||
struct nullary_result_of_select<Func, sizeof(has_tr1_result)> {typedef typename Func::template result<Func()>::type type;};
|
||||
|
||||
template<typename Func>
|
||||
struct result_of<Func()> {
|
||||
template<typename T>
|
||||
static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0);
|
||||
template<typename T>
|
||||
static has_tr1_result testFunctor(T const *, typename T::template result<T()>::type const * = 0);
|
||||
static has_none testFunctor(...);
|
||||
|
||||
// note that the following indirection is needed for gcc-3.3
|
||||
enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))};
|
||||
typedef typename nullary_result_of_select<Func, FunctorType>::type type;
|
||||
};
|
||||
|
||||
template<typename Func, typename ArgType, int SizeOf=sizeof(has_none)>
|
||||
struct unary_result_of_select {typedef typename internal::remove_all<ArgType>::type type;};
|
||||
|
||||
template<typename Func, typename ArgType>
|
||||
struct unary_result_of_select<Func, ArgType, sizeof(has_std_result_type)> {typedef typename Func::result_type type;};
|
||||
|
||||
template<typename Func, typename ArgType>
|
||||
struct unary_result_of_select<Func, ArgType, sizeof(has_tr1_result)> {typedef typename Func::template result<Func(ArgType)>::type type;};
|
||||
|
||||
template<typename Func, typename ArgType>
|
||||
struct result_of<Func(ArgType)> {
|
||||
template<typename T>
|
||||
static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0);
|
||||
template<typename T>
|
||||
static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType)>::type const * = 0);
|
||||
static has_none testFunctor(...);
|
||||
|
||||
// note that the following indirection is needed for gcc-3.3
|
||||
enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))};
|
||||
typedef typename unary_result_of_select<Func, ArgType, FunctorType>::type type;
|
||||
};
|
||||
|
||||
template<typename Func, typename ArgType0, typename ArgType1, int SizeOf=sizeof(has_none)>
|
||||
struct binary_result_of_select {typedef typename internal::remove_all<ArgType0>::type type;};
|
||||
|
||||
template<typename Func, typename ArgType0, typename ArgType1>
|
||||
struct binary_result_of_select<Func, ArgType0, ArgType1, sizeof(has_std_result_type)>
|
||||
{typedef typename Func::result_type type;};
|
||||
|
||||
template<typename Func, typename ArgType0, typename ArgType1>
|
||||
struct binary_result_of_select<Func, ArgType0, ArgType1, sizeof(has_tr1_result)>
|
||||
{typedef typename Func::template result<Func(ArgType0,ArgType1)>::type type;};
|
||||
|
||||
template<typename Func, typename ArgType0, typename ArgType1>
|
||||
struct result_of<Func(ArgType0,ArgType1)> {
|
||||
template<typename T>
|
||||
static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0);
|
||||
template<typename T>
|
||||
static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType0,ArgType1)>::type const * = 0);
|
||||
static has_none testFunctor(...);
|
||||
|
||||
// note that the following indirection is needed for gcc-3.3
|
||||
enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))};
|
||||
typedef typename binary_result_of_select<Func, ArgType0, ArgType1, FunctorType>::type type;
|
||||
};
|
||||
|
||||
template<typename Func, typename ArgType0, typename ArgType1, typename ArgType2, int SizeOf=sizeof(has_none)>
|
||||
struct ternary_result_of_select {typedef typename internal::remove_all<ArgType0>::type type;};
|
||||
|
||||
template<typename Func, typename ArgType0, typename ArgType1, typename ArgType2>
|
||||
struct ternary_result_of_select<Func, ArgType0, ArgType1, ArgType2, sizeof(has_std_result_type)>
|
||||
{typedef typename Func::result_type type;};
|
||||
|
||||
template<typename Func, typename ArgType0, typename ArgType1, typename ArgType2>
|
||||
struct ternary_result_of_select<Func, ArgType0, ArgType1, ArgType2, sizeof(has_tr1_result)>
|
||||
{typedef typename Func::template result<Func(ArgType0,ArgType1,ArgType2)>::type type;};
|
||||
|
||||
template<typename Func, typename ArgType0, typename ArgType1, typename ArgType2>
|
||||
struct result_of<Func(ArgType0,ArgType1,ArgType2)> {
|
||||
template<typename T>
|
||||
static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0);
|
||||
template<typename T>
|
||||
static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType0,ArgType1,ArgType2)>::type const * = 0);
|
||||
static has_none testFunctor(...);
|
||||
|
||||
// note that the following indirection is needed for gcc-3.3
|
||||
enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))};
|
||||
typedef typename ternary_result_of_select<Func, ArgType0, ArgType1, ArgType2, FunctorType>::type type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if EIGEN_HAS_STD_INVOKE_RESULT
|
||||
template<typename F, typename... ArgTypes>
|
||||
struct invoke_result {
|
||||
typedef typename std::invoke_result<F, ArgTypes...>::type type1;
|
||||
typedef typename remove_all<type1>::type type;
|
||||
};
|
||||
#else
|
||||
template<typename F, typename... ArgTypes>
|
||||
struct invoke_result {
|
||||
typedef typename result_of<F(ArgTypes...)>::type type1;
|
||||
template<typename T> struct result_of {
|
||||
typedef typename std::result_of<T>::type type1;
|
||||
typedef typename remove_all<type1>::type type;
|
||||
};
|
||||
#endif
|
||||
|
||||
// C++14 integer/index_sequence.
|
||||
#if defined(__cpp_lib_integer_sequence) && __cpp_lib_integer_sequence >= 201304L
|
||||
|
||||
using std::integer_sequence;
|
||||
using std::make_integer_sequence;
|
||||
|
||||
using std::index_sequence;
|
||||
using std::make_index_sequence;
|
||||
|
||||
#else
|
||||
|
||||
template <typename T, T... Ints>
|
||||
struct integer_sequence {
|
||||
static EIGEN_CONSTEXPR size_t size() EIGEN_NOEXCEPT { return sizeof...(Ints); }
|
||||
template<typename F, typename... ArgTypes>
|
||||
struct invoke_result {
|
||||
typedef typename result_of<F(ArgTypes...)>::type type1;
|
||||
typedef typename remove_all<type1>::type type;
|
||||
};
|
||||
|
||||
template <typename T, typename Sequence, T N>
|
||||
struct append_integer;
|
||||
|
||||
template<typename T, T... Ints, T N>
|
||||
struct append_integer<T, integer_sequence<T, Ints...>, N> {
|
||||
using type = integer_sequence<T, Ints..., N>;
|
||||
};
|
||||
|
||||
template<typename T, size_t N>
|
||||
struct generate_integer_sequence {
|
||||
using type = typename append_integer<T, typename generate_integer_sequence<T, N-1>::type, N-1>::type;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct generate_integer_sequence<T, 0> {
|
||||
using type = integer_sequence<T>;
|
||||
};
|
||||
|
||||
template <typename T, size_t N>
|
||||
using make_integer_sequence = typename generate_integer_sequence<T, N>::type;
|
||||
|
||||
template<size_t... Ints>
|
||||
using index_sequence = integer_sequence<size_t, Ints...>;
|
||||
|
||||
template<size_t N>
|
||||
using make_index_sequence = make_integer_sequence<size_t, N>;
|
||||
|
||||
#endif
|
||||
|
||||
// Reduces a sequence of bools to true if all are true, false otherwise.
|
||||
template<bool... values>
|
||||
using reduce_all = std::is_same<integer_sequence<bool, values..., true>, integer_sequence<bool, true, values...> >;
|
||||
using reduce_all = std::is_same<std::integer_sequence<bool, values..., true>,
|
||||
std::integer_sequence<bool, true, values...> >;
|
||||
|
||||
// Reduces a sequence of bools to true if any are true, false if all false.
|
||||
template<bool... values>
|
||||
using reduce_any = std::integral_constant<bool,
|
||||
!std::is_same<integer_sequence<bool, values..., false>, integer_sequence<bool, false, values...> >::value>;
|
||||
!std::is_same<std::integer_sequence<bool, values..., false>, std::integer_sequence<bool, false, values...> >::value>;
|
||||
|
||||
struct meta_yes { char a[1]; };
|
||||
struct meta_no { char a[2]; };
|
||||
|
||||
Reference in New Issue
Block a user