diff options
author | David Tellenbach <david.tellenbach@tellnotes.org> | 2019-01-23 00:07:19 +0100 |
---|---|---|
committer | David Tellenbach <david.tellenbach@tellnotes.org> | 2019-01-23 00:07:19 +0100 |
commit | 237b03b3724df7137e82512cd7ad758e20b8e6b6 (patch) | |
tree | 05299915caad11764673aed317c8c9c8eae8fa9b /Eigen/src | |
parent | bd6dadcda8974622bdc4c731068e4b3cf84bcf9c (diff) |
PR 574: use variadic template instead of initializer_list to implement fixed-size vector ctor from coefficients.
Diffstat (limited to 'Eigen/src')
-rw-r--r-- | Eigen/src/Core/Array.h | 27 | ||||
-rw-r--r-- | Eigen/src/Core/Matrix.h | 21 | ||||
-rw-r--r-- | Eigen/src/Core/PlainObjectBase.h | 37 |
3 files changed, 46 insertions, 39 deletions
diff --git a/Eigen/src/Core/Array.h b/Eigen/src/Core/Array.h index ff0b69b84..3a2a4fc58 100644 --- a/Eigen/src/Core/Array.h +++ b/Eigen/src/Core/Array.h @@ -183,10 +183,10 @@ class Array protected: enum { IsFixedSizeVectorAtCompileTime = RowsAtCompileTime != Dynamic && ColsAtCompileTime != Dynamic && IsVectorAtCompileTime == 1 }; public: - template<typename T, - typename = typename internal::enable_if<IsFixedSizeVectorAtCompileTime && internal::is_same<T, Scalar>::value>::type> - EIGEN_DEVICE_FUNC - explicit EIGEN_STRONG_INLINE Array(const std::initializer_list<T>& list) : Base(list) {} + template <typename... ArgTypes> + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) + : Base(a0, a1, a2, a3, args...) {} EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array(const std::initializer_list<std::initializer_list<Scalar> >& list) : Base(list) {} @@ -214,15 +214,16 @@ class Array /** constructs an initialized 2D vector with given coefficients */ Array(const Scalar& val0, const Scalar& val1); - /** \copydoc PlainObjectBase::PlainObjectBase(const std::initializer_list<Scalar>& list) - * - * Example: \include Array_initializer_list2_cxx11.cpp - * Output: \verbinclude Array_initializer_list2_cxx11.out - * - * \sa Array(const std::initializer_list<std::initializer_list<Scalar> >&) - */ - EIGEN_DEVICE_FUNC - explicit EIGEN_STRONG_INLINE Array(const std::initializer_list<Scalar>& list); + /** \copydoc PlainObjectBase(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) + * + * Example: \include Array_variadic_ctor_cxx11.cpp + * Output: \verbinclude Array_variadic_ctor_cxx11.out + * + * \sa Array(const std::initializer_list<std::initializer_list<Scalar>>&) + */ + template <typename... ArgTypes> + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args); /** \brief Constructs an array and initializes it from the coefficients given as initializer-lists grouped by row. \cpp11 * diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index aaceceafe..fb2a62a82 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -303,13 +303,11 @@ class Matrix } #if EIGEN_HAS_CXX11 - protected: - enum { IsFixedSizeVectorAtCompileTime = RowsAtCompileTime != Dynamic && ColsAtCompileTime != Dynamic && IsVectorAtCompileTime == 1 }; public: - template<typename T, - typename = typename internal::enable_if<IsFixedSizeVectorAtCompileTime && internal::is_same<T, Scalar>::value>::type> - EIGEN_DEVICE_FUNC - explicit EIGEN_STRONG_INLINE Matrix(const std::initializer_list<T>& list) : Base(list) {} + template <typename... ArgTypes> + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + Matrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) + : Base(a0, a1, a2, a3, args...) {} EIGEN_DEVICE_FUNC explicit EIGEN_STRONG_INLINE Matrix(const std::initializer_list<std::initializer_list<Scalar>>& list) : Base(list) {} @@ -353,15 +351,16 @@ class Matrix /** \brief Constructs an initialized 2D vector with given coefficients */ Matrix(const Scalar& x, const Scalar& y); - /** \copydoc PlainObjectBase::PlainObjectBase(const std::initializer_list<Scalar>& list) + /** \copydoc PlainObjectBase(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) * - * Example: \include Matrix_initializer_list2_cxx11.cpp - * Output: \verbinclude Matrix_initializer_list2_cxx11.out + * Example: \include Matrix_variadic_ctor_cxx11.cpp + * Output: \verbinclude Matrix_variadic_ctor_cxx11.out * * \sa Matrix(const std::initializer_list<std::initializer_list<Scalar>>&) */ - EIGEN_DEVICE_FUNC - explicit EIGEN_STRONG_INLINE Matrix(const std::initializer_list<Scalar>& list); + template <typename... ArgTypes> + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + Matrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args); /** \brief Constructs a Matrix and initializes it from the coefficients given as initializer-lists grouped by row. \cpp11 * diff --git a/Eigen/src/Core/PlainObjectBase.h b/Eigen/src/Core/PlainObjectBase.h index 04748e5e9..cd89fd365 100644 --- a/Eigen/src/Core/PlainObjectBase.h +++ b/Eigen/src/Core/PlainObjectBase.h @@ -527,15 +527,16 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type } #ifdef EIGEN_PARSED_BY_DOXYGEN - /** \brief Construct a row of column vector with fixed size from an initializer list of coefficients. \cpp11 + /** \brief Construct a row of column vector with fixed size from an arbitrary number of coefficients. \cpp11 * * \only_for_vectors * - * \warning To construct a column (resp. row) vector of fixed length, the number of values passed through - * the initializer list must match the the fixed number of rows (resp. columns) of \c *this. + * \warning To construct a column (resp. row) vector of fixed length, the number of values passed to this + * constructor must match the the fixed number of rows (resp. columns) of \c *this. */ - EIGEN_DEVICE_FUNC - explicit EIGEN_STRONG_INLINE PlainObjectBase(const std::initializer_list<Scalar>& list); + template <typename... ArgTypes> + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + PlainObjectBase(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args); /** \brief Constructs a Matrix or Array and initializes it by elements given by an initializer list of initializer * lists \cpp11 @@ -544,19 +545,25 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type explicit EIGEN_STRONG_INLINE PlainObjectBase(const std::initializer_list<std::initializer_list<Scalar>>& list); #else // EIGEN_PARSED_BY_DOXYGEN #if EIGEN_HAS_CXX11 - template<typename T> - EIGEN_DEVICE_FUNC - explicit EIGEN_STRONG_INLINE PlainObjectBase(const std::initializer_list<T>& list, - typename internal::enable_if<internal::is_same<T, Scalar>::value, T>::type* = 0, - typename internal::enable_if<RowsAtCompileTime != Dynamic - && ColsAtCompileTime != Dynamic - && IsVectorAtCompileTime == 1, T>::type* = 0) + + protected: + enum { IsFixedSizeVectorAtCompileTime = RowsAtCompileTime != Dynamic && ColsAtCompileTime != Dynamic && IsVectorAtCompileTime == 1 }; + public: + + template <typename... ArgTypes> + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + PlainObjectBase(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) : m_storage() { _check_template_params(); - EIGEN_STATIC_ASSERT_FIXED_SIZE(PlainObjectBase); - resize(list.size()); - std::copy(list.begin(), list.end(), m_storage.data()); + EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, sizeof...(args) + 4); + m_storage.data()[0] = a0; + m_storage.data()[1] = a1; + m_storage.data()[2] = a2; + m_storage.data()[3] = a3; + int i = 4; + auto x = {(m_storage.data()[i++] = args, 0)...}; + static_cast<void>(x); } EIGEN_DEVICE_FUNC |