mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-30 07:44:10 +08:00
Add support for C++11 result_of/lambdas
This commit is contained in:
parent
db05f2d01e
commit
829dddd0fd
@ -382,6 +382,11 @@
|
|||||||
#define EIGEN_HAVE_RVALUE_REFERENCES
|
#define EIGEN_HAVE_RVALUE_REFERENCES
|
||||||
#endif
|
#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?
|
// Does the compiler support variadic templates?
|
||||||
#if __cplusplus > 199711L
|
#if __cplusplus > 199711L
|
||||||
#define EIGEN_HAS_VARIADIC_TEMPLATES 1
|
#define EIGEN_HAS_VARIADIC_TEMPLATES 1
|
||||||
|
@ -165,6 +165,7 @@ template<typename T> struct result_of {};
|
|||||||
struct has_none {int a[1];};
|
struct has_none {int a[1];};
|
||||||
struct has_std_result_type {int a[2];};
|
struct has_std_result_type {int a[2];};
|
||||||
struct has_tr1_result {int a[3];};
|
struct has_tr1_result {int a[3];};
|
||||||
|
struct has_cxx_eleven_result {int a[4];};
|
||||||
|
|
||||||
template<typename Func, typename ArgType, int SizeOf=sizeof(has_none)>
|
template<typename Func, typename ArgType, int SizeOf=sizeof(has_none)>
|
||||||
struct unary_result_of_select {typedef ArgType type;};
|
struct unary_result_of_select {typedef ArgType type;};
|
||||||
@ -175,12 +176,21 @@ struct unary_result_of_select<Func, ArgType, sizeof(has_std_result_type)> {typed
|
|||||||
template<typename Func, typename ArgType>
|
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;};
|
struct unary_result_of_select<Func, ArgType, sizeof(has_tr1_result)> {typedef typename Func::template result<Func(ArgType)>::type type;};
|
||||||
|
|
||||||
|
#ifdef EIGEN_HAS_STD_RESULT_OF
|
||||||
|
template<typename Func, typename ArgType>
|
||||||
|
struct unary_result_of_select<Func, ArgType, sizeof(has_cxx_eleven_result)> {typedef typename std::result_of<Func(ArgType)>::type type;};
|
||||||
|
#endif
|
||||||
|
|
||||||
template<typename Func, typename ArgType>
|
template<typename Func, typename ArgType>
|
||||||
struct result_of<Func(ArgType)> {
|
struct result_of<Func(ArgType)> {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
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<typename T>
|
template<typename T>
|
||||||
static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType)>::type const * = 0);
|
static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType)>::type const * = 0);
|
||||||
|
#ifdef EIGEN_HAS_STD_RESULT_OF
|
||||||
|
template<typename T>
|
||||||
|
static has_cxx_eleven_result testFunctor(T const *, typename std::result_of<T(ArgType)>::type const * = 0);
|
||||||
|
#endif
|
||||||
static has_none testFunctor(...);
|
static has_none testFunctor(...);
|
||||||
|
|
||||||
// note that the following indirection is needed for gcc-3.3
|
// note that the following indirection is needed for gcc-3.3
|
||||||
@ -199,12 +209,22 @@ template<typename Func, typename ArgType0, typename ArgType1>
|
|||||||
struct binary_result_of_select<Func, ArgType0, ArgType1, sizeof(has_tr1_result)>
|
struct binary_result_of_select<Func, ArgType0, ArgType1, sizeof(has_tr1_result)>
|
||||||
{typedef typename Func::template result<Func(ArgType0,ArgType1)>::type type;};
|
{typedef typename Func::template result<Func(ArgType0,ArgType1)>::type type;};
|
||||||
|
|
||||||
|
#ifdef EIGEN_HAS_STD_RESULT_OF
|
||||||
|
template<typename Func, typename ArgType0, typename ArgType1>
|
||||||
|
struct binary_result_of_select<Func, ArgType0, ArgType1, sizeof(has_cxx_eleven_result)>
|
||||||
|
{typedef typename std::result_of<Func(ArgType0, ArgType1)>::type type;};
|
||||||
|
#endif
|
||||||
|
|
||||||
template<typename Func, typename ArgType0, typename ArgType1>
|
template<typename Func, typename ArgType0, typename ArgType1>
|
||||||
struct result_of<Func(ArgType0,ArgType1)> {
|
struct result_of<Func(ArgType0,ArgType1)> {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
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<typename T>
|
template<typename T>
|
||||||
static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType0,ArgType1)>::type const * = 0);
|
static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType0,ArgType1)>::type const * = 0);
|
||||||
|
#ifdef EIGEN_HAS_STD_RESULT_OF
|
||||||
|
template<typename T>
|
||||||
|
static has_cxx_eleven_result testFunctor(T const *, typename std::result_of<T(ArgType0, ArgType1)>::type const * = 0);
|
||||||
|
#endif
|
||||||
static has_none testFunctor(...);
|
static has_none testFunctor(...);
|
||||||
|
|
||||||
// note that the following indirection is needed for gcc-3.3
|
// note that the following indirection is needed for gcc-3.3
|
||||||
|
Loading…
x
Reference in New Issue
Block a user