*/
BlockVector (const std::vector<unsigned int> &n);
+ /**
+ * Constructor. Set the number of
+ * blocks to
+ * @p{n.size()}. Initialize the
+ * vector with the elements
+ * pointed to by the range of
+ * iterators given as second and
+ * third argument. Apart from the
+ * first argument, this
+ * constructor is in complete
+ * analogy to the respective
+ * constructor of the
+ * @p{std::vector} class, but the
+ * first argument is needed in
+ * order to know how to subdivide
+ * the block vector into
+ * different blocks.
+ */
+ template <typename InputIterator>
+ BlockVector (const std::vector<unsigned int> &n,
+ const InputIterator first,
+ const InputIterator end);
+
/**
* Destructor. Clears memory
*/
//@}
+ /**
+ * Exception
+ */
+ DeclException0 (ExcIteratorRangeDoesNotMatchVectorSize);
+
protected:
/**
* Pointer to the array of components.
/*----------------------- Inline functions ----------------------------------*/
+template <typename Number>
+template <typename InputIterator>
+BlockVector<Number>::BlockVector (const std::vector<unsigned int> &n,
+ const InputIterator first,
+ const InputIterator end)
+{
+ // first set sizes of blocks, but
+ // don't initialize them as we will
+ // copy elements soon
+ reinit (n, true);
+ InputIterator start = first;
+ for (unsigned int b=0; b<n.size(); ++b)
+ {
+ InputIterator end = start;
+ std::advance (end, static_cast<signed int>(n[b]));
+ std::copy (start, end, block(b).begin());
+ start = end;
+ };
+ Assert (start == end, ExcIteratorRangeDoesNotMatchVectorSize());
+};
+
+
+
+
template <typename Number>
inline
unsigned int BlockVector<Number>::size () const
#include <lac/block_vector.h>
#include <fstream>
#include <vector>
+#include <list>
void test ()
{
<< std::endl;
deallog.pop();
+
+ // initialization by an iterator
+ // range
+ deallog.push ("Initialization from iterators");
+ double array[] = { 0, 1, 2, 3, 4, 5 };
+ BlockVector<double> v1(ivector, &array[0], &array[6]);
+ for (unsigned int i=0; i<v1.size(); ++i)
+ deallog << v1(i) << ' ';
+ deallog << std::endl;
+
+ // same test, but do not initialize
+ // from double*'s, but from
+ // std::list iterators.
+ std::list<double> l(&array[0], &array[6]);
+ BlockVector<double> v2(ivector, l.begin(), l.end());
+ for (unsigned int i=0; i<v2.size(); ++i)
+ deallog << v2(i) << ' ';
+ deallog << std::endl;
+ deallog.pop ();
+
+
i3.reinit(ivector);
deallog.push("global->local");