vector: add scalar variant of redim

This commit is contained in:
Danny Robson 2015-02-12 17:41:07 +11:00
parent 23ffd18acb
commit 4bb5b7adb2
2 changed files with 21 additions and 2 deletions

View File

@ -78,6 +78,7 @@ namespace util {
// size operations
template <size_t D> vector<D,T> redim (void) const;
template <size_t D> vector<D,T> redim (const util::vector<D,T> &fill) const;
template <size_t D> vector<D,T> redim (T fill) const;
// constants
static const vector<S,T> ZERO;

View File

@ -29,7 +29,8 @@ namespace util {
//-------------------------------------------------------------------------
template<size_t S, typename T>
template<size_t D>
vector<D,T> vector<S,T>::redim (void) const {
vector<D,T> vector<S,T>::redim (void) const
{
vector<D,T> out;
std::copy_n (std::begin (this->data),
min (S, D),
@ -41,7 +42,8 @@ namespace util {
//-------------------------------------------------------------------------
template<size_t S, typename T>
template<size_t D>
vector<D,T> vector<S,T>::redim (const vector<D,T> &fill) const {
vector<D,T> vector<S,T>::redim (const vector<D,T> &fill) const
{
vector<D,T> out;
static constexpr auto L1 = min (S, D);
@ -56,4 +58,20 @@ namespace util {
out.data + L1);
return out;
}
//-------------------------------------------------------------------------
template <size_t S, typename T>
template <size_t D>
vector<D,T> vector<S,T>::redim (T fill) const
{
vector<D,T> 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;
}
}