From: wolf Date: Thu, 9 Aug 2001 12:18:19 +0000 (+0000) Subject: New constructor for Vector<...> that takes two iterators the range of which is then... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8a03e1a7c06e1100a37a494a7ff0f251e1c01a8;p=dealii-svn.git New constructor for Vector<...> that takes two iterators the range of which is then copied. git-svn-id: https://svn.dealii.org/trunk@4871 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/2001/c-3-1.html b/deal.II/doc/news/2001/c-3-1.html index cf4eb1ef51..ee4dc6318a 100644 --- a/deal.II/doc/news/2001/c-3-1.html +++ b/deal.II/doc/news/2001/c-3-1.html @@ -332,6 +332,14 @@ documentation, etc.

lac

    +
  1. + Changed: The Vector class can now be + initialized using a new constructor that takes two iterators + that denote a range of elements which are to be copied. +
    + (WB 2001/08/08) +

    +
  2. Changed: The SolverCG class now saves the initial matrix vector product if the initial value of diff --git a/deal.II/lac/include/lac/vector.h b/deal.II/lac/include/lac/vector.h index 0ada7046db..60bd884573 100644 --- a/deal.II/lac/include/lac/vector.h +++ b/deal.II/lac/include/lac/vector.h @@ -52,14 +52,14 @@ class Vector * those in the @p{C++} standard libraries * @p{vector<...>} class. */ - typedef Number value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type* iterator; - typedef const value_type* const_iterator; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef size_t size_type; + typedef Number value_type; + typedef value_type *pointer; + typedef const value_type *const_pointer; + typedef value_type *iterator; + typedef const value_type *const_iterator; + typedef value_type &reference; + typedef const value_type &const_reference; + typedef size_t size_type; /** @@ -101,6 +101,16 @@ class Vector * initialize all elements with zero. */ Vector (const unsigned int n); + + /** + * Initialize the vector with a + * given range of values pointed + * to by the iterators. This + * function is there in analogy + * to the @p{std::vector} class. + */ + template + Vector (const InputIterator first, const InputIterator last); /** * Destructor, deallocates @@ -521,6 +531,24 @@ Vector::Vector () : {} + +template +template +Vector::Vector (const InputIterator first, const InputIterator last) + : + dim (0), + maxdim (0), + val (0) +{ + // allocate memory. do not + // initialize it, as we will copy + // over to it in a second + reinit (std::distance (first, last), true); + std::copy (first, last, begin()); +}; + + + template inline Vector::Vector (const unsigned int n) : @@ -546,7 +574,8 @@ Vector::~Vector () template inline -void Vector::reinit (const unsigned int n, const bool fast) { +void Vector::reinit (const unsigned int n, const bool fast) +{ if (n==0) { if (val) delete[] val; diff --git a/deal.II/lac/include/lac/vector.templates.h b/deal.II/lac/include/lac/vector.templates.h index 682610b6e1..644bc76402 100644 --- a/deal.II/lac/include/lac/vector.templates.h +++ b/deal.II/lac/include/lac/vector.templates.h @@ -500,7 +500,7 @@ Vector::operator = (const Vector& v) template -template +template Vector& Vector::operator = (const Vector& v) { diff --git a/tests/lac/vector-vector.cc b/tests/lac/vector-vector.cc index bbb6f51145..d37aed418d 100644 --- a/tests/lac/vector-vector.cc +++ b/tests/lac/vector-vector.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1998, 1999, 2000 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -65,6 +65,11 @@ void check_vectors (Vector &d1, Vector &d2) d1 = 2.5; print (d1); + + // initialize with iterators + number1 array[] = { 0.0, 1.1, 2.2, 3.3 }; + Vector d4 (&array[0], &array[4]); + print (d4); deallog << "Extract number" << std::endl; // Each line should contain two equal numbers diff --git a/tests/lac/vector-vector.checked b/tests/lac/vector-vector.checked index 38d8d968a7..9d694f85f6 100644 --- a/tests/lac/vector-vector.checked +++ b/tests/lac/vector-vector.checked @@ -7,6 +7,7 @@ DEAL::2.00 1.50 1.00 0.50 0.00 -0.50 -1.00 -1.50 -2.00 -2.50 DEAL::0.00 2.00 8.00 18.00 32.00 50.00 72.00 98.00 128.00 162.00 DEAL::0.00 2.00 4.00 6.00 8.00 10.00 12.00 14.00 16.00 18.00 DEAL::2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 +DEAL::0.00 1.10 2.20 3.30 DEAL::Extract number DEAL::-105.00 -105.00 DEAL::1140.00 1140.00 @@ -37,6 +38,7 @@ DEAL::2.00 1.50 1.00 0.50 0.00 -0.50 -1.00 -1.50 -2.00 -2.50 DEAL::0.00 2.00 8.00 18.00 32.00 50.00 72.00 98.00 128.00 162.00 DEAL::0.00 2.00 4.00 6.00 8.00 10.00 12.00 14.00 16.00 18.00 DEAL::2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 +DEAL::0.00 1.10 2.20 3.30 DEAL::Extract number DEAL::-105.00 -105.00 DEAL::1140.00 1140.00 @@ -67,6 +69,7 @@ DEAL::2.00 1.50 1.00 0.50 0.00 -0.50 -1.00 -1.50 -2.00 -2.50 DEAL::0.00 2.00 8.00 18.00 32.00 50.00 72.00 98.00 128.00 162.00 DEAL::0.00 2.00 4.00 6.00 8.00 10.00 12.00 14.00 16.00 18.00 DEAL::2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 +DEAL::0.00 1.10 2.20 3.30 DEAL::Extract number DEAL::-105.00 -105.00 DEAL::1140.00 1140.00