aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/util/Meta.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2016-08-31 15:45:25 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2016-08-31 15:45:25 +0200
commit218c37beb4dbc701938da71acf0bd3914f34f89e (patch)
tree1d8596ef23fcbf9abc87ce9f41ea0567b8d0d486 /Eigen/src/Core/util/Meta.h
parentefe2c225c9bbd54b51c97d29e86917293a6091f4 (diff)
bug #1286: automatically detect the available prototypes of functors passed to CwiseNullaryExpr such that functors have only to implement the operators that matters among:
operator()() operator()(i) operator()(i,j) Linear access is also automatically detected based on the availability of operator()(i,j).
Diffstat (limited to 'Eigen/src/Core/util/Meta.h')
-rwxr-xr-xEigen/src/Core/util/Meta.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h
index b9beb6eb7..e69c78db2 100755
--- a/Eigen/src/Core/util/Meta.h
+++ b/Eigen/src/Core/util/Meta.h
@@ -22,6 +22,16 @@
namespace Eigen {
+typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex;
+
+/**
+ * \brief The Index type as used for the API.
+ * \details To change this, \c \#define the preprocessor symbol \c EIGEN_DEFAULT_DENSE_INDEX_TYPE.
+ * \sa \blank \ref TopicPreprocessorDirectives, StorageIndex.
+ */
+
+typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE Index;
+
namespace internal {
/** \internal
@@ -371,6 +381,39 @@ struct has_ReturnType
enum { value = sizeof(testFunctor<T>(0)) == sizeof(yes) };
};
+template<int> struct any_int {};
+template<typename T> const T& return_ref();
+
+struct meta_yes { char data[1]; };
+struct meta_no { char data[2]; };
+
+template <typename T>
+struct has_nullary_operator
+{
+ template <typename C> static meta_yes testFunctor(C const *,any_int< sizeof(return_ref<C>()()) > * = 0);
+ static meta_no testFunctor(...);
+
+ enum { value = sizeof(testFunctor(static_cast<T*>(0))) == sizeof(meta_yes) };
+};
+
+template <typename T>
+struct has_unary_operator
+{
+ template <typename C> static meta_yes testFunctor(C const *,any_int< sizeof(return_ref<C>()(Index(0))) > * = 0);
+ static meta_no testFunctor(...);
+
+ enum { value = sizeof(testFunctor(static_cast<T*>(0))) == sizeof(meta_yes) };
+};
+
+template <typename T>
+struct has_binary_operator
+{
+ template <typename C> static meta_yes testFunctor(C const *,any_int< sizeof(return_ref<C>()(Index(0),Index(0))) > * = 0);
+ static meta_no testFunctor(...);
+
+ enum { value = sizeof(testFunctor(static_cast<T*>(0))) == sizeof(meta_yes) };
+};
+
/** \internal In short, it computes int(sqrt(\a Y)) with \a Y an integer.
* Usage example: \code meta_sqrt<1023>::ret \endcode
*/