From 6ae7d842a31e1e1937f88a1acf513c7bf51aee9c Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Sun, 24 Jan 2010 21:44:18 -0500 Subject: [PATCH] generate a compilation error when using ReturnByValue::coeff() or coeffRef(), instead of doing an infinite recursion --- Eigen/src/Core/ReturnByValue.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Eigen/src/Core/ReturnByValue.h b/Eigen/src/Core/ReturnByValue.h index 0199d3740..920269365 100644 --- a/Eigen/src/Core/ReturnByValue.h +++ b/Eigen/src/Core/ReturnByValue.h @@ -70,6 +70,18 @@ template class ReturnByValue { static_cast(this)->evalTo(dst); } inline int rows() const { return static_cast(this)->rows(); } inline int cols() const { return static_cast(this)->cols(); } + +#ifndef EIGEN_PARSED_BY_DOXYGEN +#define Unusable YOU_ARE_TRYING_TO_ACCESS_A_SINGLE_COEFFICIENT_IN_A_SPECIAL_EXPRESSION_WHERE_THAT_IS_NOT_ALLOWED_BECAUSE_THAT_WOULD_BE_INEFFICIENT + class Unusable{ + Unusable(const Unusable&) {} + Unusable& operator=(const Unusable&) {return *this;} + }; + const Unusable& coeff(int) const { return *reinterpret_cast(this); } + const Unusable& coeff(int,int) const { return *reinterpret_cast(this); } + Unusable& coeffRef(int) { return *reinterpret_cast(this); } + Unusable& coeffRef(int,int) { return *reinterpret_cast(this); } +#endif }; template