Constructors that only throw if the operation they perform can throw.
This commit is contained in:
parent
fc50c6af55
commit
a95fcd629f
2 changed files with 11 additions and 14 deletions
|
@ -23,6 +23,7 @@
|
|||
#include <cstdint>
|
||||
#include <ciso646>
|
||||
#include <type_traits>
|
||||
#include <algorithm>
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
#include <iostream>
|
||||
|
@ -33,12 +34,12 @@ namespace cloonel {
|
|||
class Vector {
|
||||
template <typename U, uint32_t R> friend class Vector;
|
||||
public:
|
||||
Vector ( void ) = default;
|
||||
explicit Vector ( T parValue );
|
||||
template <typename U> explicit Vector ( const Vector<U, S>& parOther );
|
||||
template <typename = std::enable_if<S == 2> > Vector ( T parX, T parY ) : m_mem {parX, parY} {}
|
||||
template <typename = std::enable_if<S == 3> > Vector ( T parX, T parY, T parZ ) : m_mem {parX, parY, parZ} {}
|
||||
template <typename = std::enable_if<S == 4> > Vector ( T parX, T parY, T parZ, T parW ) : m_mem {parX, parY, parZ, parW} {}
|
||||
Vector ( void ) noexcept(noexcept(T())) = default;
|
||||
explicit Vector ( T parValue ) noexcept(noexcept(T()) && noexcept(parValue=parValue));
|
||||
template <typename U> explicit Vector ( const Vector<U, S>& parOther ) noexcept(noexcept(T()) && noexcept(const_cast<U&>(parOther.m_mem[0])=T()));
|
||||
template <typename = std::enable_if<S == 2> > Vector ( T parX, T parY ) noexcept : m_mem {parX, parY} {}
|
||||
template <typename = std::enable_if<S == 3> > Vector ( T parX, T parY, T parZ ) noexcept : m_mem {parX, parY, parZ} {}
|
||||
template <typename = std::enable_if<S == 4> > Vector ( T parX, T parY, T parZ, T parW ) noexcept : m_mem {parX, parY, parZ, parW} {}
|
||||
|
||||
~Vector ( void ) noexcept = default;
|
||||
|
||||
|
|
|
@ -21,20 +21,16 @@ namespace cloonel {
|
|||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, uint32_t S>
|
||||
Vector<T, S>::Vector (T parValue) {
|
||||
for (uint32_t z = 0; z < S; ++z) {
|
||||
m_mem[z] = parValue;
|
||||
}
|
||||
Vector<T, S>::Vector (T parValue) noexcept(noexcept(T()) && noexcept(parValue=parValue)) {
|
||||
std::fill(m_mem, m_mem + S, parValue);
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, uint32_t S>
|
||||
template <typename U>
|
||||
Vector<T, S>::Vector (const Vector<U, S>& parOther) {
|
||||
for (uint32_t z = 0; z < S; ++z) {
|
||||
m_mem[z] = static_cast<T>(parOther.m_mem[z]);
|
||||
}
|
||||
Vector<T, S>::Vector (const Vector<U, S>& parOther) noexcept(noexcept(T()) && noexcept(const_cast<U&>(parOther.m_mem[0])=T())) {
|
||||
std::copy(parOther.m_mem, parOther.m_mem + S, m_mem);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
|
|
Loading…
Reference in a new issue