diff options
author | Christoph Hertzberg <chtz@informatik.uni-bremen.de> | 2014-09-23 14:28:23 +0200 |
---|---|---|
committer | Christoph Hertzberg <chtz@informatik.uni-bremen.de> | 2014-09-23 14:28:23 +0200 |
commit | 36448c9e287935b8c408791bf88b2907292d6c80 (patch) | |
tree | 841afdf4ea165433ad3b0f797498441815344eeb /Eigen/src/Core | |
parent | de0d8a010e8cee66901786e0e2819beeaa5cb253 (diff) |
Make constructors explicit if they could lead to unintended implicit conversion
Diffstat (limited to 'Eigen/src/Core')
36 files changed, 197 insertions, 167 deletions
diff --git a/Eigen/src/Core/ArrayBase.h b/Eigen/src/Core/ArrayBase.h index 48a0006d5..b37b49ac4 100644 --- a/Eigen/src/Core/ArrayBase.h +++ b/Eigen/src/Core/ArrayBase.h @@ -158,9 +158,9 @@ template<typename Derived> class ArrayBase /** \returns an \link Eigen::MatrixBase Matrix \endlink expression of this array * \sa MatrixBase::array() */ EIGEN_DEVICE_FUNC - MatrixWrapper<Derived> matrix() { return derived(); } + MatrixWrapper<Derived> matrix() { return MatrixWrapper<Derived>(derived()); } EIGEN_DEVICE_FUNC - const MatrixWrapper<const Derived> matrix() const { return derived(); } + const MatrixWrapper<const Derived> matrix() const { return MatrixWrapper<const Derived>(derived()); } // template<typename Dest> // inline void evalTo(Dest& dst) const { dst = matrix(); } diff --git a/Eigen/src/Core/ArrayWrapper.h b/Eigen/src/Core/ArrayWrapper.h index ed5210272..0b89c58cb 100644 --- a/Eigen/src/Core/ArrayWrapper.h +++ b/Eigen/src/Core/ArrayWrapper.h @@ -55,7 +55,7 @@ class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> > typedef typename internal::nested<ExpressionType>::type NestedExpressionType; EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {} + explicit EIGEN_STRONG_INLINE ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {} EIGEN_DEVICE_FUNC inline Index rows() const { return m_expression.rows(); } @@ -198,7 +198,7 @@ class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> > typedef typename internal::nested<ExpressionType>::type NestedExpressionType; EIGEN_DEVICE_FUNC - inline MatrixWrapper(ExpressionType& a_matrix) : m_expression(a_matrix) {} + explicit inline MatrixWrapper(ExpressionType& a_matrix) : m_expression(a_matrix) {} EIGEN_DEVICE_FUNC inline Index rows() const { return m_expression.rows(); } diff --git a/Eigen/src/Core/BandMatrix.h b/Eigen/src/Core/BandMatrix.h index b0ebe1160..e59ee3da9 100644 --- a/Eigen/src/Core/BandMatrix.h +++ b/Eigen/src/Core/BandMatrix.h @@ -204,7 +204,7 @@ class BandMatrix : public BandMatrixBase<BandMatrix<_Scalar,Rows,Cols,Supers,Sub typedef typename internal::traits<BandMatrix>::Index Index; typedef typename internal::traits<BandMatrix>::CoefficientsType CoefficientsType; - inline BandMatrix(Index rows=Rows, Index cols=Cols, Index supers=Supers, Index subs=Subs) + explicit inline BandMatrix(Index rows=Rows, Index cols=Cols, Index supers=Supers, Index subs=Subs) : m_coeffs(1+supers+subs,cols), m_rows(rows), m_supers(supers), m_subs(subs) { @@ -266,7 +266,7 @@ class BandMatrixWrapper : public BandMatrixBase<BandMatrixWrapper<_CoefficientsT typedef typename internal::traits<BandMatrixWrapper>::CoefficientsType CoefficientsType; typedef typename internal::traits<BandMatrixWrapper>::Index Index; - inline BandMatrixWrapper(const CoefficientsType& coeffs, Index rows=_Rows, Index cols=_Cols, Index supers=_Supers, Index subs=_Subs) + explicit inline BandMatrixWrapper(const CoefficientsType& coeffs, Index rows=_Rows, Index cols=_Cols, Index supers=_Supers, Index subs=_Subs) : m_coeffs(coeffs), m_rows(rows), m_supers(supers), m_subs(subs) { @@ -314,7 +314,7 @@ class TridiagonalMatrix : public BandMatrix<Scalar,Size,Size,Options&SelfAdjoint typedef BandMatrix<Scalar,Size,Size,Options&SelfAdjoint?0:1,1,Options|RowMajor> Base; typedef typename Base::Index Index; public: - TridiagonalMatrix(Index size = Size) : Base(size,size,Options&SelfAdjoint?0:1,1) {} + explicit TridiagonalMatrix(Index size = Size) : Base(size,size,Options&SelfAdjoint?0:1,1) {} inline typename Base::template DiagonalIntReturnType<1>::Type super() { return Base::template diagonal<1>(); } diff --git a/Eigen/src/Core/CoreEvaluators.h b/Eigen/src/Core/CoreEvaluators.h index 09a83a382..ab4320c2a 100644 --- a/Eigen/src/Core/CoreEvaluators.h +++ b/Eigen/src/Core/CoreEvaluators.h @@ -34,6 +34,11 @@ template<typename StorageKind> struct storage_kind_to_shape; template<> struct storage_kind_to_shape<Dense> { typedef DenseShape Shape; }; + +// FIXME Is this necessary? And why was it not before refactoring??? +template<> struct storage_kind_to_shape<PermutationStorage> { typedef PermutationShape Shape; }; + + // Evaluators have to be specialized with respect to various criteria such as: // - storage/structure/shape // - scalar type @@ -87,7 +92,7 @@ template<typename T> struct evaluator : public unary_evaluator<T> { typedef unary_evaluator<T> Base; - evaluator(const T& xpr) : Base(xpr) {} + explicit evaluator(const T& xpr) : Base(xpr) {} }; @@ -150,7 +155,7 @@ struct evaluator<PlainObjectBase<Derived> > : RowsAtCompileTime) {} - evaluator(const PlainObjectType& m) + explicit evaluator(const PlainObjectType& m) : m_data(m.data()), m_outerStride(IsVectorAtCompileTime ? 0 : m.outerStride()) { } @@ -242,7 +247,7 @@ struct evaluator<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > evaluator() {} - evaluator(const XprType& m) + explicit evaluator(const XprType& m) : evaluator<PlainObjectBase<XprType> >(m) { } }; @@ -260,7 +265,7 @@ struct unary_evaluator<Transpose<ArgType>, IndexBased> Flags = evaluator<ArgType>::Flags ^ RowMajorBit }; - unary_evaluator(const XprType& t) : m_argImpl(t.nestedExpression()) {} + explicit unary_evaluator(const XprType& t) : m_argImpl(t.nestedExpression()) {} typedef typename XprType::Index Index; typedef typename XprType::Scalar Scalar; @@ -337,7 +342,7 @@ struct evaluator<CwiseNullaryOp<NullaryOp,PlainObjectType> > | (functor_traits<NullaryOp>::IsRepeatable ? 0 : EvalBeforeNestingBit) // FIXME EvalBeforeNestingBit should be needed anymore }; - evaluator(const XprType& n) + explicit evaluator(const XprType& n) : m_functor(n.functor()) { } @@ -387,7 +392,7 @@ struct unary_evaluator<CwiseUnaryOp<UnaryOp, ArgType>, IndexBased > | (functor_traits<UnaryOp>::PacketAccess ? PacketAccessBit : 0)) }; - unary_evaluator(const XprType& op) + explicit unary_evaluator(const XprType& op) : m_functor(op.functor()), m_argImpl(op.nestedExpression()) { } @@ -433,7 +438,7 @@ struct evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType; typedef binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > Base; - evaluator(const XprType& xpr) : Base(xpr) {} + explicit evaluator(const XprType& xpr) : Base(xpr) {} }; template<typename BinaryOp, typename Lhs, typename Rhs> @@ -461,7 +466,7 @@ struct binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, IndexBased, IndexBase Flags = (Flags0 & ~RowMajorBit) | (LhsFlags & RowMajorBit) }; - binary_evaluator(const XprType& xpr) + explicit binary_evaluator(const XprType& xpr) : m_functor(xpr.functor()), m_lhsImpl(xpr.lhs()), m_rhsImpl(xpr.rhs()) @@ -515,7 +520,7 @@ struct unary_evaluator<CwiseUnaryView<UnaryOp, ArgType>, IndexBased> Flags = (evaluator<ArgType>::Flags & (HereditaryBits | LinearAccessBit | DirectAccessBit)) }; - unary_evaluator(const XprType& op) + explicit unary_evaluator(const XprType& op) : m_unaryOp(op.functor()), m_argImpl(op.nestedExpression()) { } @@ -573,7 +578,7 @@ struct mapbase_evaluator : evaluator_base<Derived> CoeffReadCost = NumTraits<Scalar>::ReadCost }; - mapbase_evaluator(const XprType& map) + explicit mapbase_evaluator(const XprType& map) : m_data(const_cast<PointerType>(map.data())), m_xpr(map) { @@ -663,7 +668,7 @@ struct evaluator<Map<PlainObjectType, MapOptions, StrideType> > Flags = KeepsPacketAccess ? int(Flags2) : (int(Flags2) & ~PacketAccessBit) }; - evaluator(const XprType& map) + explicit evaluator(const XprType& map) : mapbase_evaluator<XprType, PlainObjectType>(map) { } }; @@ -680,7 +685,7 @@ struct evaluator<Ref<PlainObjectType, RefOptions, StrideType> > Flags = evaluator<Map<PlainObjectType, RefOptions, StrideType> >::Flags }; - evaluator(const XprType& ref) + explicit evaluator(const XprType& ref) : mapbase_evaluator<XprType, PlainObjectType>(ref) { } }; @@ -731,7 +736,7 @@ struct evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel> > Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit }; typedef block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel> block_evaluator_type; - evaluator(const XprType& block) : block_evaluator_type(block) {} + explicit evaluator(const XprType& block) : block_evaluator_type(block) {} }; // no direct-access => dispatch to a unary evaluator @@ -741,7 +746,7 @@ struct block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel, /*HasDirectAcc { typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType; - block_evaluator(const XprType& block) + explicit block_evaluator(const XprType& block) : unary_evaluator<XprType>(block) {} }; @@ -752,7 +757,7 @@ struct unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, IndexBa { typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType; - unary_evaluator(const XprType& block) + explicit unary_evaluator(const XprType& block) : m_argImpl(block.nestedExpression()), m_startRow(block.startRow()), m_startCol(block.startCol()) @@ -831,7 +836,7 @@ struct block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel, /* HasDirectAc { typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType; - block_evaluator(const XprType& block) + explicit block_evaluator(const XprType& block) : mapbase_evaluator<XprType, typename XprType::PlainObject>(block) { // FIXME this should be an internal assertion @@ -857,7 +862,7 @@ struct evaluator<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> > Flags = (unsigned int)evaluator<ThenMatrixType>::Flags & evaluator<ElseMatrixType>::Flags & HereditaryBits }; - evaluator(const XprType& select) + explicit evaluator(const XprType& select) : m_conditionImpl(select.conditionMatrix()), m_thenImpl(select.thenMatrix()), m_elseImpl(select.elseMatrix()) @@ -911,7 +916,7 @@ struct unary_evaluator<Replicate<ArgType, RowFactor, ColFactor> > Flags = (evaluator<ArgTypeNestedCleaned>::Flags & HereditaryBits & ~RowMajorBit) | (traits<XprType>::Flags & RowMajorBit) }; - unary_evaluator(const XprType& replicate) + explicit unary_evaluator(const XprType& replicate) : m_arg(replicate.nestedExpression()), m_argImpl(m_arg), m_rows(replicate.nestedExpression().rows()), @@ -975,7 +980,7 @@ struct evaluator<PartialReduxExpr<ArgType, MemberOp, Direction> > Flags = (traits<XprType>::Flags&RowMajorBit) | (evaluator<ArgType>::Flags&HereditaryBits) }; - evaluator(const XprType expr) + explicit evaluator(const XprType expr) : m_expr(expr) {} @@ -1012,7 +1017,7 @@ struct evaluator_wrapper_base Flags = evaluator<ArgType>::Flags }; - evaluator_wrapper_base(const ArgType& arg) : m_argImpl(arg) {} + explicit evaluator_wrapper_base(const ArgType& arg) : m_argImpl(arg) {} typedef typename ArgType::Index Index; typedef typename ArgType::Scalar Scalar; @@ -1074,7 +1079,7 @@ struct unary_evaluator<MatrixWrapper<TArgType> > { typedef MatrixWrapper<TArgType> XprType; - unary_evaluator(const XprType& wrapper) + explicit unary_evaluator(const XprType& wrapper) : evaluator_wrapper_base<MatrixWrapper<TArgType> >(wrapper.nestedExpression()) { } }; @@ -1085,7 +1090,7 @@ struct unary_evaluator<ArrayWrapper<TArgType> > { typedef ArrayWrapper<TArgType> XprType; - unary_evaluator(const XprType& wrapper) + explicit unary_evaluator(const XprType& wrapper) : evaluator_wrapper_base<ArrayWrapper<TArgType> >(wrapper.nestedExpression()) { } }; @@ -1131,7 +1136,7 @@ struct unary_evaluator<Reverse<ArgType, Direction> > }; typedef internal::reverse_packet_cond<PacketScalar,ReversePacket> reverse_packet; - unary_evaluator(const XprType& reverse) + explicit unary_evaluator(const XprType& reverse) : m_argImpl(reverse.nestedExpression()), m_rows(ReverseRow ? reverse.nestedExpression().rows() : 0), m_cols(ReverseCol ? reverse.nestedExpression().cols() : 0) @@ -1212,7 +1217,7 @@ struct evaluator<Diagonal<ArgType, DiagIndex> > Flags = (unsigned int)evaluator<ArgType>::Flags & (HereditaryBits | LinearAccessBit | DirectAccessBit) & ~RowMajorBit }; - evaluator(const XprType& diagonal) + explicit evaluator(const XprType& diagonal) : m_argImpl(diagonal.nestedExpression()), m_index(diagonal.index()) { } @@ -1275,7 +1280,7 @@ class EvalToTemp typedef typename dense_xpr_base<EvalToTemp>::type Base; EIGEN_GENERIC_PUBLIC_INTERFACE(EvalToTemp) - EvalToTemp(const ArgType& arg) + explicit EvalToTemp(const ArgType& arg) : m_arg(arg) { } @@ -1309,7 +1314,7 @@ struct evaluator<EvalToTemp<ArgType> > typedef evaluator type; typedef evaluator nestedType; - evaluator(const XprType& xpr) + explicit evaluator(const XprType& xpr) : m_result(xpr.rows(), xpr.cols()) { ::new (static_cast<Base*>(this)) Base(m_result); diff --git a/Eigen/src/Core/CwiseUnaryOp.h b/Eigen/src/Core/CwiseUnaryOp.h index 79a872934..708e3e818 100644 --- a/Eigen/src/Core/CwiseUnaryOp.h +++ b/Eigen/src/Core/CwiseUnaryOp.h @@ -63,7 +63,7 @@ class CwiseUnaryOp : internal::no_assignment_operator, typedef typename internal::remove_all<XprType>::type NestedExpression; EIGEN_DEVICE_FUNC - inline CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp()) + explicit inline CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp()) : m_xpr(xpr), m_functor(func) {} EIGEN_DEVICE_FUNC diff --git a/Eigen/src/Core/CwiseUnaryView.h b/Eigen/src/Core/CwiseUnaryView.h index 71249a39c..61fd8ee35 100644 --- a/Eigen/src/Core/CwiseUnaryView.h +++ b/Eigen/src/Core/CwiseUnaryView.h @@ -63,7 +63,7 @@ class CwiseUnaryView : public CwiseUnaryViewImpl<ViewOp, MatrixType, typename in EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView) typedef typename internal::remove_all<MatrixType>::type NestedExpression; - inline CwiseUnaryView(const MatrixType& mat, const ViewOp& func = ViewOp()) + explicit inline CwiseUnaryView(const MatrixType& mat, const ViewOp& func = ViewOp()) : m_matrix(mat), m_functor(func) {} EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView) diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h index 6078af553..101ef6f20 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -275,6 +275,7 @@ template<typename Derived> class DenseBase // TODO flagged is temporarly disabled. It seems useless now template<unsigned int Added,unsigned int Removed> + EIGEN_DEPRECATED const Derived& flagged() const { return derived(); } @@ -282,8 +283,9 @@ template<typename Derived> class DenseBase EIGEN_DEVICE_FUNC CommaInitializer<Derived> operator<< (const DenseBase<OtherDerived>& other); + typedef Transpose<Derived> TransposeReturnType; EIGEN_DEVICE_FUNC - Eigen::Transpose<Derived> transpose(); + TransposeReturnType transpose(); typedef typename internal::add_const<Transpose<const Derived> >::type ConstTransposeReturnType; EIGEN_DEVICE_FUNC ConstTransposeReturnType transpose() const; diff --git a/Eigen/src/Core/DenseStorage.h b/Eigen/src/Core/DenseStorage.h index 59f515495..852648639 100644 --- a/Eigen/src/Core/DenseStorage.h +++ b/Eigen/src/Core/DenseStorage.h @@ -130,7 +130,7 @@ template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseSt public: EIGEN_DEVICE_FUNC DenseStorage() {} EIGEN_DEVICE_FUNC - DenseStorage(internal::constructor_without_unaligned_array_assert) + explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(internal::constructor_without_unaligned_array_assert()) {} EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) : m_data(other.m_data) {} @@ -155,7 +155,7 @@ template<typename T, int _Rows, int _Cols, int _Options> class DenseStorage<T, 0 { public: EIGEN_DEVICE_FUNC DenseStorage() {} - EIGEN_DEVICE_FUNC DenseStorage(internal::constructor_without_unaligned_array_assert) {} + EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) {} EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage&) {} EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage&) { return *this; } EIGEN_DEVICE_FUNC DenseStorage(DenseIndex,DenseIndex,DenseIndex) {} @@ -186,7 +186,7 @@ template<typename T, int Size, int _Options> class DenseStorage<T, Size, Dynamic DenseIndex m_cols; public: EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0), m_cols(0) {} - DenseStorage(internal::constructor_without_unaligned_array_assert) + explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {} DenseStorage(const DenseStorage& other) : m_data(other.m_data), m_rows(other.m_rows), m_cols(other.m_cols) {} DenseStorage& operator=(const DenseStorage& other) @@ -217,7 +217,7 @@ template<typename T, int Size, int _Cols, int _Options> class DenseStorage<T, Si DenseIndex m_rows; public: EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0) {} - DenseStorage(internal::constructor_without_unaligned_array_assert) + explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0) {} DenseStorage(const DenseStorage& other) : m_data(other.m_data), m_rows(other.m_rows) {} DenseStorage& operator=(const DenseStorage& other) @@ -246,7 +246,7 @@ template<typename T, int Size, int _Rows, int _Options> class DenseStorage<T, Si DenseIndex m_cols; public: EIGEN_DEVICE_FUNC DenseStorage() : m_cols(0) {} - DenseStorage(internal::constructor_without_unaligned_array_assert) + explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(internal::constructor_without_unaligned_array_assert()), m_cols(0) {} DenseStorage(const DenseStorage& other) : m_data(other.m_data), m_cols(other.m_cols) {} DenseStorage& operator=(const DenseStorage& other) @@ -276,7 +276,7 @@ template<typename T, int _Options> class DenseStorage<T, Dynamic, Dynamic, Dynam DenseIndex m_cols; public: EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_rows(0), m_cols(0) {} - DenseStorage(internal::constructor_without_unaligned_array_assert) + explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0), m_cols(0) {} DenseStorage(DenseIndex size, DenseIndex nbRows, DenseIndex nbCols) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(nbRows), m_cols(nbCols) @@ -350,7 +350,7 @@ template<typename T, int _Rows, int _Options> class DenseStorage<T, Dynamic, _Ro DenseIndex m_cols; public: EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_cols(0) {} - DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {} + explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {} DenseStorage(DenseIndex size, DenseIndex, DenseIndex nbCols) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_cols(nbCols) { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN } DenseStorage(const DenseStorage& other) @@ -416,7 +416,7 @@ template<typename T, int _Cols, int _Options> class DenseStorage<T, Dynamic, Dyn DenseIndex m_rows; public: EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_rows(0) {} - DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {} + explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {} DenseStorage(DenseIndex size, DenseIndex nbRows, DenseIndex) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(nbRows) { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN } DenseStorage(const DenseStorage& other) diff --git a/Eigen/src/Core/Diagonal.h b/Eigen/src/Core/Diagonal.h index 1ffcd97f9..ba7ddbb14 100644 --- a/Eigen/src/Core/Diagonal.h +++ b/Eigen/src/Core/Diagonal.h @@ -70,7 +70,7 @@ template<typename MatrixType, int _DiagIndex> class Diagonal EIGEN_DENSE_PUBLIC_INTERFACE(Diagonal) EIGEN_DEVICE_FUNC - inline Diagonal(MatrixType& matrix, Index a_index = DiagIndex) : m_matrix(matrix), m_index(a_index) {} + explicit inline Diagonal(MatrixType& matrix, Index a_index = DiagIndex) : m_matrix(matrix), m_index(a_index) {} EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Diagonal) @@ -189,7 +189,7 @@ template<typename Derived> inline typename MatrixBase<Derived>::DiagonalReturnType MatrixBase<Derived>::diagonal() { - return derived(); + return DiagonalReturnType(derived()); } /** This is the const version of diagonal(). */ @@ -238,20 +238,20 @@ MatrixBase<Derived>::diagonal(Index index) const * * \sa MatrixBase::diagonal(), class Diagonal */ template<typename Derived> -template<int Index> -inline typename MatrixBase<Derived>::template DiagonalIndexReturnType<Index>::Type +template<int Index_> +inline typename MatrixBase<Derived>::template DiagonalIndexReturnType<Index_>::Type MatrixBase<Derived>::diagonal() { - return derived(); + return typename DiagonalIndexReturnType<Index_>::Type(derived()); } /** This is the const version of diagonal<int>(). */ template<typename Derived> -template<int Index> -inline typename MatrixBase<Derived>::template ConstDiagonalIndexReturnType<Index>::Type +template<int Index_> +inline typename MatrixBase<Derived>::template ConstDiagonalIndexReturnType<Index_>::Type MatrixBase<Derived>::diagonal() const { - return derived(); + return typename ConstDiagonalIndexReturnType<Index_>::Type(derived()); } } // end namespace Eigen diff --git a/Eigen/src/Core/DiagonalMatrix.h b/Eigen/src/Core/DiagonalMatrix.h index 44c249aa6..e3dc71336 100644 --- a/Eigen/src/Core/DiagonalMatrix.h +++ b/Eigen/src/Core/DiagonalMatrix.h @@ -63,24 +63,26 @@ class DiagonalBase : public EigenBase<Derived> return Product<Derived, MatrixDerived, LazyProduct>(derived(),matrix.derived()); } + typedef DiagonalWrapper<const CwiseUnaryOp<internal::scalar_inverse_op<Scalar>, const DiagonalVectorType> > InverseReturnType; EIGEN_DEVICE_FUNC - inline const DiagonalWrapper<const CwiseUnaryOp<internal::scalar_inverse_op<Scalar>, const DiagonalVectorType> > + inline const InverseReturnType inverse() const { - return diagonal().cwiseInverse(); + return InverseReturnType(diagonal().cwiseInverse()); } + typedef DiagonalWrapper<const CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, const DiagonalVectorType> > ScalarMultipleReturnType; EIGEN_DEVICE_FUNC - inline const DiagonalWrapper<const CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, const DiagonalVectorType> > + inline const ScalarMultipleReturnType operator*(const Scalar& scalar) const { - return diagonal() * scalar; + return ScalarMultipleReturnType(diagonal() * scalar); } EIGEN_DEVICE_FUNC - friend inline const DiagonalWrapper<const CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, const DiagonalVectorType> > + friend inline const ScalarMultipleReturnType operator*(const Scalar& scalar, const DiagonalBase& other) { - return other.diagonal() * scalar; + return ScalarMultipleReturnType(other.diagonal() * scalar); } }; @@ -144,7 +146,7 @@ class DiagonalMatrix /** Constructs a diagonal matrix with given dimension */ EIGEN_DEVICE_FUNC - inline DiagonalMatrix(Index dim) : m_diagonal(dim) {} + explicit inline DiagonalMatrix(Index dim) : m_diagonal(dim) {} /** 2D constructor. */ EIGEN_DEVICE_FUNC @@ -253,7 +255,7 @@ class DiagonalWrapper /** Constructor from expression of diagonal coefficients to wrap. */ EIGEN_DEVICE_FUNC - inline DiagonalWrapper(DiagonalVectorType& a_diagonal) : m_diagonal(a_diagonal) {} + explicit inline DiagonalWrapper(DiagonalVectorType& a_diagonal) : m_diagonal(a_diagonal) {} /** \returns a const reference to the wrapped expression of diagonal coefficients. */ EIGEN_DEVICE_FUNC @@ -276,7 +278,7 @@ template<typename Derived> inline const DiagonalWrapper<const Derived> MatrixBase<Derived>::asDiagonal() const { - return derived(); + return DiagonalWrapper<const Derived>(derived()); } /** \returns true if *this is approximately equal to a diagonal matrix, diff --git a/Eigen/src/Core/Flagged.h b/Eigen/src/Core/Flagged.h index 1f2955fc1..6ce11edf3 100644 --- a/Eigen/src/Core/Flagged.h +++ b/Eigen/src/Core/Flagged.h @@ -48,7 +48,7 @@ template<typename ExpressionType, unsigned int Added, unsigned int Removed> clas ExpressionType, const ExpressionType&>::type ExpressionTypeNested; typedef typename ExpressionType::InnerIterator InnerIterator; - inline Flagged(const ExpressionType& matrix) : m_matrix(matrix) {} + explicit inline Flagged(const ExpressionType& matrix) : m_matrix(matrix) {} inline Index rows() const { return m_matrix.rows(); } inline Index cols() const { return m_matrix.cols(); } @@ -132,7 +132,7 @@ template<unsigned int Added,unsigned int Removed> inline const Flagged<Derived, Added, Removed> DenseBase<Derived>::flagged() const { - return derived(); + return Flagged<Derived, Added, Removed>(derived()); } } // end namespace Eigen diff --git a/Eigen/src/Core/ForceAlignedAccess.h b/Eigen/src/Core/ForceAlignedAccess.h index 807c7a293..065acfa64 100644 --- a/Eigen/src/Core/ForceAlignedAccess.h +++ b/Eigen/src/Core/ForceAlignedAccess.h @@ -39,7 +39,7 @@ template<typename ExpressionType> class ForceAlignedAccess typedef typename internal::dense_xpr_base<ForceAlignedAccess>::type Base; EIGEN_DENSE_PUBLIC_INTERFACE(ForceAlignedAccess) - inline ForceAlignedAccess(const ExpressionType& matrix) : m_expression(matrix) {} + explicit inline ForceAlignedAccess(const ExpressionType& matrix) : m_expression(matrix) {} inline Index rows() const { return m_expression.rows(); } inline Index cols() const { return m_expression.cols(); } @@ -127,7 +127,7 @@ template<bool Enable> inline typename internal::add_const_on_value_type<typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type>::type MatrixBase<Derived>::forceAlignedAccessIf() const { - return derived(); + return derived(); // FIXME This should not work but apparently is never used } /** \returns an expression of *this with forced aligned access if \a Enable is true. @@ -138,7 +138,7 @@ template<bool Enable> inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type MatrixBase<Derived>::forceAlignedAccessIf() { - return derived(); + return derived(); // FIXME This should not work but apparently is never used } } // end namespace Eigen diff --git a/Eigen/src/Core/GlobalFunctions.h b/Eigen/src/Core/GlobalFunctions.h index 2067a2a6e..ee67b7d3c 100644 --- a/Eigen/src/Core/GlobalFunctions.h +++ b/Eigen/src/Core/GlobalFunctions.h @@ -15,7 +15,7 @@ template<typename Derived> \ inline const Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived> \ NAME(const Eigen::ArrayBase<Derived>& x) { \ - return x.derived(); \ + return Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived>(x.derived()); \ } #define EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(NAME,FUNCTOR) \ @@ -30,7 +30,7 @@ { \ static inline typename NAME##_retval<ArrayBase<Derived> >::type run(const Eigen::ArrayBase<Derived>& x) \ { \ - return x.derived(); \ + return typename NAME##_retval<ArrayBase<Derived> >::type(x.derived()); \ } \ }; diff --git a/Eigen/src/Core/Inverse.h b/Eigen/src/Core/Inverse.h index 5cfa7e50c..706796b78 100644 --- a/Eigen/src/Core/Inverse.h +++ b/Eigen/src/Core/Inverse.h @@ -51,7 +51,7 @@ public: typedef typename internal::nested<XprType>::type XprTypeNested; typedef typename internal::remove_all<XprTypeNested>::type XprTypeNestedCleaned; - Inverse(const XprType &xpr) + explicit Inverse(const XprType &xpr) : m_xpr(xpr) {} diff --git a/Eigen/src/Core/Map.h b/Eigen/src/Core/Map.h index 87c1787bf..098f1c096 100644 --- a/Eigen/src/Core/Map.h +++ b/Eigen/src/Core/Map.h @@ -122,7 +122,7 @@ template<typename PlainObjectType, int MapOptions, typename StrideType> class Ma * \param a_stride optional Stride object, passing the strides. */ EIGEN_DEVICE_FUNC - inline Map(PointerArgType dataPtr, const StrideType& a_stride = StrideType()) + explicit inline Map(PointerArgType dataPtr, const StrideType& a_stride = StrideType()) : Base(cast_to_pointer_type(dataPtr)), m_stride(a_stride) { PlainObjectType::Base::_check_template_params(); diff --git a/Eigen/src/Core/MapBase.h b/Eigen/src/Core/MapBase.h index 6d3b344e8..3e68b1e91 100644 --- a/Eigen/src/Core/MapBase.h +++ b/Eigen/src/Core/MapBase.h @@ -128,7 +128,7 @@ template<typename Derived> class MapBase<Derived, ReadOnlyAccessors> } EIGEN_DEVICE_FUNC - inline MapBase(PointerType dataPtr) : m_data(dataPtr), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime) + explicit inline MapBase(PointerType dataPtr) : m_data(dataPtr), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime) { EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived) checkSanity(); diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index 8a5821548..bb6c75387 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -214,7 +214,7 @@ class Matrix // FIXME is it still needed EIGEN_DEVICE_FUNC - Matrix(internal::constructor_without_unaligned_array_assert) + explicit Matrix(internal::constructor_without_unaligned_array_assert) : Base(internal::constructor_without_unaligned_array_assert()) { Base::_check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED } diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 9dbbd6fb5..048060e6b 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -327,7 +327,7 @@ template<typename Derived> class MatrixBase NoAlias<Derived,Eigen::MatrixBase > noalias(); - // TODO forceAlignedAccess is temporarly disabled + // TODO forceAlignedAccess is temporarily disabled // Need to find a nicer workaround. inline const Derived& forceAlignedAccess() const { return derived(); } inline Derived& forceAlignedAccess() { return derived(); } @@ -343,10 +343,10 @@ template<typename Derived> class MatrixBase /** \returns an \link Eigen::ArrayBase Array \endlink expression of this matrix * \sa ArrayBase::matrix() */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ArrayWrapper<Derived> array() { return derived(); } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ArrayWrapper<Derived> array() { return ArrayWrapper<Derived>(derived()); } /** \returns a const \link Eigen::ArrayBase Array \endlink expression of this matrix * \sa ArrayBase::matrix() */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArrayWrapper<const Derived> array() const { return derived(); } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArrayWrapper<const Derived> array() const { return ArrayWrapper<const Derived>(derived()); } /////////// LU module /////////// diff --git a/Eigen/src/Core/NestByValue.h b/Eigen/src/Core/NestByValue.h index a893b1761..248dd8eb0 100644 --- a/Eigen/src/Core/NestByValue.h +++ b/Eigen/src/Core/NestByValue.h @@ -40,7 +40,7 @@ template<typename ExpressionType> class NestByValue typedef typename internal::dense_xpr_base<NestByValue>::type Base; EIGEN_DENSE_PUBLIC_INTERFACE(NestByValue) - inline NestByValue(const ExpressionType& matrix) : m_expression(matrix) {} + explicit inline NestByValue(const ExpressionType& matrix) : m_expression(matrix) {} inline Index rows() const { return m_expression.rows(); } inline Index cols() const { return m_expression.cols(); } diff --git a/Eigen/src/Core/NoAlias.h b/Eigen/src/Core/NoAlias.h index 097c9c062..0ade75255 100644 --- a/Eigen/src/Core/NoAlias.h +++ b/Eigen/src/Core/NoAlias.h @@ -33,7 +33,7 @@ class NoAlias public: typedef typename ExpressionType::Scalar Scalar; - NoAlias(ExpressionType& expression) : m_expression(expression) {} + explicit NoAlias(ExpressionType& expression) : m_expression(expression) {} template<typename OtherDerived> EIGEN_DEVICE_FUNC @@ -100,7 +100,7 @@ class NoAlias template<typename Derived> NoAlias<Derived,MatrixBase> MatrixBase<Derived>::noalias() { - return derived(); + return NoAlias<Derived, Eigen::MatrixBase >(derived()); } } // end namespace Eigen diff --git a/Eigen/src/Core/PermutationMatrix.h b/Eigen/src/Core/PermutationMatrix.h index 200518173..98c83047a 100644 --- a/Eigen/src/Core/PermutationMatrix.h +++ b/Eigen/src/Core/PermutationMatrix.h @@ -73,6 +73,7 @@ class PermutationBase : public EigenBase<Derived> typedef PermutationMatrix<IndicesType::SizeAtCompileTime,IndicesType::MaxSizeAtCompileTime,StorageIndexType> PlainPermutationType; using Base::derived; + typedef Transpose<PermutationBase> TransposeReturnType; #endif /** Copies the other permutation into *this */ @@ -198,14 +199,14 @@ class PermutationBase : public EigenBase<Derived> * * \note \note_try_to_help_rvo */ - inline Transpose<PermutationBase> inverse() const - { return derived(); } + inline TransposeReturnType inverse() const + { return TransposeReturnType(derived()); } /** \returns the tranpose permutation matrix. * * \note \note_try_to_help_rvo */ - inline Transpose<PermutationBase> transpose() const - { return derived(); } + inline TransposeReturnType transpose() const + { return TransposeReturnType(derived()); } /**** multiplication helpers to hopefully get RVO ****/ @@ -301,7 +302,7 @@ class PermutationMatrix : public PermutationBase<PermutationMatrix<SizeAtCompile /** Constructs an uninitialized permutation matrix of given size. */ - inline PermutationMatrix(Index size) : m_indices(size) + explicit inline PermutationMatrix(Index size) : m_indices(size) {} /** Copy constructor. */ diff --git a/Eigen/src/Core/PlainObjectBase.h b/Eigen/src/Core/PlainObjectBase.h index 0605e29aa..ec7621d09 100644 --- a/Eigen/src/Core/PlainObjectBase.h +++ b/Eigen/src/Core/PlainObjectBase.h @@ -457,7 +457,7 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type // FIXME is it still needed ? /** \internal */ EIGEN_DEVICE_FUNC - PlainObjectBase(internal::constructor_without_unaligned_array_assert) + explicit PlainObjectBase(internal::constructor_without_unaligned_array_assert) : m_storage(internal::constructor_without_unaligned_array_assert()) { // _check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED diff --git a/Eigen/src/Core/ProductEvaluators.h b/Eigen/src/Core/ProductEvaluators.h index f880e7696..69e569908 100644 --- a/Eigen/src/Core/ProductEvaluators.h +++ b/Eigen/src/Core/ProductEvaluators.h @@ -35,7 +35,7 @@ struct evaluator<Product<Lhs, Rhs, Options> > typedef evaluator type; typedef evaluator nestedType; - evaluator(const XprType& xpr) : Base(xpr) {} + explicit evaluator(const XprType& xpr) : Base(xpr) {} }; // Catch scalar * ( A * B ) and transform it to (A*scalar) * B @@ -50,7 +50,7 @@ struct evaluator<CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, const Produ typedef evaluator type; typedef evaluator nestedType; - evaluator(const XprType& xpr) + explicit evaluator(const XprType& xpr) : Base(xpr.functor().m_other * xpr.nestedExpression().lhs() * xpr.nestedExpression().rhs()) {} }; @@ -66,7 +66,7 @@ struct evaluator<Diagonal<const Product<Lhs, Rhs, DefaultProduct>, DiagIndex> > typedef evaluator type; typedef evaluator nestedType; - evaluator(const XprType& xpr) + explicit evaluator(const XprType& xpr) : Base(Diagonal<const Product<Lhs, Rhs, LazyProduct>, DiagIndex>( Product<Lhs, Rhs, LazyProduct>(xpr.nestedExpression().lhs(), xpr.nestedExpression().rhs()), xpr.index() )) @@ -103,7 +103,7 @@ struct product_evaluator<Product<Lhs, Rhs, DefaultProduct>, ProductTag, LhsShape typedef typename XprType::PlainObject PlainObject; typedef typename evaluator<PlainObject>::type Base; - product_evaluator(const XprType& xpr) + explicit product_evaluator(const XprType& xpr) : m_result(xpr.rows(), xpr.cols()) { ::new (static_cast<Base*>(this)) Base(m_result); @@ -242,7 +242,7 @@ struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,OuterProduct> struct sub { template<typename Dst, typename Src> void operator()(const Dst& dst, const Src& src) const { dst.const_cast_derived() -= src; } }; struct adds { Scalar m_scale; - adds(const Scalar& s) : m_scale(s) {} + explicit adds(const Scalar& s) : m_scale(s) {} template<typename Dst, typename Src> void operator()(const Dst& dst, const Src& src) const { dst.const_cast_derived() += m_scale * src; } @@ -377,7 +377,7 @@ struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, DenseShape, typedef typename XprType::PacketScalar PacketScalar; typedef typename XprType::PacketReturnType PacketReturnType; - product_evaluator(const XprType& xpr) + explicit product_evaluator(const XprType& xpr) : m_lhs(xpr.lhs()), m_rhs(xpr.rhs()), m_lhsImpl(m_lhs), // FIXME the creation of the evaluator objects should result in a no-op, but check that! @@ -508,7 +508,7 @@ struct product_evaluator<Product<Lhs, Rhs, DefaultProduct>, LazyCoeffBasedProduc typedef Product<Lhs, Rhs, DefaultProduct> XprType; typedef Product<Lhs, Rhs, LazyProduct> BaseProduct; typedef product_evaluator<BaseProduct, CoeffBasedProductMode, DenseShape, DenseShape, typename Lhs::Scalar, typename Rhs::Scalar > Base; - product_evaluator(const XprType& xpr) + explicit product_evaluator(const XprType& xpr) : Base(BaseProduct(xpr.lhs(),xpr.rhs())) {} }; @@ -739,7 +739,7 @@ struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DiagonalSha StorageOrder = int(Rhs::Flags) & RowMajorBit ? RowMajor : ColMajor }; - product_evaluator(const XprType& xpr) + explicit product_evaluator(const XprType& xpr) : Base(xpr.rhs(), xpr.lhs().diagonal()) { } @@ -783,7 +783,7 @@ struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DenseShape, enum { StorageOrder = int(Lhs::Flags) & RowMajorBit ? RowMajor : ColMajor }; - product_evaluator(const XprType& xpr) + explicit product_evaluator(const XprType& xpr) : Base(xpr.lhs(), xpr.rhs().diagonal()) { } diff --git a/Eigen/src/Core/Redux.h b/Eigen/src/Core/Redux.h index c6c355d43..14a2671e9 100644 --- a/Eigen/src/Core/Redux.h +++ b/Eigen/src/Core/Redux.h @@ -340,7 +340,7 @@ class redux_evaluator { public: typedef _XprType XprType; - redux_evaluator(const XprType &xpr) : m_evaluator(xpr), m_xpr(xpr) {} + explicit redux_evaluator(const XprType &xpr) : m_evaluator(xpr), m_xpr(xpr) {} typedef typename XprType::Index Index; typedef typename XprType::Scalar Scalar; diff --git a/Eigen/src/Core/ReturnByValue.h b/Eigen/src/Core/ReturnByValue.h index f4e12a93b..5fcd9e3fc 100644 --- a/Eigen/src/Core/ReturnByValue.h +++ b/Eigen/src/Core/ReturnByValue.h @@ -103,7 +103,7 @@ struct evaluator<ReturnByValue<Derived> > typedef evaluator type; typedef evaluator nestedType; - evaluator(const XprType& xpr) + explicit evaluator(const XprType& xpr) : m_result(xpr.rows(), xpr.cols()) { ::new (static_cast<Base*>(this)) Base(m_result); diff --git a/Eigen/src/Core/Reverse.h b/Eigen/src/Core/Reverse.h index 01de90800..9ba6ea2e6 100644 --- a/Eigen/src/Core/Reverse.h +++ b/Eigen/src/Core/Reverse.h @@ -89,7 +89,7 @@ template<typename MatrixType, int Direction> class Reverse typedef internal::reverse_packet_cond<PacketScalar,ReversePacket> reverse_packet; public: - inline Reverse(const MatrixType& matrix) : m_matrix(matrix) { } + explicit inline Reverse(const MatrixType& matrix) : m_matrix(matrix) { } EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Reverse) @@ -184,7 +184,7 @@ template<typename Derived> inline typename DenseBase<Derived>::ReverseReturnType DenseBase<Derived>::reverse() { - return derived(); + return ReverseReturnType(derived()); } /** This is the const version of reverse(). */ @@ -192,7 +192,7 @@ template<typename Derived> inline const typename DenseBase<Derived>::ConstReverseReturnType DenseBase<Derived>::reverse() const { - return derived(); + return ConstReverseReturnType(derived()); } /** This is the "in place" version of reverse: it reverses \c *this. diff --git a/Eigen/src/Core/SelfAdjointView.h b/Eigen/src/Core/SelfAdjointView.h index 19cb232c9..f5fbd7215 100644 --- a/Eigen/src/Core/SelfAdjointView.h +++ b/Eigen/src/Core/SelfAdjointView.h @@ -67,7 +67,7 @@ template<typename _MatrixType, unsigned int UpLo> class SelfAdjointView typedef typename MatrixType::PlainObject PlainObject; EIGEN_DEVICE_FUNC - inline SelfAdjointView(MatrixType& matrix) : m_matrix(matrix) + explicit inline SelfAdjointView(MatrixType& matrix) : m_matrix(matrix) {} EIGEN_DEVICE_FUNC @@ -258,7 +258,7 @@ template<unsigned int UpLo> typename MatrixBase<Derived>::template ConstSelfAdjointViewReturnType<UpLo>::Type MatrixBase<Derived>::selfadjointView() const { - return derived(); + return typename ConstSelfAdjointViewReturnType<UpLo>::Type(derived()); } template<typename Derived> @@ -266,7 +266,7 @@ template<unsigned int UpLo> typename MatrixBase<Derived>::template SelfAdjointViewReturnType<UpLo>::Type MatrixBase<Derived>::selfadjointView() { - return derived(); + return typename SelfAdjointViewReturnType<UpLo>::Type(derived()); } } // end namespace Eigen diff --git a/Eigen/src/Core/Solve.h b/Eigen/src/Core/Solve.h index 7b12be1e6..641ffa218 100644 --- a/Eigen/src/Core/Solve.h +++ b/Eigen/src/Core/Solve.h @@ -121,7 +121,7 @@ struct evaluator<Solve<Decomposition,RhsType> > typedef evaluator type; typedef evaluator nestedType; - evaluator(const SolveType& solve) + explicit evaluator(const SolveType& solve) : m_result(solve.rows(), solve.cols()) { ::new (static_cast<Base*>(this)) Base(m_result); diff --git a/Eigen/src/Core/Stride.h b/Eigen/src/Core/Stride.h index 187774978..e46faad34 100644 --- a/Eigen/src/Core/Stride.h +++ b/Eigen/src/Core/Stride.h @@ -93,7 +93,7 @@ class InnerStride : public Stride<0, Value> public: typedef DenseIndex Index; EIGEN_DEVICE_FUNC InnerStride() : Base() {} - EIGEN_DEVICE_FUNC InnerStride(Index v) : Base(0, v) {} + EIGEN_DEVICE_FUNC InnerStride(Index v) : Base(0, v) {} // FIXME making this explicit could break valid code }; /** \brief Convenience specialization of Stride to specify only an outer stride @@ -105,7 +105,7 @@ class OuterStride : public Stride<Value, 0> public: typedef DenseIndex Index; EIGEN_DEVICE_FUNC OuterStride() : Base() {} - EIGEN_DEVICE_FUNC OuterStride(Index v) : Base(v,0) {} + EIGEN_DEVICE_FUNC OuterStride(Index v) : Base(v,0) {} // FIXME making this explicit could break valid code }; } // end namespace Eigen diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 144bb2c01..57d6fd2fe 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -64,7 +64,7 @@ template<typename MatrixType> class Transpose typedef typename internal::remove_all<MatrixType>::type NestedExpression; EIGEN_DEVICE_FUNC - inline Transpose(MatrixType& a_matrix) : m_matrix(a_matrix) {} + explicit inline Transpose(MatrixType& a_matrix) : m_matrix(a_matrix) {} EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Transpose) @@ -169,7 +169,7 @@ template<typename Derived> inline Transpose<Derived> DenseBase<Derived>::transpose() { - return derived(); + return TransposeReturnType(derived()); } /** This is the const version of transpose(). @@ -207,8 +207,7 @@ template<typename Derived> inline const typename MatrixBase<Derived>::AdjointReturnType MatrixBase<Derived>::adjoint() const { - return this->transpose(); // in the complex case, the .conjugate() is be implicit here - // due to implicit conversion to return type + return AdjointReturnType(this->transpose()); } /*************************************************************************** diff --git a/Eigen/src/Core/Transpositions.h b/Eigen/src/Core/Transpositions.h index 92261118f..77e7d6f45 100644 --- a/Eigen/src/Core/Transpositions.h +++ b/Eigen/src/Core/Transpositions.h @@ -240,7 +240,7 @@ class Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndexTyp typedef typename IndicesType::Scalar StorageIndexType; typedef typename IndicesType::Index Index; - inline Map(const StorageIndexType* indicesPtr) + explicit inline Map(const StorageIndexType* indicesPtr) : m_indices(indicesPtr) {} @@ -299,7 +299,7 @@ class TranspositionsWrapper typedef typename IndicesType::Scalar StorageIndexType; typedef typename IndicesType::Index Index; - inline TranspositionsWrapper(IndicesType& a_indices) + explicit inline TranspositionsWrapper(IndicesType& a_indices) : m_indices(a_indices) {} @@ -414,7 +414,7 @@ class Transpose<TranspositionsBase<TranspositionsDerived> > typedef typename TranspositionType::IndicesType IndicesType; public: - Transpose(const TranspositionType& t) : m_transpositions(t) {} + explicit Transpose(const TranspositionType& t) : m_transpositions(t) {} inline int size() const { return m_transpositions.size(); } diff --git a/Eigen/src/Core/TriangularMatrix.h b/Eigen/src/Core/TriangularMatrix.h index 36f04a5e8..36bbd46e1 100644 --- a/Eigen/src/Core/TriangularMatrix.h +++ b/Eigen/src/Core/TriangularMatrix.h @@ -211,8 +211,9 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView IsVectorAtCompileTime = false }; + // FIXME This, combined with const_cast_derived in transpose() leads to a const-correctness loophole EIGEN_DEVICE_FUNC - inline TriangularView(const MatrixType& matrix) : m_matrix(matrix) + explicit inline TriangularView(const MatrixType& matrix) : m_matrix(matrix) {} using Base::operator=; @@ -229,32 +230,36 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView EIGEN_DEVICE_FUNC NestedExpression& nestedExpression() { return *const_cast<NestedExpression*>(&m_matrix); } + typedef TriangularView<MatrixConjugateReturnType,Mode> ConjugateReturnType; /** \sa MatrixBase::conjugate() */ EIGEN_DEVICE_FUNC - inline TriangularView<MatrixConjugateReturnType,Mode> conjugate() - { return m_matrix.conjugate(); } + inline ConjugateReturnType conjugate() + { return ConjugateReturnType(m_matrix.conjugate()); } /** \sa MatrixBase::conjugate() const */ + EIGEN_DEVICE_FUNC - inline const TriangularView<MatrixConjugateReturnType,Mode> conjugate() const - { return m_matrix.conjugate(); } + inline const ConjugateReturnType conjugate() const + { return ConjugateReturnType(m_matrix.conjugate()); } + typedef TriangularView<const typename MatrixType::AdjointReturnType,TransposeMode> AdjointReturnType; /** \sa MatrixBase::adjoint() const */ EIGEN_DEVICE_FUNC - inline const TriangularView<const typename MatrixType::AdjointReturnType,TransposeMode> adjoint() const - { return m_matrix.adjoint(); } + inline const AdjointReturnType adjoint() const + { return AdjointReturnType(m_matrix.adjoint()); } - /** \sa MatrixBase::transpose() */ + typedef TriangularView<Transpose<MatrixType>,TransposeMode> TransposeReturnType; + /** \sa MatrixBase::transpose() */ EIGEN_DEVICE_FUNC - inline TriangularView<Transpose<MatrixType>,TransposeMode> transpose() + inline TransposeReturnType transpose() { EIGEN_STATIC_ASSERT_LVALUE(MatrixType) - return m_matrix.const_cast_derived().transpose(); + return TransposeReturnType(m_matrix.const_cast_derived().transpose()); } /** \sa MatrixBase::transpose() const */ EIGEN_DEVICE_FUNC - inline const TriangularView<Transpose<MatrixType>,TransposeMode> transpose() const + inline const TransposeReturnType transpose() const { - return m_matrix.transpose(); + return TransposeReturnType(m_matrix.transpose()); } template<typename Other> @@ -556,7 +561,7 @@ template<unsigned int Mode> typename MatrixBase<Derived>::template TriangularViewReturnType<Mode>::Type MatrixBase<Derived>::triangularView() { - return derived(); + return typename TriangularViewReturnType<Mode>::Type(derived()); } /** This is the const version of MatrixBase::triangularView() */ @@ -565,7 +570,7 @@ template<unsigned int Mode> typename MatrixBase<Derived>::template ConstTriangularViewReturnType<Mode>::Type MatrixBase<Derived>::triangularView() const { - return derived(); + return typename ConstTriangularViewReturnType<Mode>::Type(derived()); } /** \returns true if *this is approximately equal to an upper triangular matrix, diff --git a/Eigen/src/Core/VectorwiseOp.h b/Eigen/src/Core/VectorwiseOp.h index a8130e902..e340c1433 100644 --- a/Eigen/src/Core/VectorwiseOp.h +++ b/Eigen/src/Core/VectorwiseOp.h @@ -65,7 +65,7 @@ class PartialReduxExpr : internal::no_assignment_operator, typedef typename internal::traits<PartialReduxExpr>::MatrixTypeNested MatrixTypeNested; typedef typename internal::traits<PartialReduxExpr>::_MatrixTypeNested _MatrixTypeNested; - PartialReduxExpr(const MatrixType& mat, const MemberOp& func = MemberOp()) + explicit PartialReduxExpr(const MatrixType& mat, const MemberOp& func = MemberOp()) : m_matrix(mat), m_functor(func) {} Index rows() const { return (Direction==Vertical ? 1 : m_matrix.rows()); } @@ -128,7 +128,7 @@ struct member_redux { >::type result_type; template<typename _Scalar, int Size> struct Cost { enum { value = (Size-1) * functor_traits<BinaryOp>::Cost }; }; - member_redux(const BinaryOp func) : m_functor(func) {} + member_redux(const BinaryOp func) : m_functor(func) {} // FIXME this should actually be explicit, but lets not exaggerate template<typename Derived> inline result_type operator()(const DenseBase<Derived>& mat) const { return mat.redux(m_functor); } @@ -249,7 +249,7 @@ template<typename ExpressionType, int Direction> class VectorwiseOp public: - inline VectorwiseOp(ExpressionType& matrix) : m_matrix(matrix) {} + explicit inline VectorwiseOp(ExpressionType& matrix) : m_matrix(matrix) {} /** \internal */ inline const ExpressionType& _expression() const { return m_matrix; } @@ -266,6 +266,21 @@ template<typename ExpressionType, int Direction> class VectorwiseOp redux(const BinaryOp& func = BinaryOp()) const { return typename ReduxReturnType<BinaryOp>::Type(_expression(), func); } + typedef typename ReturnType<internal::member_minCoeff>::Type MinCoeffReturnType; + typedef typename ReturnType<internal::member_maxCoeff>::Type MaxCoeffReturnType; + typedef typename ReturnType<internal::member_squaredNorm,RealScalar>::Type SquareNormReturnType; + typedef typename ReturnType<internal::member_norm,RealScalar>::Type NormReturnType; + typedef typename ReturnType<internal::member_blueNorm,RealScalar>::Type BlueNormReturnType; + typedef typename ReturnType<internal::member_stableNorm,RealScalar>::Type StableNormReturnType; + typedef typename ReturnType<internal::member_hypotNorm,RealScalar>::Type HypotNormReturnType; + typedef typename ReturnType<internal::member_sum>::Type SumReturnType; + typedef typename ReturnType<internal::member_mean>::Type MeanReturnType; + typedef typename ReturnType<internal::member_all>::Type AllReturnType; + typedef typename ReturnType<internal::member_any>::Type AnyReturnType; + typedef PartialReduxExpr<ExpressionType, internal::member_count<Index>, Direction> CountReturnType; + typedef typename ReturnType<internal::member_prod>::Type ProdReturnType; + typedef Reverse<ExpressionType, Direction> ReverseReturnType; + /** \returns a row (or column) vector expression of the smallest coefficient * of each column (or row) of the referenced expression. * @@ -275,8 +290,8 @@ template<typename ExpressionType, int Direction> class VectorwiseOp * Output: \verbinclude PartialRedux_minCoeff.out * * \sa DenseBase::minCoeff() */ - const typename ReturnType<internal::member_minCoeff>::Type minCoeff() const - { return _expression(); } + const MinCoeffReturnType minCoeff() const + { return MinCoeffReturnType(_expression()); } /** \returns a row (or column) vector expression of the largest coefficient * of each column (or row) of the referenced expression. @@ -287,8 +302,8 @@ template<typename ExpressionType, int Direction> class VectorwiseOp * Output: \verbinclude PartialRedux_maxCoeff.out * * \sa DenseBase::maxCoeff() */ - const typename ReturnType<internal::member_maxCoeff>::Type maxCoeff() const - { return _expression(); } + const MaxCoeffReturnType maxCoeff() const + { return MaxCoeffReturnType(_expression()); } /** \returns a row (or column) vector expression of the squared norm * of each column (or row) of the referenced expression. @@ -298,8 +313,8 @@ template<typename ExpressionType, int Direction> class VectorwiseOp * Output: \verbinclude PartialRedux_squaredNorm.out * * \sa DenseBase::squaredNorm() */ - const typename ReturnType<internal::member_squaredNorm,RealScalar>::Type squaredNorm() const - { return _expression(); } + const SquareNormReturnType squaredNorm() const + { return SquareNormReturnType(_expression()); } /** \returns a row (or column) vector expression of the norm * of each column (or row) of the referenced expression. @@ -309,8 +324,8 @@ template<typename ExpressionType, int Direction> class VectorwiseOp * Output: \verbinclude PartialRedux_norm.out * * \sa DenseBase::norm() */ - const typename ReturnType<internal::member_norm,RealScalar>::Type norm() const - { return _expression(); } + const NormReturnType norm() const + { return NormReturnType(_expression()); } /** \returns a row (or column) vector expression of the norm @@ -319,8 +334,8 @@ template<typename ExpressionType, int Direction> class VectorwiseOp * This is a vector with real entries, even if the original matrix has complex entries. * * \sa DenseBase::blueNorm() */ - const typename ReturnType<internal::member_blueNorm,RealScalar>::Type blueNorm() const - { return _expression(); } + const BlueNormReturnType blueNorm() const + { return BlueNormReturnType(_expression()); } /** \returns a row (or column) vector expression of the norm @@ -329,8 +344,8 @@ template<typename ExpressionType, int Direction> class VectorwiseOp * This is a vector with real entries, even if the original matrix has complex entries. * * \sa DenseBase::stableNorm() */ - const typename ReturnType<internal::member_stableNorm,RealScalar>::Type stableNorm() const - { return _expression(); } + const StableNormReturnType stableNorm() const + { return StableNormReturnType(_expression()); } /** \returns a row (or column) vector expression of the norm @@ -339,8 +354,8 @@ template<typename ExpressionType, int Direction> class VectorwiseOp * This is a vector with real entries, even if the original matrix has complex entries. * * \sa DenseBase::hypotNorm() */ - const typename ReturnType<internal::member_hypotNorm,RealScalar>::Type hypotNorm() const - { return _expression(); } + const HypotNormReturnType hypotNorm() const + { return HypotNormReturnType(_expression()); } /** \returns a row (or column) vector expression of the sum * of each column (or row) of the referenced expression. @@ -349,31 +364,31 @@ template<typename ExpressionType, int Direction> class VectorwiseOp * Output: \verbinclude PartialRedux_sum.out * * \sa DenseBase::sum() */ - const typename ReturnType<internal::member_sum>::Type sum() const - { return _expression(); } + const SumReturnType sum() const + { return SumReturnType(_expression()); } /** \returns a row (or column) vector expression of the mean * of each column (or row) of the referenced expression. * * \sa DenseBase::mean() */ - const typename ReturnType<internal::member_mean>::Type mean() const - { return _expression(); } + const MeanReturnType mean() const + { return MeanReturnType(_expression()); } /** \returns a row (or column) vector expression representing * whether \b all coefficients of each respective column (or row) are \c true. * This expression can be assigned to a vector with entries of type \c bool. * * \sa DenseBase::all() */ - const typename ReturnType<internal::member_all>::Type all() const - { return _expression(); } + const AllReturnType all() const + { return AllReturnType(_expression()); } /** \returns a row (or column) vector expression representing * whether \b at \b least one coefficient of each respective column (or row) is \c true. * This expression can be assigned to a vector with entries of type \c bool. * * \sa DenseBase::any() */ - const typename ReturnType<internal::member_any>::Type any() const - { return _expression(); } + const AnyReturnType any() const + { return Any(_expression()); } /** \returns a row (or column) vector expression representing * the number of \c true coefficients of each respective column (or row). @@ -384,8 +399,8 @@ template<typename ExpressionType, int Direction> class VectorwiseOp * Output: \verbinclude PartialRedux_count.out * * \sa DenseBase::count() */ - const PartialReduxExpr<ExpressionType, internal::member_count<Index>, Direction> count() const - { return _expression(); } + const CountReturnType count() const + { return CountReturnType(_expression()); } /** \returns a row (or column) vector expression of the product * of each column (or row) of the referenced expression. @@ -394,8 +409,8 @@ template<typename ExpressionType, int Direction> class VectorwiseOp * Output: \verbinclude PartialRedux_prod.out * * \sa DenseBase::prod() */ - const typename ReturnType<internal::member_prod>::Type prod() const - { return _expression(); } + const ProdReturnType prod() const + { return ProdReturnType(_expression()); } /** \returns a matrix expression @@ -405,8 +420,8 @@ template<typename ExpressionType, int Direction> class VectorwiseOp * Output: \verbinclude Vectorwise_reverse.out * * \sa DenseBase::reverse() */ - const Reverse<ExpressionType, Direction> reverse() const - { return Reverse<ExpressionType, Direction>( _expression() ); } + const ReverseReturnType reverse() const + { return ReverseReturnType( _expression() ); } typedef Replicate<ExpressionType,Direction==Vertical?Dynamic:1,Direction==Horizontal?Dynamic:1> ReplicateReturnType; const ReplicateReturnType replicate(Index factor) const; @@ -550,7 +565,8 @@ template<typename ExpressionType, int Direction> class VectorwiseOp /////////// Geometry module /////////// - Homogeneous<ExpressionType,Direction> homogeneous() const; + typedef Homogeneous<ExpressionType,Direction> HomogeneousReturnType; + HomogeneousReturnType homogeneous() const; typedef typename ExpressionType::PlainObject CrossReturnType; template<typename OtherDerived> @@ -595,7 +611,7 @@ template<typename Derived> inline const typename DenseBase<Derived>::ConstColwiseReturnType DenseBase<Derived>::colwise() const { - return derived(); + return ConstColwiseReturnType(derived()); } /** \returns a writable VectorwiseOp wrapper of *this providing additional partial reduction operations @@ -606,7 +622,7 @@ template<typename Derived> inline typename DenseBase<Derived>::ColwiseReturnType DenseBase<Derived>::colwise() { - return derived(); + return ColwiseReturnType(derived()); } /** \returns a VectorwiseOp wrapper of *this providing additional partial reduction operations @@ -620,7 +636,7 @@ template<typename Derived> inline const typename DenseBase<Derived>::ConstRowwiseReturnType DenseBase<Derived>::rowwise() const { - return derived(); + return ConstRowwiseReturnType(derived()); } /** \returns a writable VectorwiseOp wrapper of *this providing additional partial reduction operations @@ -631,7 +647,7 @@ template<typename Derived> inline typename DenseBase<Derived>::RowwiseReturnType DenseBase<Derived>::rowwise() { - return derived(); + return RowwiseReturnType(derived()); } } // end namespace Eigen diff --git a/Eigen/src/Core/Visitor.h b/Eigen/src/Core/Visitor.h index 810ec28e7..02bd4eff3 100644 --- a/Eigen/src/Core/Visitor.h +++ b/Eigen/src/Core/Visitor.h @@ -58,7 +58,7 @@ template<typename XprType> class visitor_evaluator { public: - visitor_evaluator(const XprType &xpr) : m_evaluator(xpr), m_xpr(xpr) {} + explicit visitor_evaluator(const XprType &xpr) : m_evaluator(xpr), m_xpr(xpr) {} typedef typename XprType::Index Index; typedef typename XprType::Scalar Scalar; diff --git a/Eigen/src/Core/products/SelfadjointRank2Update.h b/Eigen/src/Core/products/SelfadjointRank2Update.h index 8594a97ce..2ae364111 100644 --- a/Eigen/src/Core/products/SelfadjointRank2Update.h +++ b/Eigen/src/Core/products/SelfadjointRank2Update.h @@ -79,11 +79,11 @@ SelfAdjointView<MatrixType,UpLo>& SelfAdjointView<MatrixType,UpLo> if (IsRowMajor) actualAlpha = numext::conj(actualAlpha); - internal::selfadjoint_rank2_update_selector<Scalar, Index, - typename internal::remove_all<typename internal::conj_expr_if<IsRowMajor ^ UBlasTraits::NeedToConjugate,_ActualUType>::type>::type, - typename internal::remove_all<typename internal::conj_expr_if<IsRowMajor ^ VBlasTraits::NeedToConjugate,_ActualVType>::type>::type, + typedef typename internal::remove_all<typename internal::conj_expr_if<IsRowMajor ^ UBlasTraits::NeedToConjugate,_ActualUType>::type>::type UType; + typedef typename internal::remove_all<typename internal::conj_expr_if<IsRowMajor ^ VBlasTraits::NeedToConjugate,_ActualVType>::type>::type VType; + internal::selfadjoint_rank2_update_selector<Scalar, Index, UType, VType, (IsRowMajor ? int(UpLo==Upper ? Lower : Upper) : UpLo)> - ::run(_expression().const_cast_derived().data(),_expression().outerStride(),actualU,actualV,actualAlpha); + ::run(_expression().const_cast_derived().data(),_expression().outerStride(),UType(actualU),VType(actualV),actualAlpha); return *this; } diff --git a/Eigen/src/Core/util/BlasUtil.h b/Eigen/src/Core/util/BlasUtil.h index 0d8e2705a..9f9115c2a 100644 --- a/Eigen/src/Core/util/BlasUtil.h +++ b/Eigen/src/Core/util/BlasUtil.h @@ -231,7 +231,7 @@ struct blas_traits<Transpose<NestedXpr> > enum { IsTransposed = Base::IsTransposed ? 0 : 1 }; - static inline ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); } + static inline ExtractType extract(const XprType& x) { return ExtractType(Base::extract(x.nestedExpression())); } static inline Scalar extractScalarFactor(const XprType& x) { return Base::extractScalarFactor(x.nestedExpression()); } }; |