diff --git a/vector.hpp b/vector.hpp index 0506ac3a..c0b74b07 100644 --- a/vector.hpp +++ b/vector.hpp @@ -78,6 +78,7 @@ namespace util { // size operations template vector redim (void) const; template vector redim (const util::vector &fill) const; + template vector redim (T fill) const; // constants static const vector ZERO; diff --git a/vector.ipp b/vector.ipp index 8fbf99a5..4be4ef2e 100644 --- a/vector.ipp +++ b/vector.ipp @@ -29,7 +29,8 @@ namespace util { //------------------------------------------------------------------------- template template - vector vector::redim (void) const { + vector vector::redim (void) const + { vector out; std::copy_n (std::begin (this->data), min (S, D), @@ -41,7 +42,8 @@ namespace util { //------------------------------------------------------------------------- template template - vector vector::redim (const vector &fill) const { + vector vector::redim (const vector &fill) const + { vector out; static constexpr auto L1 = min (S, D); @@ -56,4 +58,20 @@ namespace util { out.data + L1); return out; } + + + //------------------------------------------------------------------------- + template + template + vector vector::redim (T fill) const + { + vector out; + + auto cursor = std::copy_n (std::begin (this->data), + min (S, D), + std::begin (out.data)); + std::fill (cursor, std::end (out.data), fill); + + return out; + } }