Skip to content

Commit

Permalink
adapt preprocessor defines for result_of/invoke_result
Browse files Browse the repository at this point in the history
  • Loading branch information
tnagler committed Jan 12, 2024
1 parent 91b9815 commit 76f9fd3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
13 changes: 12 additions & 1 deletion inst/include/Eigen/src/Core/util/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,25 @@
#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_MAX_CPP_VER>=11 && ((__has_feature(cxx_lambdas) || (defined(__cplusplus) && __cplusplus >= 201103L)))
#if EIGEN_HAS_CXX11 && EIGEN_CPLUSPLUS <= 201402L
#define EIGEN_HAS_STD_RESULT_OF 1
#else
#define EIGEN_HAS_STD_RESULT_OF 0
#endif
#endif

// Does the compiler support invoke_result?
// invoke_result was introduced in c++17
#ifndef EIGEN_HAS_STD_INVOKE_RESULT
#if EIGEN_COMP_CXXVER > 201402L
#define EIGEN_HAS_STD_INVOKE_RESULT 1
#else
#define EIGEN_HAS_STD_INVOKE_RESULT 0
#endif
#endif

// Does the compiler support type_traits?
// - full support of type traits was added only to GCC 5.1.0.
// - 20150626 corresponds to the last release of 4.x libstdc++
Expand Down
31 changes: 24 additions & 7 deletions inst/include/Eigen/src/Core/util/Meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,20 +309,37 @@ class noncopyable
};

/** \internal
* Convenient struct to get the result type of a unary or binary functor.
*
* It supports both the current STL mechanism (using the result_type member) as well as
* upcoming next STL generation (using a templated result member).
* If none of these members is provided, then the type of the first argument is returned. FIXME, that behavior is a pretty bad hack.
*/
#if EIGEN_HAS_STD_RESULT_OF
* 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:
* This uses std::result_of. However, note the `type` member removes
* const and converts references/pointers to their corresponding value type.
*/
#if EIGEN_HAS_STD_INVOKE_RESULT
template<typename T> struct result_of;

template<typename F, typename... ArgTypes>
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];};
Expand Down

0 comments on commit 76f9fd3

Please sign in to comment.