Constructors that only throw if the operation they perform can throw.

This commit is contained in:
King_DuckZ 2014-05-13 11:45:53 +02:00
parent fc50c6af55
commit a95fcd629f
2 changed files with 11 additions and 14 deletions

View file

@ -23,6 +23,7 @@
#include <cstdint> #include <cstdint>
#include <ciso646> #include <ciso646>
#include <type_traits> #include <type_traits>
#include <algorithm>
#if !defined(NDEBUG) #if !defined(NDEBUG)
#include <iostream> #include <iostream>
@ -33,12 +34,12 @@ namespace cloonel {
class Vector { class Vector {
template <typename U, uint32_t R> friend class Vector; template <typename U, uint32_t R> friend class Vector;
public: public:
Vector ( void ) = default; Vector ( void ) noexcept(noexcept(T())) = default;
explicit Vector ( T parValue ); explicit Vector ( T parValue ) noexcept(noexcept(T()) && noexcept(parValue=parValue));
template <typename U> explicit Vector ( const Vector<U, S>& parOther ); 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 ) : m_mem {parX, parY} {} 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 ) : m_mem {parX, parY, parZ} {} 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 ) : m_mem {parX, parY, parZ, parW} {} 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; ~Vector ( void ) noexcept = default;

View file

@ -21,20 +21,16 @@ namespace cloonel {
///------------------------------------------------------------------------- ///-------------------------------------------------------------------------
///------------------------------------------------------------------------- ///-------------------------------------------------------------------------
template <typename T, uint32_t S> template <typename T, uint32_t S>
Vector<T, S>::Vector (T parValue) { Vector<T, S>::Vector (T parValue) noexcept(noexcept(T()) && noexcept(parValue=parValue)) {
for (uint32_t z = 0; z < S; ++z) { std::fill(m_mem, m_mem + S, parValue);
m_mem[z] = parValue;
}
} }
///------------------------------------------------------------------------- ///-------------------------------------------------------------------------
///------------------------------------------------------------------------- ///-------------------------------------------------------------------------
template <typename T, uint32_t S> template <typename T, uint32_t S>
template <typename U> template <typename U>
Vector<T, S>::Vector (const Vector<U, S>& parOther) { Vector<T, S>::Vector (const Vector<U, S>& parOther) noexcept(noexcept(T()) && noexcept(const_cast<U&>(parOther.m_mem[0])=T())) {
for (uint32_t z = 0; z < S; ++z) { std::copy(parOther.m_mem, parOther.m_mem + S, m_mem);
m_mem[z] = static_cast<T>(parOther.m_mem[z]);
}
} }
#pragma GCC diagnostic push #pragma GCC diagnostic push