From 4bb5b7adb2f115effa3d74a3adf84e4822444096 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 12 Feb 2015 17:41:07 +1100 Subject: [PATCH] vector: add scalar variant of redim --- vector.hpp | 1 + vector.ipp | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) 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; + } }