mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-09-14 18:33:16 +08:00
use a more c++-ish way of preventing the compiler from generating default operator=
when it's not wanted. Thanks to Christian Mayer for the tip.
This commit is contained in:
parent
fa8009c6b7
commit
7ddc13b9fa
@ -26,8 +26,8 @@
|
||||
#ifndef EIGEN_CAST_H
|
||||
#define EIGEN_CAST_H
|
||||
|
||||
template<typename NewScalar, typename MatrixType> class Cast
|
||||
: public MatrixBase<NewScalar, Cast<NewScalar, MatrixType> >
|
||||
template<typename NewScalar, typename MatrixType> class Cast : NoDefaultOperatorEquals,
|
||||
public MatrixBase<NewScalar, Cast<NewScalar, MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef NewScalar Scalar;
|
||||
@ -42,9 +42,6 @@ template<typename NewScalar, typename MatrixType> class Cast
|
||||
Cast(const Cast& other)
|
||||
: m_matrix(other.m_matrix) {}
|
||||
|
||||
// assignments are illegal but we still want to intercept them and get clean compile errors
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Cast)
|
||||
|
||||
private:
|
||||
const Cast& _ref() const { return *this; }
|
||||
int _rows() const { return m_matrix.rows(); }
|
||||
|
@ -26,8 +26,8 @@
|
||||
#ifndef EIGEN_CONJUGATE_H
|
||||
#define EIGEN_CONJUGATE_H
|
||||
|
||||
template<typename MatrixType> class Conjugate
|
||||
: public MatrixBase<typename MatrixType::Scalar, Conjugate<MatrixType> >
|
||||
template<typename MatrixType> class Conjugate : NoDefaultOperatorEquals,
|
||||
public MatrixBase<typename MatrixType::Scalar, Conjugate<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
@ -42,9 +42,6 @@ template<typename MatrixType> class Conjugate
|
||||
Conjugate(const Conjugate& other)
|
||||
: m_matrix(other.m_matrix) {}
|
||||
|
||||
// assignments are illegal but we still want to intercept them and get clean compile errors
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Conjugate)
|
||||
|
||||
private:
|
||||
const Conjugate& _ref() const { return *this; }
|
||||
int _rows() const { return m_matrix.rows(); }
|
||||
|
@ -26,8 +26,8 @@
|
||||
#ifndef EIGEN_DIFFERENCE_H
|
||||
#define EIGEN_DIFFERENCE_H
|
||||
|
||||
template<typename Lhs, typename Rhs> class Difference
|
||||
: public MatrixBase<typename Lhs::Scalar, Difference<Lhs, Rhs> >
|
||||
template<typename Lhs, typename Rhs> class Difference : NoDefaultOperatorEquals,
|
||||
public MatrixBase<typename Lhs::Scalar, Difference<Lhs, Rhs> >
|
||||
{
|
||||
public:
|
||||
typedef typename Lhs::Scalar Scalar;
|
||||
@ -47,9 +47,6 @@ template<typename Lhs, typename Rhs> class Difference
|
||||
Difference(const Difference& other)
|
||||
: m_lhs(other.m_lhs), m_rhs(other.m_rhs) {}
|
||||
|
||||
// assignments are illegal but we still want to intercept them and get clean compile errors
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Difference)
|
||||
|
||||
private:
|
||||
const Difference& _ref() const { return *this; }
|
||||
int _rows() const { return m_lhs.rows(); }
|
||||
|
@ -26,8 +26,8 @@
|
||||
#ifndef EIGEN_IDENTITY_H
|
||||
#define EIGEN_IDENTITY_H
|
||||
|
||||
template<typename MatrixType> class Identity
|
||||
: public MatrixBase<typename MatrixType::Scalar, Identity<MatrixType> >
|
||||
template<typename MatrixType> class Identity : NoDefaultOperatorEquals,
|
||||
public MatrixBase<typename MatrixType::Scalar, Identity<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
@ -42,9 +42,6 @@ template<typename MatrixType> class Identity
|
||||
assert(RowsAtCompileTime == ColsAtCompileTime);
|
||||
}
|
||||
|
||||
// assignments are illegal but we still want to intercept them and get clean compile errors
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Identity)
|
||||
|
||||
private:
|
||||
Identity& _ref() { return *this; }
|
||||
const Identity& _ref() const { return *this; }
|
||||
|
@ -81,9 +81,6 @@ template<> inline int random(int a, int b)
|
||||
}
|
||||
template<> inline int random()
|
||||
{
|
||||
// "rand() % n" is bad, they say, because the low-order bits are not random enough.
|
||||
// However here, 21 is odd, so random() % 21 uses the high-order bits
|
||||
// as well, so there's no problem.
|
||||
return random<int>(-10, 10);
|
||||
}
|
||||
inline bool isMuchSmallerThan(int a, int, int = precision<int>())
|
||||
|
@ -26,8 +26,8 @@
|
||||
#ifndef EIGEN_OPPOSITE_H
|
||||
#define EIGEN_OPPOSITE_H
|
||||
|
||||
template<typename MatrixType> class Opposite
|
||||
: public MatrixBase<typename MatrixType::Scalar, Opposite<MatrixType> >
|
||||
template<typename MatrixType> class Opposite : NoDefaultOperatorEquals,
|
||||
public MatrixBase<typename MatrixType::Scalar, Opposite<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
@ -42,9 +42,6 @@ template<typename MatrixType> class Opposite
|
||||
Opposite(const Opposite& other)
|
||||
: m_matrix(other.m_matrix) {}
|
||||
|
||||
// assignments are illegal but we still want to intercept them and get clean compile errors
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Opposite)
|
||||
|
||||
private:
|
||||
const Opposite& _ref() const { return *this; }
|
||||
int _rows() const { return m_matrix.rows(); }
|
||||
|
@ -60,8 +60,8 @@ struct ProductUnroller<Index, 0, Lhs, Rhs>
|
||||
static void run(int, int, const Lhs&, const Rhs&, typename Lhs::Scalar&) {}
|
||||
};
|
||||
|
||||
template<typename Lhs, typename Rhs> class Product
|
||||
: public MatrixBase<typename Lhs::Scalar, Product<Lhs, Rhs> >
|
||||
template<typename Lhs, typename Rhs> class Product : NoDefaultOperatorEquals,
|
||||
public MatrixBase<typename Lhs::Scalar, Product<Lhs, Rhs> >
|
||||
{
|
||||
public:
|
||||
typedef typename Lhs::Scalar Scalar;
|
||||
@ -81,9 +81,6 @@ template<typename Lhs, typename Rhs> class Product
|
||||
Product(const Product& other)
|
||||
: m_lhs(other.m_lhs), m_rhs(other.m_rhs) {}
|
||||
|
||||
// assignments are illegal but we still want to intercept them and get clean compile errors
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Product)
|
||||
|
||||
private:
|
||||
const Product& _ref() const { return *this; }
|
||||
int _rows() const { return m_lhs.rows(); }
|
||||
|
@ -26,8 +26,8 @@
|
||||
#ifndef EIGEN_RANDOM_H
|
||||
#define EIGEN_RANDOM_H
|
||||
|
||||
template<typename MatrixType> class Random
|
||||
: public MatrixBase<typename MatrixType::Scalar, Random<MatrixType> >
|
||||
template<typename MatrixType> class Random : NoDefaultOperatorEquals,
|
||||
public MatrixBase<typename MatrixType::Scalar, Random<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
@ -41,9 +41,6 @@ template<typename MatrixType> class Random
|
||||
assert(rows > 0 && cols > 0);
|
||||
}
|
||||
|
||||
// assignments are illegal but we still want to intercept them and get clean compile errors
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Random)
|
||||
|
||||
private:
|
||||
const Random& _ref() const { return *this; }
|
||||
int _rows() const { return m_rows; }
|
||||
|
@ -26,8 +26,8 @@
|
||||
#ifndef EIGEN_SCALARMULTIPLE_H
|
||||
#define EIGEN_SCALARMULTIPLE_H
|
||||
|
||||
template<typename MatrixType> class ScalarMultiple
|
||||
: public MatrixBase<typename MatrixType::Scalar, ScalarMultiple<MatrixType> >
|
||||
template<typename MatrixType> class ScalarMultiple : NoDefaultOperatorEquals,
|
||||
public MatrixBase<typename MatrixType::Scalar, ScalarMultiple<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
@ -43,9 +43,6 @@ template<typename MatrixType> class ScalarMultiple
|
||||
ScalarMultiple(const ScalarMultiple& other)
|
||||
: m_matrix(other.m_matrix), m_scalar(other.m_scalar) {}
|
||||
|
||||
// assignments are illegal but we still want to intercept them and get clean compile errors
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ScalarMultiple)
|
||||
|
||||
private:
|
||||
const ScalarMultiple& _ref() const { return *this; }
|
||||
int _rows() const { return m_matrix.rows(); }
|
||||
|
@ -26,8 +26,8 @@
|
||||
#ifndef EIGEN_SUM_H
|
||||
#define EIGEN_SUM_H
|
||||
|
||||
template<typename Lhs, typename Rhs> class Sum
|
||||
: public MatrixBase<typename Lhs::Scalar, Sum<Lhs, Rhs> >
|
||||
template<typename Lhs, typename Rhs> class Sum : NoDefaultOperatorEquals,
|
||||
public MatrixBase<typename Lhs::Scalar, Sum<Lhs, Rhs> >
|
||||
{
|
||||
public:
|
||||
typedef typename Lhs::Scalar Scalar;
|
||||
@ -44,11 +44,7 @@ template<typename Lhs, typename Rhs> class Sum
|
||||
assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols());
|
||||
}
|
||||
|
||||
Sum(const Sum& other)
|
||||
: m_lhs(other.m_lhs), m_rhs(other.m_rhs) {}
|
||||
|
||||
// assignments are illegal but we still want to intercept them and get clean compile errors
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Sum)
|
||||
Sum(const Sum& other) : m_lhs(other.m_lhs), m_rhs(other.m_rhs) {}
|
||||
|
||||
private:
|
||||
const Sum& _ref() const { return *this; }
|
||||
|
@ -124,4 +124,11 @@ enum AssertLevel
|
||||
InternalDebugging = 2
|
||||
};
|
||||
|
||||
//classes inheriting NoDefaultOperatorEquals don't generate a default operator=.
|
||||
class NoDefaultOperatorEquals
|
||||
{
|
||||
private:
|
||||
NoDefaultOperatorEquals& operator=(const NoDefaultOperatorEquals&);
|
||||
};
|
||||
|
||||
#endif // EIGEN_UTIL_H
|
||||
|
@ -26,8 +26,8 @@
|
||||
#ifndef EIGEN_ZERO_H
|
||||
#define EIGEN_ZERO_H
|
||||
|
||||
template<typename MatrixType> class Zero
|
||||
: public MatrixBase<typename MatrixType::Scalar, Zero<MatrixType> >
|
||||
template<typename MatrixType> class Zero : NoDefaultOperatorEquals,
|
||||
public MatrixBase<typename MatrixType::Scalar, Zero<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
@ -41,9 +41,6 @@ template<typename MatrixType> class Zero
|
||||
assert(rows > 0 && cols > 0);
|
||||
}
|
||||
|
||||
// assignments are illegal but we still want to intercept them and get clean compile errors
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Zero)
|
||||
|
||||
private:
|
||||
const Zero& _ref() const { return *this; }
|
||||
int _rows() const { return m_rows; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user