vector: add scalar variant of redim
This commit is contained in:
parent
23ffd18acb
commit
4bb5b7adb2
@ -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;
|
||||
|
22
vector.ipp
22
vector.ipp
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user