Add array::assign
This commit is contained in:
parent
35de0993d2
commit
a397a21628
1 changed files with 12 additions and 0 deletions
|
|
@ -122,6 +122,8 @@ namespace psemek::util
|
|||
|
||||
void resize(dims_type const & dims, T const & value);
|
||||
|
||||
void assign(dims_type const & dims, T const & value);
|
||||
|
||||
T * data() { return data_.get(); }
|
||||
T const * data() const { return data_.get(); }
|
||||
|
||||
|
|
@ -394,6 +396,16 @@ namespace psemek::util
|
|||
resize_impl(std::move(data), dims);
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
void array<T, N>::assign(dims_type const & dims, T const & value)
|
||||
{
|
||||
auto const size = detail::product(dims);
|
||||
std::unique_ptr<T[]> data(new T[size]);
|
||||
std::fill(data.get(), data.get() + size, value);
|
||||
data_ = std::move(data);
|
||||
dims_ = dims;
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
std::unique_ptr<T[]> array<T, N>::release()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue