mirror of https://github.com/QMCPACK/qmcpack.git
Merge pull request #622 from ye-luo/init-Vector-val
Initialize Vector value similarly to std::vector.
This commit is contained in:
commit
bb143b5615
|
@ -43,12 +43,12 @@ public:
|
|||
|
||||
/** constructor with size n*/
|
||||
explicit inline
|
||||
Vector(size_t n=0): nLocal(n), nAllocated(0), X(nullptr)
|
||||
Vector(size_t n=0, Type_t val = Type_t()): nLocal(n), nAllocated(0), X(nullptr)
|
||||
{
|
||||
if(n)
|
||||
{
|
||||
resize_impl(n);
|
||||
std::fill_n(X, n, T());
|
||||
std::fill_n(X, n, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,14 +117,19 @@ public:
|
|||
}
|
||||
|
||||
///resize
|
||||
inline void resize(size_t n)
|
||||
inline void resize(size_t n, Type_t val = Type_t())
|
||||
{
|
||||
if(nLocal>nAllocated)
|
||||
throw std::runtime_error("Resize not allowed on Vector constructed by initialized memory.");
|
||||
if(n>nAllocated)
|
||||
{
|
||||
resize_impl(n);
|
||||
std::fill_n(X, n, T());
|
||||
std::fill_n(X, n, val);
|
||||
}
|
||||
else if(n>nLocal)
|
||||
{
|
||||
std::fill_n(X+nLocal, n-nLocal, val);
|
||||
nLocal=n;
|
||||
}
|
||||
else
|
||||
nLocal=n;
|
||||
|
|
Loading…
Reference in New Issue