vector: add cast operator

This commit is contained in:
Danny Robson 2015-04-08 13:51:09 +10:00
parent ec9b8a0c57
commit a67edcde1a
2 changed files with 16 additions and 0 deletions

View File

@ -52,6 +52,8 @@ namespace util {
// constants
static const vector<S,T> ZERO;
template<typename U> vector<S,U> cast (void) const;
void sanity (void) const;
};

View File

@ -74,4 +74,18 @@ namespace util {
return out;
}
//-------------------------------------------------------------------------
template <size_t S, typename T>
template <typename U>
vector<S,U>
vector<S,T>::cast (void) const
{
vector<S,U> out;
std::copy (std::begin (this->data),
std::end (this->data),
std::begin (out.data));
return out;
}
}