From 829dddd0fdb1bfd4942ff35fe7dfd4ccdeddc97e Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 19 Feb 2015 15:18:37 +0100 Subject: [PATCH] Add support for C++11 result_of/lambdas --- Eigen/src/Core/util/Macros.h | 5 +++++ Eigen/src/Core/util/Meta.h | 32 ++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index e607cdd12..aaea9f035 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -382,6 +382,11 @@ #define EIGEN_HAVE_RVALUE_REFERENCES #endif +// Does the compiler support result_of? +#if (__has_feature(cxx_lambdas) || (defined(__cplusplus) && __cplusplus >= 201103L)) +#define EIGEN_HAS_STD_RESULT_OF 1 +#endif + // Does the compiler support variadic templates? #if __cplusplus > 199711L #define EIGEN_HAS_VARIADIC_TEMPLATES 1 diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h index 3be9e6ca5..674cd8f97 100644 --- a/Eigen/src/Core/util/Meta.h +++ b/Eigen/src/Core/util/Meta.h @@ -165,6 +165,7 @@ 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];}; +struct has_cxx_eleven_result {int a[4];}; template struct unary_result_of_select {typedef ArgType type;}; @@ -175,13 +176,22 @@ struct unary_result_of_select {typed template struct unary_result_of_select {typedef typename Func::template result::type type;}; +#ifdef EIGEN_HAS_STD_RESULT_OF +template +struct unary_result_of_select {typedef typename std::result_of::type type;}; +#endif + template struct result_of { template - static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0); + static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0); template - static has_tr1_result testFunctor(T const *, typename T::template result::type const * = 0); - static has_none testFunctor(...); + static has_tr1_result testFunctor(T const *, typename T::template result::type const * = 0); +#ifdef EIGEN_HAS_STD_RESULT_OF + template + static has_cxx_eleven_result testFunctor(T const *, typename std::result_of::type const * = 0); +#endif + static has_none testFunctor(...); // note that the following indirection is needed for gcc-3.3 enum {FunctorType = sizeof(testFunctor(static_cast(0)))}; @@ -199,13 +209,23 @@ template struct binary_result_of_select {typedef typename Func::template result::type type;}; +#ifdef EIGEN_HAS_STD_RESULT_OF +template +struct binary_result_of_select +{typedef typename std::result_of::type type;}; +#endif + template struct result_of { template - static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0); + static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0); template - static has_tr1_result testFunctor(T const *, typename T::template result::type const * = 0); - static has_none testFunctor(...); + static has_tr1_result testFunctor(T const *, typename T::template result::type const * = 0); +#ifdef EIGEN_HAS_STD_RESULT_OF + template + static has_cxx_eleven_result testFunctor(T const *, typename std::result_of::type const * = 0); +#endif + static has_none testFunctor(...); // note that the following indirection is needed for gcc-3.3 enum {FunctorType = sizeof(testFunctor(static_cast(0)))};