diff --git a/dune/common/fmatrix.hh b/dune/common/fmatrix.hh index 43d715ed2cae6efad120c732ecf37752d26eee93..d57af2dba95b2b2089d7affa4f4debda91d06c14 100644 --- a/dune/common/fmatrix.hh +++ b/dune/common/fmatrix.hh @@ -7,6 +7,7 @@ #include <cmath> #include <cstddef> #include <iostream> +#include <algorithm> #include <initializer_list> #include <dune/common/exceptions.hh> @@ -100,21 +101,19 @@ namespace Dune */ FieldMatrix (std::initializer_list<std::initializer_list<K> > const &ll) { - assert(ll.size() == rows); - size_t i = 0; - for (typename std::initializer_list<std::initializer_list<K> >:: - const_iterator lit = ll.begin(); lit != ll.end(); ++lit) - _data[i++] = *lit; + assert(ll.size() == rows); // Actually, this is not needed any more! + std::copy_n(ll.begin(), std::min(static_cast<std::size_t>(ROWS), + ll.size()), + _data.begin()); } /** \brief Constructor initializing the matrix from a list of vector */ FieldMatrix(std::initializer_list<Dune::FieldVector<K, cols> > const &l) { - assert(l.size() == rows); - size_t i = 0; - for (typename std::initializer_list<Dune::FieldVector<K, cols> >:: - const_iterator lit = l.begin(); lit != l.end(); ++lit) - _data[i++] = *lit; + assert(l.size() == rows); // Actually, this is not needed any more! + std::copy_n(l.begin(), std::min(static_cast<std::size_t>(ROWS), + l.size()), + _data.begin()); } //===== assignment diff --git a/dune/common/fvector.hh b/dune/common/fvector.hh index bc212c1e5c1de8536c9f3d978f7d43d740352332..606e6be5c8cf453de701d60c650fab171a740b58 100644 --- a/dune/common/fvector.hh +++ b/dune/common/fvector.hh @@ -11,6 +11,7 @@ #include <cstring> #include <utility> #include <initializer_list> +#include <algorithm> #include <dune/common/std/constexpr.hh> @@ -119,11 +120,10 @@ namespace Dune { FieldVector (std::initializer_list<K> const &l) { - assert(l.size() == dimension); - size_t i = 0; - for (typename std::initializer_list<K>::const_iterator it = l.begin(); - it != l.end(); ++it) - _data[i++] = *it; + assert(l.size() == dimension);// Actually, this is not needed any more! + std::copy_n(l.begin(), std::min(static_cast<std::size_t>(dimension), + l.size()), + _data.begin()); } /** @@ -142,9 +142,8 @@ namespace Dune { { DUNE_UNUSED_PARAMETER(dummy); // do a run-time size check, for the case that x is not a FieldVector - assert(x.size() == SIZE); - for (size_type i = 0; i<SIZE; i++) - _data[i] = x[i]; + assert(x.size() == SIZE); // Actually this is not needed any more! + std::copy_n(x.begin(), std::min(static_cast<std::size_t>(SIZE),x.size()), _data.begin()); } //! Constructor making vector with identical coordinates