diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h index 15570bb9..569802c2 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h @@ -69,4 +69,27 @@ freely, subject to the following restrictions: #endif +namespace PolyVox +{ +#if defined(HAS_CXX11_STATIC_ASSERT) + //In this case we can just use static_assert +#define POLYVOX_STATIC_ASSERT static_assert +#else + // empty default template + template + struct StaticAssert {}; + + // template specialized on true + template <> + struct StaticAssert + { + // If the static assertion is failing then this function won't exist. It will then + // appear in the error message which gives a clue to the user about what is wrong. + static void ERROR_The_static_assertion_has_failed() {} + }; + + #define POLYVOX_STATIC_ASSERT(condition, message) StaticAssert<(condition)>::ERROR_The_static_assertion_has_failed(); +#endif +} + #endif //__PolyVox_ErrorHandling_H__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h index da1fedd5..3724efe4 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h @@ -98,13 +98,6 @@ freely, subject to the following restrictions: #define polyvox_constexpr #endif -#if defined(HAS_CXX11_STATIC_ASSERT) - //In this case we can just use static_assert -#else - #include - #define static_assert(condition, message) BOOST_STATIC_ASSERT(condition) -#endif - #if defined(HAS_CXX11_CSTDINT_H) #include #else diff --git a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl index 65b5eba7..57b3e2f0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl @@ -53,7 +53,7 @@ namespace PolyVox template Vector::Vector(StorageType x, StorageType y) { - static_assert(Size == 2, "This constructor should only be used for vectors with two elements."); + POLYVOX_STATIC_ASSERT(Size == 2, "This constructor should only be used for vectors with two elements."); m_tElements[0] = x; m_tElements[1] = y; @@ -68,7 +68,7 @@ namespace PolyVox template Vector::Vector(StorageType x, StorageType y, StorageType z) { - static_assert(Size == 3, "This constructor should only be used for vectors with three elements."); + POLYVOX_STATIC_ASSERT(Size == 3, "This constructor should only be used for vectors with three elements."); m_tElements[0] = x; m_tElements[1] = y; @@ -86,7 +86,7 @@ namespace PolyVox template Vector::Vector(StorageType x, StorageType y, StorageType z, StorageType w) { - static_assert(Size == 4, "This constructor should only be used for vectors with four elements."); + POLYVOX_STATIC_ASSERT(Size == 4, "This constructor should only be used for vectors with four elements."); m_tElements[0] = x; m_tElements[1] = y; @@ -129,14 +129,14 @@ namespace PolyVox template Vector::~Vector(void) { - // We put the static_asserts in the destructor because there is one one of these, + // We put the static asserts in the destructor because there is one one of these, // where as there are multiple constructors. // Force a vector to have a length greater than one. There is no need for a // vector with one element, and supporting this would cause confusion over the // behaviour of the constructor taking a single value, as this fills all elements // to that value rather than just the first one. - static_assert(Size > 1, "Vector must have a length greater than one."); + POLYVOX_STATIC_ASSERT(Size > 1, "Vector must have a length greater than one."); } /** @@ -442,7 +442,7 @@ namespace PolyVox template inline StorageType Vector::getZ(void) const { - static_assert(Size >= 3, "You can only get the 'z' component from a vector with at least three elements."); + POLYVOX_STATIC_ASSERT(Size >= 3, "You can only get the 'z' component from a vector with at least three elements."); return m_tElements[2]; } @@ -453,7 +453,7 @@ namespace PolyVox template inline StorageType Vector::getW(void) const { - static_assert(Size >= 4, "You can only get the 'w' component from a vector with at least four elements."); + POLYVOX_STATIC_ASSERT(Size >= 4, "You can only get the 'w' component from a vector with at least four elements."); return m_tElements[3]; } @@ -491,7 +491,7 @@ namespace PolyVox template inline void Vector::setElements(StorageType x, StorageType y, StorageType z) { - static_assert(Size >= 3, "You can only use this version of setElements() on a vector with at least three elements."); + POLYVOX_STATIC_ASSERT(Size >= 3, "You can only use this version of setElements() on a vector with at least three elements."); m_tElements[0] = x; m_tElements[1] = y; @@ -508,7 +508,7 @@ namespace PolyVox template inline void Vector::setElements(StorageType x, StorageType y, StorageType z, StorageType w) { - static_assert(Size >= 4, "You can only use this version of setElements() on a vector with at least four elements."); + POLYVOX_STATIC_ASSERT(Size >= 4, "You can only use this version of setElements() on a vector with at least four elements."); m_tElements[0] = x; m_tElements[1] = y; @@ -540,7 +540,7 @@ namespace PolyVox template inline void Vector::setZ(StorageType tZ) { - static_assert(Size >= 3, "You can only set the 'w' component from a vector with at least three elements."); + POLYVOX_STATIC_ASSERT(Size >= 3, "You can only set the 'w' component from a vector with at least three elements."); m_tElements[2] = tZ; } @@ -551,7 +551,7 @@ namespace PolyVox template inline void Vector::setW(StorageType tW) { - static_assert(Size >= 4, "You can only set the 'w' component from a vector with at least four elements."); + POLYVOX_STATIC_ASSERT(Size >= 4, "You can only set the 'w' component from a vector with at least four elements."); m_tElements[3] = tW; }