aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/PlainObjectBase.h
diff options
context:
space:
mode:
authorGravatar David Tellenbach <david.tellenbach@tellnotes.org>2019-01-23 00:07:19 +0100
committerGravatar David Tellenbach <david.tellenbach@tellnotes.org>2019-01-23 00:07:19 +0100
commit237b03b3724df7137e82512cd7ad758e20b8e6b6 (patch)
tree05299915caad11764673aed317c8c9c8eae8fa9b /Eigen/src/Core/PlainObjectBase.h
parentbd6dadcda8974622bdc4c731068e4b3cf84bcf9c (diff)
PR 574: use variadic template instead of initializer_list to implement fixed-size vector ctor from coefficients.
Diffstat (limited to 'Eigen/src/Core/PlainObjectBase.h')
-rw-r--r--Eigen/src/Core/PlainObjectBase.h37
1 files changed, 22 insertions, 15 deletions
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