Skip to content
Snippets Groups Projects
Commit d498dcb6 authored by Oliver Sander's avatar Oliver Sander
Browse files

Implement construction of a BlockVector from a std::initializer_list

parent fd509600
No related branches found
No related tags found
No related merge requests found
......@@ -303,6 +303,26 @@ namespace Dune {
}
}
/** \brief Construct from a std::initializer_list */
BlockVector (std::initializer_list<B> const &l)
{
this->n = l.size();
capacity_ = l.size();
if (capacity_>0) {
this->p = this->allocator_.allocate(capacity_);
// actually construct the objects
new(this->p)B[capacity_];
std::copy_n(l.begin(), l.size(), this->p);
} else
{
this->p = 0;
this->n = 0;
capacity_ = 0;
}
}
/** \brief Make vector with _n components but preallocating capacity components
If _n > capacity then space for _n entries is allocated.
......
......@@ -134,6 +134,13 @@ int main()
VectorOfVector vv;
vv.two_norm();
// Test construction from initializer_list
Vector fromInitializerList = {0,1,2};
assert(fromInitializerList.size() == 3);
assert(fromInitializerList[0] == value_type(0));
assert(fromInitializerList[1] == value_type(1));
assert(fromInitializerList[2] == value_type(2));
int ret = 0;
ret += testVector<1>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment