From 9680c3081018ac9346c9bb4f671f913e3ae2e562 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 28 Mar 2019 09:00:42 -0600 Subject: [PATCH] Allow initialization of Vector with std::initializer_list. --- include/deal.II/lac/vector.h | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/include/deal.II/lac/vector.h b/include/deal.II/lac/vector.h index 5ba9658531..7372650b49 100644 --- a/include/deal.II/lac/vector.h +++ b/include/deal.II/lac/vector.h @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -164,14 +165,34 @@ public: Vector(Vector &&v) noexcept = default; /** - * Copy constructor taking a vector of another data type. This will fail if - * there is no conversion path from @p OtherNumber to @p Number. Note that - * you may lose accuracy when copying to a vector with data elements with + * Copy constructor taking a vector of another data type. + * + * This constructor will fail to compile if + * there is no conversion path from @p OtherNumber to @p Number. You may + * lose accuracy when copying to a vector with data elements with * less accuracy. */ template explicit Vector(const Vector &v); + /** + * Copy constructor taking an object of type `std::initializer_list`. This + * constructor can be used to initialize a vector using a brace-enclosed + * list of numbers, such as in the following example: + * @code + * Vector v({1,2,3}); + * @endcode + * This creates a vector of size 3, whose (double precision) elements have + * values 1.0, 2.0, and 3.0. + * + * This constructor will fail to compile if + * there is no conversion path from @p OtherNumber to @p Number. You may + * lose accuracy when copying to a vector with data elements with + * less accuracy. + */ + template + explicit Vector(const std::initializer_list &v); + #ifdef DEAL_II_WITH_PETSC /** * Another copy constructor: copy the values from a PETSc vector class. This @@ -1049,6 +1070,14 @@ inline Vector::Vector() +template +template +Vector::Vector(const std::initializer_list &v) + : Vector(v.begin(), v.end()) +{} + + + template template Vector::Vector(const InputIterator first, const InputIterator last) -- 2.39.5