From 76f9fd3e960516f6554120cdfa05d712fa4bfbec Mon Sep 17 00:00:00 2001 From: tnagler Date: Fri, 12 Jan 2024 13:44:50 +0100 Subject: [PATCH 1/2] adapt preprocessor defines for result_of/invoke_result --- inst/include/Eigen/src/Core/util/Macros.h | 13 +++++++++- inst/include/Eigen/src/Core/util/Meta.h | 31 ++++++++++++++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/inst/include/Eigen/src/Core/util/Macros.h b/inst/include/Eigen/src/Core/util/Macros.h index 6b0399eb..efb410e4 100644 --- a/inst/include/Eigen/src/Core/util/Macros.h +++ b/inst/include/Eigen/src/Core/util/Macros.h @@ -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++ diff --git a/inst/include/Eigen/src/Core/util/Meta.h b/inst/include/Eigen/src/Core/util/Meta.h index 9b61ff03..821e287f 100755 --- a/inst/include/Eigen/src/Core/util/Meta.h +++ b/inst/include/Eigen/src/Core/util/Meta.h @@ -309,13 +309,29 @@ 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::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 struct result_of; + +template +struct result_of { + typedef typename std::invoke_result::type type1; + typedef typename remove_all::type type; +}; +#elif EIGEN_HAS_STD_RESULT_OF template struct result_of { typedef typename std::result_of::type type1; typedef typename remove_all::type type; @@ -323,6 +339,7 @@ template struct result_of { #else template struct result_of { }; + struct has_none {int a[1];}; struct has_std_result_type {int a[2];}; struct has_tr1_result {int a[3];}; From 32ec83ba05c63c6b7939a6797b79c01dc7a3b8cf Mon Sep 17 00:00:00 2001 From: tnagler Date: Fri, 12 Jan 2024 14:08:55 +0100 Subject: [PATCH 2/2] define EIGEN_CPLUSPLUS --- inst/include/Eigen/src/Core/util/Macros.h | 26 ++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/inst/include/Eigen/src/Core/util/Macros.h b/inst/include/Eigen/src/Core/util/Macros.h index efb410e4..fb723c86 100644 --- a/inst/include/Eigen/src/Core/util/Macros.h +++ b/inst/include/Eigen/src/Core/util/Macros.h @@ -387,6 +387,30 @@ #define EIGEN_HAS_C99_MATH 0 #endif #endif + +/// \internal EIGEN_COMP_MSVC_LANG set to _MSVC_LANG if the compiler is Microsoft Visual C++, 0 otherwise. +#if defined(_MSVC_LANG) +#define EIGEN_COMP_MSVC_LANG _MSVC_LANG +#else +#define EIGEN_COMP_MSVC_LANG 0 +#endif + +// The macro EIGEN_CPLUSPLUS is a replacement for __cplusplus/_MSVC_LANG that +// works for both platforms, indicating the C++ standard version number. +// +// With MSVC, without defining /Zc:__cplusplus, the __cplusplus macro will +// report 199711L regardless of the language standard specified via /std. +// We need to rely on _MSVC_LANG instead, which is only available after +// VS2015.3. +#if EIGEN_COMP_MSVC_LANG > 0 +#define EIGEN_CPLUSPLUS EIGEN_COMP_MSVC_LANG +#elif EIGEN_COMP_MSVC >= 1900 +#define EIGEN_CPLUSPLUS 201103L +#elif defined(__cplusplus) +#define EIGEN_CPLUSPLUS __cplusplus +#else +#define EIGEN_CPLUSPLUS 0 +#endif // Does the compiler support result_of? // result_of was deprecated in c++17 and removed in c++ 20 @@ -401,7 +425,7 @@ // Does the compiler support invoke_result? // invoke_result was introduced in c++17 #ifndef EIGEN_HAS_STD_INVOKE_RESULT -#if EIGEN_COMP_CXXVER > 201402L +#if EIGEN_CPLUSPLUS > 201402L #define EIGEN_HAS_STD_INVOKE_RESULT 1 #else #define EIGEN_HAS_STD_INVOKE_RESULT 0