PR 574: use variadic template instead of initializer_list to implement fixed-size vector ctor from coefficients.

This commit is contained in:
David Tellenbach
2019-01-23 00:07:19 +01:00
parent bd6dadcda8
commit 237b03b372
8 changed files with 55 additions and 48 deletions

View File

@@ -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