Skip to content

Commit

Permalink
Add PODVector::assign(value) (#3866)
Browse files Browse the repository at this point in the history
## Summary

```
vector.assign(vector.size(), 42);
```
is a bit verbose for a standard operation, even if it mirrors
https://en.cppreference.com/w/cpp/container/vector/assign

Add another overload similar to `setVal(ue)` used in other AMReX
containers.

## Additional background

AMReX-Codes/pyamrex#222 (comment)

## Checklist

The proposed changes:
- [ ] fix a bug or incorrect behavior in AMReX
- [x] add new capabilities to AMReX
- [ ] changes answers in the test suite to more than roundoff level
- [ ] are likely to significantly affect the results of downstream AMReX
users
- [ ] include documentation in the code and/or rst files, if appropriate
  • Loading branch information
ax3l authored Apr 2, 2024
1 parent 728eec4 commit f2536be
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Src/Base/AMReX_PODVector.H
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,15 @@ namespace amrex
(Allocator const&)(*this));
}

/** Set the same value to every element of the vector
*
* @param a_value the value to assign
*/
void assign (const T& a_value)
{
assign(m_size, a_value);
}

[[nodiscard]] allocator_type get_allocator () const noexcept { return *this; }

void push_back (const T& a_value)
Expand Down

0 comments on commit f2536be

Please sign in to comment.