From 69b455955d7cf9f9f2f5317dcd6da3a23f4b52e5 Mon Sep 17 00:00:00 2001 From: Yuya Asano <64895419+sukeya@users.noreply.github.com> Date: Tue, 18 Jul 2023 20:28:55 +0900 Subject: [PATCH 01/13] Make vectors trivially relocatable. Signed-off-by: Yuya Asano <64895419+sukeya@users.noreply.github.com> --- src/Imath/ImathBoxAlgo.h | 2 +- src/Imath/ImathVec.h | 96 ++++++++++++++-------------------------- 2 files changed, 34 insertions(+), 64 deletions(-) diff --git a/src/Imath/ImathBoxAlgo.h b/src/Imath/ImathBoxAlgo.h index 3ad5e127..00545e34 100644 --- a/src/Imath/ImathBoxAlgo.h +++ b/src/Imath/ImathBoxAlgo.h @@ -49,7 +49,7 @@ clip (const T& p, const Box& box) IMATH_NOEXCEPT /// template -IMATH_HOSTDEVICE constexpr inline T +IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline T closestPointInBox (const T& p, const Box& box) IMATH_NOEXCEPT { return clip (p, box); diff --git a/src/Imath/ImathVec.h b/src/Imath/ImathVec.h index 49d69256..4dd48c30 100644 --- a/src/Imath/ImathVec.h +++ b/src/Imath/ImathVec.h @@ -72,15 +72,22 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 IMATH_HOSTDEVICE constexpr Vec2 (T a, T b) IMATH_NOEXCEPT; /// Copy constructor - IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT; + IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT = default; + + /// Move constructor + IMATH_HOSTDEVICE constexpr Vec2 (Vec2&& v) IMATH_NOEXCEPT = default; /// Construct from Vec2 of another base type template IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT; - /// Assignment - IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2& - operator= (const Vec2& v) IMATH_NOEXCEPT; + /// Copy assignment + IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec2& + operator= (const Vec2& v) IMATH_NOEXCEPT = default; + + /// Move assignment + IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec2& + operator= (Vec2&& v) IMATH_NOEXCEPT = default; /// Destructor ~Vec2 () IMATH_NOEXCEPT = default; @@ -369,7 +376,10 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 IMATH_HOSTDEVICE constexpr Vec3 (T a, T b, T c) IMATH_NOEXCEPT; /// Copy constructor - IMATH_HOSTDEVICE constexpr Vec3 (const Vec3& v) IMATH_NOEXCEPT; + IMATH_HOSTDEVICE constexpr Vec3 (const Vec3& v) IMATH_NOEXCEPT = default; + + /// Move constructor + IMATH_HOSTDEVICE constexpr Vec3 (Vec3&& v) IMATH_NOEXCEPT = default; /// Construct from Vec3 of another base type template @@ -387,9 +397,13 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 explicit IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec3 (const Vec4& v, InfException); - /// Assignment - IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3& - operator= (const Vec3& v) IMATH_NOEXCEPT; + /// Copy assignment + IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec3& + operator= (const Vec3& v) IMATH_NOEXCEPT = default; + + /// Move assignment + IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec3& + operator= (Vec3&& v) IMATH_NOEXCEPT = default; /// Destructor ~Vec3 () IMATH_NOEXCEPT = default; @@ -690,7 +704,10 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 IMATH_HOSTDEVICE constexpr Vec4 (T a, T b, T c, T d) IMATH_NOEXCEPT; /// Copy constructor - IMATH_HOSTDEVICE constexpr Vec4 (const Vec4& v) IMATH_NOEXCEPT; + IMATH_HOSTDEVICE constexpr Vec4 (const Vec4& v) IMATH_NOEXCEPT = default; + + /// Move constructor + IMATH_HOSTDEVICE constexpr Vec4 (Vec4&& v) IMATH_NOEXCEPT = default; /// Construct from Vec4 of another base type template @@ -700,9 +717,13 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 template IMATH_HOSTDEVICE explicit constexpr Vec4 (const Vec3& v) IMATH_NOEXCEPT; - /// Assignment - IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4& - operator= (const Vec4& v) IMATH_NOEXCEPT; + /// Copy assignment + IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec4& + operator= (const Vec4& v) IMATH_NOEXCEPT = default; + + /// Move assignment + IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec4& + operator= (Vec4&& v) IMATH_NOEXCEPT = default; /// Destructor ~Vec4 () IMATH_NOEXCEPT = default; @@ -1212,12 +1233,6 @@ IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (T a, T b) IMATH_NOEXCEPT y (b) {} -template -IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (const Vec2& v) IMATH_NOEXCEPT - : x (v.x), - y (v.y) -{} - template template IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (const Vec2& v) @@ -1225,15 +1240,6 @@ IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (const Vec2& v) y (T (v.y)) {} -template -IMATH_CONSTEXPR14 IMATH_HOSTDEVICE inline const Vec2& -Vec2::operator= (const Vec2& v) IMATH_NOEXCEPT -{ - x = v.x; - y = v.y; - return *this; -} - template template IMATH_HOSTDEVICE inline void @@ -1618,13 +1624,6 @@ IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (T a, T b, T c) IMATH_NOEXCEPT z (c) {} -template -IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec3& v) IMATH_NOEXCEPT - : x (v.x), - y (v.y), - z (v.z) -{} - template template IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec3& v) @@ -1633,16 +1632,6 @@ IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec3& v) z (T (v.z)) {} -template -IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec3& -Vec3::operator= (const Vec3& v) IMATH_NOEXCEPT -{ - x = v.x; - y = v.y; - z = v.z; - return *this; -} - template template IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec4& v) @@ -2093,14 +2082,6 @@ IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (T a, T b, T c, T d) w (d) {} -template -IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec4& v) IMATH_NOEXCEPT - : x (v.x), - y (v.y), - z (v.z), - w (v.w) -{} - template template IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec4& v) @@ -2110,17 +2091,6 @@ IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec4& v) w (T (v.w)) {} -template -IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec4& -Vec4::operator= (const Vec4& v) IMATH_NOEXCEPT -{ - x = v.x; - y = v.y; - z = v.z; - w = v.w; - return *this; -} - template template IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec3& v) From 56f83c338350bb79fa9b235380069d400cf9cd4b Mon Sep 17 00:00:00 2001 From: Yuya Asano <64895419+sukeya@users.noreply.github.com> Date: Sat, 22 Jul 2023 01:07:29 +0900 Subject: [PATCH 02/13] Keep both ways of having default ctor or not. Signed-off-by: Yuya Asano <64895419+sukeya@users.noreply.github.com> --- config/ImathConfig.h.in | 3 ++ src/Imath/ImathVec.h | 102 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) diff --git a/config/ImathConfig.h.in b/config/ImathConfig.h.in index 132f6235..bca83fd7 100644 --- a/config/ImathConfig.h.in +++ b/config/ImathConfig.h.in @@ -174,4 +174,7 @@ # endif #endif +// Whether the copy and move constructors of Vec2, Vec3 and Vec4 are default or not. +#cmakedefine IMATH_VEC_USE_DEFAULT_CONSTRUCTOR + #endif // INCLUDED_IMATH_CONFIG_H diff --git a/src/Imath/ImathVec.h b/src/Imath/ImathVec.h index 4dd48c30..5876baf7 100644 --- a/src/Imath/ImathVec.h +++ b/src/Imath/ImathVec.h @@ -72,22 +72,35 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 IMATH_HOSTDEVICE constexpr Vec2 (T a, T b) IMATH_NOEXCEPT; /// Copy constructor +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT = default; +#else + IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT; +#endif +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR /// Move constructor IMATH_HOSTDEVICE constexpr Vec2 (Vec2&& v) IMATH_NOEXCEPT = default; +#endif /// Construct from Vec2 of another base type template IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT; /// Copy assignment +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec2& operator= (const Vec2& v) IMATH_NOEXCEPT = default; +#else + IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2& + operator= (const Vec2& v) IMATH_NOEXCEPT; +#endif +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR /// Move assignment IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec2& operator= (Vec2&& v) IMATH_NOEXCEPT = default; +#endif /// Destructor ~Vec2 () IMATH_NOEXCEPT = default; @@ -376,10 +389,16 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 IMATH_HOSTDEVICE constexpr Vec3 (T a, T b, T c) IMATH_NOEXCEPT; /// Copy constructor +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE constexpr Vec3 (const Vec3& v) IMATH_NOEXCEPT = default; +#else + IMATH_HOSTDEVICE constexpr Vec3 (const Vec3& v) IMATH_NOEXCEPT; +#endif +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR /// Move constructor IMATH_HOSTDEVICE constexpr Vec3 (Vec3&& v) IMATH_NOEXCEPT = default; +#endif /// Construct from Vec3 of another base type template @@ -398,12 +417,19 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 Vec3 (const Vec4& v, InfException); /// Copy assignment +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec3& operator= (const Vec3& v) IMATH_NOEXCEPT = default; +#else + IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec3& + operator= (const Vec3& v) IMATH_NOEXCEPT; +#endif +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR /// Move assignment IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec3& operator= (Vec3&& v) IMATH_NOEXCEPT = default; +#endif /// Destructor ~Vec3 () IMATH_NOEXCEPT = default; @@ -704,10 +730,16 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 IMATH_HOSTDEVICE constexpr Vec4 (T a, T b, T c, T d) IMATH_NOEXCEPT; /// Copy constructor +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE constexpr Vec4 (const Vec4& v) IMATH_NOEXCEPT = default; +#else + IMATH_HOSTDEVICE constexpr Vec4 (const Vec4& v) IMATH_NOEXCEPT; +#endif +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR /// Move constructor IMATH_HOSTDEVICE constexpr Vec4 (Vec4&& v) IMATH_NOEXCEPT = default; +#endif /// Construct from Vec4 of another base type template @@ -718,12 +750,19 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 IMATH_HOSTDEVICE explicit constexpr Vec4 (const Vec3& v) IMATH_NOEXCEPT; /// Copy assignment +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec4& operator= (const Vec4& v) IMATH_NOEXCEPT = default; +#else + IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec4& + operator= (const Vec4& v) IMATH_NOEXCEPT; +#endif +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR /// Move assignment IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec4& operator= (Vec4&& v) IMATH_NOEXCEPT = default; +#endif /// Destructor ~Vec4 () IMATH_NOEXCEPT = default; @@ -1233,6 +1272,14 @@ IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (T a, T b) IMATH_NOEXCEPT y (b) {} +#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +template +IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (const Vec2& v) IMATH_NOEXCEPT + : x (v.x), + y (v.y) +{} +#endif + template template IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (const Vec2& v) @@ -1240,6 +1287,17 @@ IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (const Vec2& v) y (T (v.y)) {} +#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +template +IMATH_CONSTEXPR14 IMATH_HOSTDEVICE inline const Vec2& +Vec2::operator= (const Vec2& v) IMATH_NOEXCEPT +{ + x = v.x; + y = v.y; + return *this; +} +#endif + template template IMATH_HOSTDEVICE inline void @@ -1624,6 +1682,15 @@ IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (T a, T b, T c) IMATH_NOEXCEPT z (c) {} +#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +template +IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec3& v) IMATH_NOEXCEPT + : x (v.x), + y (v.y), + z (v.z) +{} +#endif + template template IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec3& v) @@ -1632,6 +1699,18 @@ IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec3& v) z (T (v.z)) {} +#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +template +IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec3& +Vec3::operator= (const Vec3& v) IMATH_NOEXCEPT +{ + x = v.x; + y = v.y; + z = v.z; + return *this; +} +#endif + template template IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec4& v) @@ -2082,6 +2161,16 @@ IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (T a, T b, T c, T d) w (d) {} +#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +template +IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec4& v) IMATH_NOEXCEPT + : x (v.x), + y (v.y), + z (v.z), + w (v.w) +{} +#endif + template template IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec4& v) @@ -2091,6 +2180,19 @@ IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec4& v) w (T (v.w)) {} +#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +template +IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec4& +Vec4::operator= (const Vec4& v) IMATH_NOEXCEPT +{ + x = v.x; + y = v.y; + z = v.z; + w = v.w; + return *this; +} +#endif + template template IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec3& v) From abc7c5e76bd85fbbe75fc9c40483e1bc05c0ab5e Mon Sep 17 00:00:00 2001 From: Yuya Asano <64895419+sukeya@users.noreply.github.com> Date: Sat, 22 Jul 2023 01:32:35 +0900 Subject: [PATCH 03/13] Fix using default ctor whatever value the flag is. Signed-off-by: Yuya Asano <64895419+sukeya@users.noreply.github.com> --- config/CMakeLists.txt | 4 ++++ config/ImathConfig.h.in | 2 +- src/Imath/ImathVec.h | 36 ++++++++++++++++++------------------ 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index 32fb7af8..fc453d12 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -10,6 +10,10 @@ else() set(IMATH_ENABLE_API_VISIBILITY ON) endif() +if (IMATH_VEC_USE_DEFAULT_CONSTRUCTOR) + set(IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR ON) +endif() + configure_file(ImathConfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/ImathConfig.h) add_library(ImathConfig INTERFACE) diff --git a/config/ImathConfig.h.in b/config/ImathConfig.h.in index bca83fd7..5c39ad15 100644 --- a/config/ImathConfig.h.in +++ b/config/ImathConfig.h.in @@ -175,6 +175,6 @@ #endif // Whether the copy and move constructors of Vec2, Vec3 and Vec4 are default or not. -#cmakedefine IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#cmakedefine IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR #endif // INCLUDED_IMATH_CONFIG_H diff --git a/src/Imath/ImathVec.h b/src/Imath/ImathVec.h index 5876baf7..4a8d7986 100644 --- a/src/Imath/ImathVec.h +++ b/src/Imath/ImathVec.h @@ -72,13 +72,13 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 IMATH_HOSTDEVICE constexpr Vec2 (T a, T b) IMATH_NOEXCEPT; /// Copy constructor -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT = default; #else IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR /// Move constructor IMATH_HOSTDEVICE constexpr Vec2 (Vec2&& v) IMATH_NOEXCEPT = default; #endif @@ -88,7 +88,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT; /// Copy assignment -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec2& operator= (const Vec2& v) IMATH_NOEXCEPT = default; #else @@ -96,7 +96,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 operator= (const Vec2& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR /// Move assignment IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec2& operator= (Vec2&& v) IMATH_NOEXCEPT = default; @@ -389,13 +389,13 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 IMATH_HOSTDEVICE constexpr Vec3 (T a, T b, T c) IMATH_NOEXCEPT; /// Copy constructor -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE constexpr Vec3 (const Vec3& v) IMATH_NOEXCEPT = default; #else IMATH_HOSTDEVICE constexpr Vec3 (const Vec3& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR /// Move constructor IMATH_HOSTDEVICE constexpr Vec3 (Vec3&& v) IMATH_NOEXCEPT = default; #endif @@ -417,7 +417,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 Vec3 (const Vec4& v, InfException); /// Copy assignment -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec3& operator= (const Vec3& v) IMATH_NOEXCEPT = default; #else @@ -425,7 +425,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 operator= (const Vec3& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR /// Move assignment IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec3& operator= (Vec3&& v) IMATH_NOEXCEPT = default; @@ -730,13 +730,13 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 IMATH_HOSTDEVICE constexpr Vec4 (T a, T b, T c, T d) IMATH_NOEXCEPT; /// Copy constructor -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE constexpr Vec4 (const Vec4& v) IMATH_NOEXCEPT = default; #else IMATH_HOSTDEVICE constexpr Vec4 (const Vec4& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR /// Move constructor IMATH_HOSTDEVICE constexpr Vec4 (Vec4&& v) IMATH_NOEXCEPT = default; #endif @@ -750,7 +750,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 IMATH_HOSTDEVICE explicit constexpr Vec4 (const Vec3& v) IMATH_NOEXCEPT; /// Copy assignment -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec4& operator= (const Vec4& v) IMATH_NOEXCEPT = default; #else @@ -758,7 +758,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 operator= (const Vec4& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR /// Move assignment IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec4& operator= (Vec4&& v) IMATH_NOEXCEPT = default; @@ -1272,7 +1272,7 @@ IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (T a, T b) IMATH_NOEXCEPT y (b) {} -#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifndef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR template IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (const Vec2& v) IMATH_NOEXCEPT : x (v.x), @@ -1287,7 +1287,7 @@ IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (const Vec2& v) y (T (v.y)) {} -#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifndef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR template IMATH_CONSTEXPR14 IMATH_HOSTDEVICE inline const Vec2& Vec2::operator= (const Vec2& v) IMATH_NOEXCEPT @@ -1682,7 +1682,7 @@ IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (T a, T b, T c) IMATH_NOEXCEPT z (c) {} -#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifndef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR template IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec3& v) IMATH_NOEXCEPT : x (v.x), @@ -1699,7 +1699,7 @@ IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec3& v) z (T (v.z)) {} -#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifndef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec3& Vec3::operator= (const Vec3& v) IMATH_NOEXCEPT @@ -2161,7 +2161,7 @@ IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (T a, T b, T c, T d) w (d) {} -#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifndef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR template IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec4& v) IMATH_NOEXCEPT : x (v.x), @@ -2180,7 +2180,7 @@ IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec4& v) w (T (v.w)) {} -#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifndef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec4& Vec4::operator= (const Vec4& v) IMATH_NOEXCEPT From 04950f468bac69f0cecd79b06d6c086efccceef0 Mon Sep 17 00:00:00 2001 From: Yuya Asano <64895419+sukeya@users.noreply.github.com> Date: Sat, 22 Jul 2023 10:10:52 +0900 Subject: [PATCH 04/13] Revert "Fix using default ctor whatever value the flag is." This reverts commit abc7c5e76bd85fbbe75fc9c40483e1bc05c0ab5e. Signed-off-by: Yuya Asano <64895419+sukeya@users.noreply.github.com> --- config/CMakeLists.txt | 4 ---- config/ImathConfig.h.in | 2 +- src/Imath/ImathVec.h | 36 ++++++++++++++++++------------------ 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index fc453d12..32fb7af8 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -10,10 +10,6 @@ else() set(IMATH_ENABLE_API_VISIBILITY ON) endif() -if (IMATH_VEC_USE_DEFAULT_CONSTRUCTOR) - set(IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR ON) -endif() - configure_file(ImathConfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/ImathConfig.h) add_library(ImathConfig INTERFACE) diff --git a/config/ImathConfig.h.in b/config/ImathConfig.h.in index 5c39ad15..bca83fd7 100644 --- a/config/ImathConfig.h.in +++ b/config/ImathConfig.h.in @@ -175,6 +175,6 @@ #endif // Whether the copy and move constructors of Vec2, Vec3 and Vec4 are default or not. -#cmakedefine IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#cmakedefine IMATH_VEC_USE_DEFAULT_CONSTRUCTOR #endif // INCLUDED_IMATH_CONFIG_H diff --git a/src/Imath/ImathVec.h b/src/Imath/ImathVec.h index 4a8d7986..5876baf7 100644 --- a/src/Imath/ImathVec.h +++ b/src/Imath/ImathVec.h @@ -72,13 +72,13 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 IMATH_HOSTDEVICE constexpr Vec2 (T a, T b) IMATH_NOEXCEPT; /// Copy constructor -#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT = default; #else IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR /// Move constructor IMATH_HOSTDEVICE constexpr Vec2 (Vec2&& v) IMATH_NOEXCEPT = default; #endif @@ -88,7 +88,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT; /// Copy assignment -#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec2& operator= (const Vec2& v) IMATH_NOEXCEPT = default; #else @@ -96,7 +96,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 operator= (const Vec2& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR /// Move assignment IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec2& operator= (Vec2&& v) IMATH_NOEXCEPT = default; @@ -389,13 +389,13 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 IMATH_HOSTDEVICE constexpr Vec3 (T a, T b, T c) IMATH_NOEXCEPT; /// Copy constructor -#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE constexpr Vec3 (const Vec3& v) IMATH_NOEXCEPT = default; #else IMATH_HOSTDEVICE constexpr Vec3 (const Vec3& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR /// Move constructor IMATH_HOSTDEVICE constexpr Vec3 (Vec3&& v) IMATH_NOEXCEPT = default; #endif @@ -417,7 +417,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 Vec3 (const Vec4& v, InfException); /// Copy assignment -#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec3& operator= (const Vec3& v) IMATH_NOEXCEPT = default; #else @@ -425,7 +425,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 operator= (const Vec3& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR /// Move assignment IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec3& operator= (Vec3&& v) IMATH_NOEXCEPT = default; @@ -730,13 +730,13 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 IMATH_HOSTDEVICE constexpr Vec4 (T a, T b, T c, T d) IMATH_NOEXCEPT; /// Copy constructor -#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE constexpr Vec4 (const Vec4& v) IMATH_NOEXCEPT = default; #else IMATH_HOSTDEVICE constexpr Vec4 (const Vec4& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR /// Move constructor IMATH_HOSTDEVICE constexpr Vec4 (Vec4&& v) IMATH_NOEXCEPT = default; #endif @@ -750,7 +750,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 IMATH_HOSTDEVICE explicit constexpr Vec4 (const Vec3& v) IMATH_NOEXCEPT; /// Copy assignment -#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec4& operator= (const Vec4& v) IMATH_NOEXCEPT = default; #else @@ -758,7 +758,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 operator= (const Vec4& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR /// Move assignment IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec4& operator= (Vec4&& v) IMATH_NOEXCEPT = default; @@ -1272,7 +1272,7 @@ IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (T a, T b) IMATH_NOEXCEPT y (b) {} -#ifndef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR template IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (const Vec2& v) IMATH_NOEXCEPT : x (v.x), @@ -1287,7 +1287,7 @@ IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (const Vec2& v) y (T (v.y)) {} -#ifndef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR template IMATH_CONSTEXPR14 IMATH_HOSTDEVICE inline const Vec2& Vec2::operator= (const Vec2& v) IMATH_NOEXCEPT @@ -1682,7 +1682,7 @@ IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (T a, T b, T c) IMATH_NOEXCEPT z (c) {} -#ifndef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR template IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec3& v) IMATH_NOEXCEPT : x (v.x), @@ -1699,7 +1699,7 @@ IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec3& v) z (T (v.z)) {} -#ifndef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec3& Vec3::operator= (const Vec3& v) IMATH_NOEXCEPT @@ -2161,7 +2161,7 @@ IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (T a, T b, T c, T d) w (d) {} -#ifndef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR template IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec4& v) IMATH_NOEXCEPT : x (v.x), @@ -2180,7 +2180,7 @@ IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec4& v) w (T (v.w)) {} -#ifndef IMATH_VEC_ENABLE_DEFAULT_CONSTRUCTOR +#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec4& Vec4::operator= (const Vec4& v) IMATH_NOEXCEPT From 9db40194100c510cdac77ecce90a7744086268e9 Mon Sep 17 00:00:00 2001 From: Yuya Asano <64895419+sukeya@users.noreply.github.com> Date: Sat, 22 Jul 2023 10:26:30 +0900 Subject: [PATCH 05/13] Fix using a build flag to use a macro. Signed-off-by: Yuya Asano <64895419+sukeya@users.noreply.github.com> --- config/ImathConfig.h.in | 4 +++- src/Imath/ImathVec.h | 36 ++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/config/ImathConfig.h.in b/config/ImathConfig.h.in index bca83fd7..e4fca5ef 100644 --- a/config/ImathConfig.h.in +++ b/config/ImathConfig.h.in @@ -175,6 +175,8 @@ #endif // Whether the copy and move constructors of Vec2, Vec3 and Vec4 are default or not. -#cmakedefine IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +# define IMATH_VEC_USE_DEFAULT_CONSTRUCTOR 0 +#endif #endif // INCLUDED_IMATH_CONFIG_H diff --git a/src/Imath/ImathVec.h b/src/Imath/ImathVec.h index 5876baf7..6ff65c65 100644 --- a/src/Imath/ImathVec.h +++ b/src/Imath/ImathVec.h @@ -72,13 +72,13 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 IMATH_HOSTDEVICE constexpr Vec2 (T a, T b) IMATH_NOEXCEPT; /// Copy constructor -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT = default; #else IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 /// Move constructor IMATH_HOSTDEVICE constexpr Vec2 (Vec2&& v) IMATH_NOEXCEPT = default; #endif @@ -88,7 +88,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT; /// Copy assignment -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec2& operator= (const Vec2& v) IMATH_NOEXCEPT = default; #else @@ -96,7 +96,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 operator= (const Vec2& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 /// Move assignment IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec2& operator= (Vec2&& v) IMATH_NOEXCEPT = default; @@ -389,13 +389,13 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 IMATH_HOSTDEVICE constexpr Vec3 (T a, T b, T c) IMATH_NOEXCEPT; /// Copy constructor -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 IMATH_HOSTDEVICE constexpr Vec3 (const Vec3& v) IMATH_NOEXCEPT = default; #else IMATH_HOSTDEVICE constexpr Vec3 (const Vec3& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 /// Move constructor IMATH_HOSTDEVICE constexpr Vec3 (Vec3&& v) IMATH_NOEXCEPT = default; #endif @@ -417,7 +417,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 Vec3 (const Vec4& v, InfException); /// Copy assignment -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec3& operator= (const Vec3& v) IMATH_NOEXCEPT = default; #else @@ -425,7 +425,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 operator= (const Vec3& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 /// Move assignment IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec3& operator= (Vec3&& v) IMATH_NOEXCEPT = default; @@ -730,13 +730,13 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 IMATH_HOSTDEVICE constexpr Vec4 (T a, T b, T c, T d) IMATH_NOEXCEPT; /// Copy constructor -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 IMATH_HOSTDEVICE constexpr Vec4 (const Vec4& v) IMATH_NOEXCEPT = default; #else IMATH_HOSTDEVICE constexpr Vec4 (const Vec4& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 /// Move constructor IMATH_HOSTDEVICE constexpr Vec4 (Vec4&& v) IMATH_NOEXCEPT = default; #endif @@ -750,7 +750,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 IMATH_HOSTDEVICE explicit constexpr Vec4 (const Vec3& v) IMATH_NOEXCEPT; /// Copy assignment -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec4& operator= (const Vec4& v) IMATH_NOEXCEPT = default; #else @@ -758,7 +758,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 operator= (const Vec4& v) IMATH_NOEXCEPT; #endif -#ifdef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 /// Move assignment IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec4& operator= (Vec4&& v) IMATH_NOEXCEPT = default; @@ -1272,7 +1272,7 @@ IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (T a, T b) IMATH_NOEXCEPT y (b) {} -#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 template IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (const Vec2& v) IMATH_NOEXCEPT : x (v.x), @@ -1287,7 +1287,7 @@ IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (const Vec2& v) y (T (v.y)) {} -#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 template IMATH_CONSTEXPR14 IMATH_HOSTDEVICE inline const Vec2& Vec2::operator= (const Vec2& v) IMATH_NOEXCEPT @@ -1682,7 +1682,7 @@ IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (T a, T b, T c) IMATH_NOEXCEPT z (c) {} -#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 template IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec3& v) IMATH_NOEXCEPT : x (v.x), @@ -1699,7 +1699,7 @@ IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec3& v) z (T (v.z)) {} -#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec3& Vec3::operator= (const Vec3& v) IMATH_NOEXCEPT @@ -2161,7 +2161,7 @@ IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (T a, T b, T c, T d) w (d) {} -#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 template IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec4& v) IMATH_NOEXCEPT : x (v.x), @@ -2180,7 +2180,7 @@ IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec4& v) w (T (v.w)) {} -#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR +#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec4& Vec4::operator= (const Vec4& v) IMATH_NOEXCEPT From c49dc99a52ba136a8ad02f61264b62a38cf9b878 Mon Sep 17 00:00:00 2001 From: Yuya Asano <64895419+sukeya@users.noreply.github.com> Date: Sat, 22 Jul 2023 12:43:31 +0900 Subject: [PATCH 06/13] [wip] add a test for ImathVec when using default. Signed-off-by: Yuya Asano <64895419+sukeya@users.noreply.github.com> --- src/ImathTest/CMakeLists.txt | 9 +- src/ImathTest/main.cpp | 2 + .../testVecUseDefaultConstructor.cpp | 268 ++++++++++++++++++ src/ImathTest/testVecUseDefaultConstructor.h | 6 + 4 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 src/ImathTest/testVecUseDefaultConstructor.cpp create mode 100644 src/ImathTest/testVecUseDefaultConstructor.h diff --git a/src/ImathTest/CMakeLists.txt b/src/ImathTest/CMakeLists.txt index 58820316..d739ff73 100644 --- a/src/ImathTest/CMakeLists.txt +++ b/src/ImathTest/CMakeLists.txt @@ -11,6 +11,12 @@ if("${CMAKE_PROJECT_NAME}" STREQUAL "") find_package(Imath) endif() +add_library(ImathTestVecUseDefaultConstructor + testVecUseDefaultConstructor.h + testVecUseDefaultConstructor.cpp +) +target_link_libraries(ImathTestVecUseDefaultConstructor PRIVATE Imath::Imath Imath::Config) + add_executable(ImathTest main.cpp testBox.cpp @@ -48,7 +54,7 @@ add_executable(ImathTest testNoInterop.cpp ) -target_link_libraries(ImathTest Imath::Imath) +target_link_libraries(ImathTest Imath::Imath ImathTestVecUseDefaultConstructor) set_target_properties(ImathTest PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" ) @@ -121,5 +127,6 @@ define_imath_tests( testFrustumTest testInterop testNoInterop + testVecUseDefaultConstructor ) diff --git a/src/ImathTest/main.cpp b/src/ImathTest/main.cpp index cc8ab569..0047aaf7 100644 --- a/src/ImathTest/main.cpp +++ b/src/ImathTest/main.cpp @@ -40,6 +40,7 @@ #include "testTinySVD.h" #include "testToFloat.h" #include "testVec.h" +#include "testVecUseDefaultConstructor.h" #include #include @@ -88,6 +89,7 @@ main (int argc, char* argv[]) TEST (testFrustumTest); TEST (testInterop); TEST (testNoInterop); + TEST (testVecUseDefaultConstructor) // NB: If you add a test here, make sure to enumerate it in the // CMakeLists.txt so it runs as part of the test suite diff --git a/src/ImathTest/testVecUseDefaultConstructor.cpp b/src/ImathTest/testVecUseDefaultConstructor.cpp new file mode 100644 index 00000000..7f9194bb --- /dev/null +++ b/src/ImathTest/testVecUseDefaultConstructor.cpp @@ -0,0 +1,268 @@ +// +// SPDX-License-Identifier: BSD-3-Clause +// Copyright Contributors to the OpenEXR Project. +// + +#ifdef NDEBUG +# undef NDEBUG +#endif + +#define IMATH_VEC_USE_DEFAULT_CONSTRUCTOR 1 + +#include "testVecUseDefaultConstructor.h" +#include +#include +#include +#include +#include + +// Include ImathForward *after* other headers to validate forward declarations +#include + +using namespace std; +using namespace IMATH_INTERNAL_NAMESPACE; + +namespace +{ + +template +void +testLength2T () +{ + const T s = std::sqrt (std::numeric_limits::min ()); + const T e = 4 * std::numeric_limits::epsilon (); + + Vec2 v; + + v = Vec2 (0, 0); + assert (v.length () == 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 0, e)); + + v = Vec2 (3, 4); + assert (v.length () == 5); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + + v = Vec2 (3000, 4000); + assert (v.length () == 5000); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + + T t = s * (1 << 4); + + v = Vec2 (t, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec2 (0, t); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec2 (-t, -t); + assert (IMATH_INTERNAL_NAMESPACE::equal ( + v.length (), t * std::sqrt (2), t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + + t = s / (1 << 4); + + v = Vec2 (t, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec2 (0, t); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec2 (-t, -t); + assert (IMATH_INTERNAL_NAMESPACE::equal ( + v.length (), t * std::sqrt (2), t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + + t = s / (1 << 20); + + v = Vec2 (t, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec2 (0, t); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec2 (-t, -t); + assert (IMATH_INTERNAL_NAMESPACE::equal ( + v.length (), t * std::sqrt (2), t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); +} + +template +void +testLength3T () +{ + const T s = std::sqrt (std::numeric_limits::min ()); + const T e = 4 * std::numeric_limits::epsilon (); + + Vec3 v; + + v = Vec3 (0, 0, 0); + assert (v.length () == 0); + assert (v.normalized ().length () == 0); + + v = Vec3 (3, 4, 0); + assert (v.length () == 5); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + + v = Vec3 (3000, 4000, 0); + assert (v.length () == 5000); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + + v = Vec3 (1, -1, 1); + assert ( + IMATH_INTERNAL_NAMESPACE::equal (v.length (), 1 * std::sqrt (3), e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + + v = Vec3 (1000, -1000, 1000); + assert (IMATH_INTERNAL_NAMESPACE::equal ( + v.length (), 1000 * std::sqrt (3), 1000 * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + + T t = s * (1 << 4); + + v = Vec3 (t, 0, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec3 (0, t, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec3 (0, 0, t); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec3 (-t, -t, -t); + assert (IMATH_INTERNAL_NAMESPACE::equal ( + v.length (), t * std::sqrt (3), t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + + t = s / (1 << 4); + + v = Vec3 (t, 0, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec3 (0, t, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec3 (0, 0, t); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec3 (-t, -t, -t); + assert (IMATH_INTERNAL_NAMESPACE::equal ( + v.length (), t * std::sqrt (3), t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + + t = s / (1 << 20); + + v = Vec3 (t, 0, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec3 (0, t, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec3 (0, 0, t); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec3 (-t, -t, -t); + assert (IMATH_INTERNAL_NAMESPACE::equal ( + v.length (), t * std::sqrt (3), t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); +} + +template +void +testLength4T () +{ + const T s = std::sqrt (std::numeric_limits::min ()); + const T e = 4 * std::numeric_limits::epsilon (); + + Vec4 v; + + v = Vec4 (0, 0, 0, 0); + assert (v.length () == 0); + assert (v.normalized ().length () == 0); + + v = Vec4 (3, 4, 0, 0); + assert (v.length () == 5); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + + v = Vec4 (3000, 4000, 0, 0); + assert (v.length () == 5000); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + + v = Vec4 (1, -1, 1, 1); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), 2, e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + + v = Vec4 (1000, -1000, 1000, 1000); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), 2000, 1000 * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + + T t = s * (1 << 4); + + v = Vec4 (t, 0, 0, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec4 (0, t, 0, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec4 (0, 0, t, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec4 (0, 0, 0, t); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec4 (-t, -t, -t, -t); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t * 2, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + + t = s / (1 << 4); + + v = Vec4 (t, 0, 0, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec4 (0, t, 0, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec4 (0, 0, t, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec4 (0, 0, 0, t); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec4 (-t, -t, -t, -t); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t * 2, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + + t = s / (1 << 20); + + v = Vec4 (t, 0, 0, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec4 (0, t, 0, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec4 (0, 0, t, 0); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec4 (0, 0, 0, t); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); + v = Vec4 (-t, -t, -t, -t); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.length (), t * 2, t * e)); + assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); +} + +} // namespace + +void +testVecUseDefaultConstructor () +{ + cout << "Testing some basic vector operations using default constructor" << endl; + + testLength2T (); + testLength2T (); + testLength3T (); + testLength3T (); + testLength4T (); + testLength4T (); + + cout << "ok\n" << endl; +} diff --git a/src/ImathTest/testVecUseDefaultConstructor.h b/src/ImathTest/testVecUseDefaultConstructor.h new file mode 100644 index 00000000..312c626a --- /dev/null +++ b/src/ImathTest/testVecUseDefaultConstructor.h @@ -0,0 +1,6 @@ +// +// SPDX-License-Identifier: BSD-3-Clause +// Copyright Contributors to the OpenEXR Project. +// + +void testVecUseDefaultConstructor (); From 5d4ed114f09c9cd8ba325c22a47a720c282aa5ff Mon Sep 17 00:00:00 2001 From: Yuya Asano <64895419+sukeya@users.noreply.github.com> Date: Sat, 22 Jul 2023 13:55:14 +0900 Subject: [PATCH 07/13] Remove Imath::Config from ImathTestVecUseDefaultConstructor. Signed-off-by: Yuya Asano <64895419+sukeya@users.noreply.github.com> --- src/Imath/ImathVec.h | 61 +++++++++++++++++-- src/ImathTest/CMakeLists.txt | 2 +- src/ImathTest/main.cpp | 2 + .../testVecUseDefaultConstructor.cpp | 3 + 4 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/Imath/ImathVec.h b/src/Imath/ImathVec.h index 6ff65c65..1049d01a 100644 --- a/src/Imath/ImathVec.h +++ b/src/Imath/ImathVec.h @@ -20,6 +20,8 @@ #include #include #include +#include +#include #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER // suppress exception specification warnings @@ -69,7 +71,10 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 IMATH_HOSTDEVICE constexpr explicit Vec2 (T a) IMATH_NOEXCEPT; /// Initialize to given elements `(a,b)` - IMATH_HOSTDEVICE constexpr Vec2 (T a, T b) IMATH_NOEXCEPT; + IMATH_HOSTDEVICE constexpr explicit Vec2 (T a, T b) IMATH_NOEXCEPT; + + /// Initialize to given initializer list `{a,b}` + IMATH_HOSTDEVICE constexpr Vec2 (std::initializer_list l) IMATH_NOEXCEPT; /// Copy constructor #if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 @@ -386,7 +391,10 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 IMATH_HOSTDEVICE constexpr explicit Vec3 (T a) IMATH_NOEXCEPT; /// Initialize to given elements `(a,b,c)` - IMATH_HOSTDEVICE constexpr Vec3 (T a, T b, T c) IMATH_NOEXCEPT; + IMATH_HOSTDEVICE constexpr explicit Vec3 (T a, T b, T c) IMATH_NOEXCEPT; + + /// Initialize to given initializer list `{a,b,c}` + IMATH_HOSTDEVICE constexpr Vec3 (std::initializer_list l) IMATH_NOEXCEPT; /// Copy constructor #if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 @@ -727,7 +735,10 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 IMATH_HOSTDEVICE constexpr explicit Vec4 (T a) IMATH_NOEXCEPT; /// Initialize to given elements `(a,b,c,d)` - IMATH_HOSTDEVICE constexpr Vec4 (T a, T b, T c, T d) IMATH_NOEXCEPT; + IMATH_HOSTDEVICE constexpr explicit Vec4 (T a, T b, T c, T d) IMATH_NOEXCEPT; + + /// Initialize to given initializer list `{a,b,c,d}` + IMATH_HOSTDEVICE constexpr Vec4 (std::initializer_list l) IMATH_NOEXCEPT; /// Copy constructor #if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 @@ -1272,6 +1283,17 @@ IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (T a, T b) IMATH_NOEXCEPT y (b) {} +template +IMATH_HOSTDEVICE constexpr Vec2::Vec2 (std::initializer_list l) IMATH_NOEXCEPT +{ + assert (l.size() == 2); + + auto it = l.begin(); + x = *it; + ++it; + y = *it; +} + #if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 template IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (const Vec2& v) IMATH_NOEXCEPT @@ -1623,7 +1645,10 @@ Vec2::normalized () const IMATH_NOEXCEPT if (IMATH_UNLIKELY (l == T (0))) return Vec2 (T (0)); - return Vec2 (x / l, y / l); + auto v = Vec2 (x / l, y / l); + + std::cout << "In normalized: " << v.x << ", " << v.y << std::endl; + return v; } template @@ -1682,6 +1707,19 @@ IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (T a, T b, T c) IMATH_NOEXCEPT z (c) {} +template +IMATH_HOSTDEVICE constexpr Vec3::Vec3 (std::initializer_list l) IMATH_NOEXCEPT +{ + assert(l.size() == 3); + + auto it = l.begin(); + x = *it; + ++it; + y = *it; + ++it; + z = *it; +} + #if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 template IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec3& v) IMATH_NOEXCEPT @@ -2161,6 +2199,21 @@ IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (T a, T b, T c, T d) w (d) {} +template +IMATH_HOSTDEVICE constexpr Vec4::Vec4 (std::initializer_list l) IMATH_NOEXCEPT +{ + assert(l.size() == 4); + + auto it = l.begin(); + x = *it; + ++it; + y = *it; + ++it; + z = *it; + ++it; + w = *it; +} + #if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 template IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec4& v) IMATH_NOEXCEPT diff --git a/src/ImathTest/CMakeLists.txt b/src/ImathTest/CMakeLists.txt index d739ff73..00516ef8 100644 --- a/src/ImathTest/CMakeLists.txt +++ b/src/ImathTest/CMakeLists.txt @@ -15,7 +15,7 @@ add_library(ImathTestVecUseDefaultConstructor testVecUseDefaultConstructor.h testVecUseDefaultConstructor.cpp ) -target_link_libraries(ImathTestVecUseDefaultConstructor PRIVATE Imath::Imath Imath::Config) +target_link_libraries(ImathTestVecUseDefaultConstructor PRIVATE Imath::Imath) add_executable(ImathTest main.cpp diff --git a/src/ImathTest/main.cpp b/src/ImathTest/main.cpp index 0047aaf7..4c574b8e 100644 --- a/src/ImathTest/main.cpp +++ b/src/ImathTest/main.cpp @@ -53,6 +53,7 @@ main (int argc, char* argv[]) { // NB: If you add a test here, make sure to enumerate it in the // CMakeLists.txt so it runs as part of the test suite + /* TEST (testToFloat); TEST (testSize); TEST (testArithmetic); @@ -89,6 +90,7 @@ main (int argc, char* argv[]) TEST (testFrustumTest); TEST (testInterop); TEST (testNoInterop); + */ TEST (testVecUseDefaultConstructor) // NB: If you add a test here, make sure to enumerate it in the // CMakeLists.txt so it runs as part of the test suite diff --git a/src/ImathTest/testVecUseDefaultConstructor.cpp b/src/ImathTest/testVecUseDefaultConstructor.cpp index 7f9194bb..48ddea39 100644 --- a/src/ImathTest/testVecUseDefaultConstructor.cpp +++ b/src/ImathTest/testVecUseDefaultConstructor.cpp @@ -40,6 +40,9 @@ testLength2T () v = Vec2 (3, 4); assert (v.length () == 5); + std::cout << v.x << ", " << v.y << std::endl; + auto nv = v.normalized(); + std::cout << nv.x << ", " << nv.y << std::endl; assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); v = Vec2 (3000, 4000); From 63478fc763775ab014393cf4b1301715c418b965 Mon Sep 17 00:00:00 2001 From: Yuya Asano <64895419+sukeya@users.noreply.github.com> Date: Sat, 22 Jul 2023 14:00:02 +0900 Subject: [PATCH 08/13] Revert "Remove Imath::Config from ImathTestVecUseDefaultConstructor." This reverts commit 5d4ed114f09c9cd8ba325c22a47a720c282aa5ff. Signed-off-by: Yuya Asano <64895419+sukeya@users.noreply.github.com> --- src/Imath/ImathVec.h | 61 ++----------------- src/ImathTest/CMakeLists.txt | 2 +- src/ImathTest/main.cpp | 2 - .../testVecUseDefaultConstructor.cpp | 3 - 4 files changed, 5 insertions(+), 63 deletions(-) diff --git a/src/Imath/ImathVec.h b/src/Imath/ImathVec.h index 1049d01a..6ff65c65 100644 --- a/src/Imath/ImathVec.h +++ b/src/Imath/ImathVec.h @@ -20,8 +20,6 @@ #include #include #include -#include -#include #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER // suppress exception specification warnings @@ -71,10 +69,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 IMATH_HOSTDEVICE constexpr explicit Vec2 (T a) IMATH_NOEXCEPT; /// Initialize to given elements `(a,b)` - IMATH_HOSTDEVICE constexpr explicit Vec2 (T a, T b) IMATH_NOEXCEPT; - - /// Initialize to given initializer list `{a,b}` - IMATH_HOSTDEVICE constexpr Vec2 (std::initializer_list l) IMATH_NOEXCEPT; + IMATH_HOSTDEVICE constexpr Vec2 (T a, T b) IMATH_NOEXCEPT; /// Copy constructor #if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 @@ -391,10 +386,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 IMATH_HOSTDEVICE constexpr explicit Vec3 (T a) IMATH_NOEXCEPT; /// Initialize to given elements `(a,b,c)` - IMATH_HOSTDEVICE constexpr explicit Vec3 (T a, T b, T c) IMATH_NOEXCEPT; - - /// Initialize to given initializer list `{a,b,c}` - IMATH_HOSTDEVICE constexpr Vec3 (std::initializer_list l) IMATH_NOEXCEPT; + IMATH_HOSTDEVICE constexpr Vec3 (T a, T b, T c) IMATH_NOEXCEPT; /// Copy constructor #if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 @@ -735,10 +727,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 IMATH_HOSTDEVICE constexpr explicit Vec4 (T a) IMATH_NOEXCEPT; /// Initialize to given elements `(a,b,c,d)` - IMATH_HOSTDEVICE constexpr explicit Vec4 (T a, T b, T c, T d) IMATH_NOEXCEPT; - - /// Initialize to given initializer list `{a,b,c,d}` - IMATH_HOSTDEVICE constexpr Vec4 (std::initializer_list l) IMATH_NOEXCEPT; + IMATH_HOSTDEVICE constexpr Vec4 (T a, T b, T c, T d) IMATH_NOEXCEPT; /// Copy constructor #if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 @@ -1283,17 +1272,6 @@ IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (T a, T b) IMATH_NOEXCEPT y (b) {} -template -IMATH_HOSTDEVICE constexpr Vec2::Vec2 (std::initializer_list l) IMATH_NOEXCEPT -{ - assert (l.size() == 2); - - auto it = l.begin(); - x = *it; - ++it; - y = *it; -} - #if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 template IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (const Vec2& v) IMATH_NOEXCEPT @@ -1645,10 +1623,7 @@ Vec2::normalized () const IMATH_NOEXCEPT if (IMATH_UNLIKELY (l == T (0))) return Vec2 (T (0)); - auto v = Vec2 (x / l, y / l); - - std::cout << "In normalized: " << v.x << ", " << v.y << std::endl; - return v; + return Vec2 (x / l, y / l); } template @@ -1707,19 +1682,6 @@ IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (T a, T b, T c) IMATH_NOEXCEPT z (c) {} -template -IMATH_HOSTDEVICE constexpr Vec3::Vec3 (std::initializer_list l) IMATH_NOEXCEPT -{ - assert(l.size() == 3); - - auto it = l.begin(); - x = *it; - ++it; - y = *it; - ++it; - z = *it; -} - #if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 template IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec3& v) IMATH_NOEXCEPT @@ -2199,21 +2161,6 @@ IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (T a, T b, T c, T d) w (d) {} -template -IMATH_HOSTDEVICE constexpr Vec4::Vec4 (std::initializer_list l) IMATH_NOEXCEPT -{ - assert(l.size() == 4); - - auto it = l.begin(); - x = *it; - ++it; - y = *it; - ++it; - z = *it; - ++it; - w = *it; -} - #if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 template IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec4& v) IMATH_NOEXCEPT diff --git a/src/ImathTest/CMakeLists.txt b/src/ImathTest/CMakeLists.txt index 00516ef8..d739ff73 100644 --- a/src/ImathTest/CMakeLists.txt +++ b/src/ImathTest/CMakeLists.txt @@ -15,7 +15,7 @@ add_library(ImathTestVecUseDefaultConstructor testVecUseDefaultConstructor.h testVecUseDefaultConstructor.cpp ) -target_link_libraries(ImathTestVecUseDefaultConstructor PRIVATE Imath::Imath) +target_link_libraries(ImathTestVecUseDefaultConstructor PRIVATE Imath::Imath Imath::Config) add_executable(ImathTest main.cpp diff --git a/src/ImathTest/main.cpp b/src/ImathTest/main.cpp index 4c574b8e..0047aaf7 100644 --- a/src/ImathTest/main.cpp +++ b/src/ImathTest/main.cpp @@ -53,7 +53,6 @@ main (int argc, char* argv[]) { // NB: If you add a test here, make sure to enumerate it in the // CMakeLists.txt so it runs as part of the test suite - /* TEST (testToFloat); TEST (testSize); TEST (testArithmetic); @@ -90,7 +89,6 @@ main (int argc, char* argv[]) TEST (testFrustumTest); TEST (testInterop); TEST (testNoInterop); - */ TEST (testVecUseDefaultConstructor) // NB: If you add a test here, make sure to enumerate it in the // CMakeLists.txt so it runs as part of the test suite diff --git a/src/ImathTest/testVecUseDefaultConstructor.cpp b/src/ImathTest/testVecUseDefaultConstructor.cpp index 48ddea39..7f9194bb 100644 --- a/src/ImathTest/testVecUseDefaultConstructor.cpp +++ b/src/ImathTest/testVecUseDefaultConstructor.cpp @@ -40,9 +40,6 @@ testLength2T () v = Vec2 (3, 4); assert (v.length () == 5); - std::cout << v.x << ", " << v.y << std::endl; - auto nv = v.normalized(); - std::cout << nv.x << ", " << nv.y << std::endl; assert (IMATH_INTERNAL_NAMESPACE::equal (v.normalized ().length (), 1, e)); v = Vec2 (3000, 4000); From 536b4304e4756faf5d1ee1fa6f6378dbe6599da2 Mon Sep 17 00:00:00 2001 From: Yuya Asano <64895419+sukeya@users.noreply.github.com> Date: Sat, 22 Jul 2023 14:00:58 +0900 Subject: [PATCH 09/13] Remove Imath::Config from ImathTestVecUseDefaultConstructor. Signed-off-by: Yuya Asano <64895419+sukeya@users.noreply.github.com> --- src/ImathTest/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImathTest/CMakeLists.txt b/src/ImathTest/CMakeLists.txt index d739ff73..00516ef8 100644 --- a/src/ImathTest/CMakeLists.txt +++ b/src/ImathTest/CMakeLists.txt @@ -15,7 +15,7 @@ add_library(ImathTestVecUseDefaultConstructor testVecUseDefaultConstructor.h testVecUseDefaultConstructor.cpp ) -target_link_libraries(ImathTestVecUseDefaultConstructor PRIVATE Imath::Imath Imath::Config) +target_link_libraries(ImathTestVecUseDefaultConstructor PRIVATE Imath::Imath) add_executable(ImathTest main.cpp From 961ac87b332f3a4e3b5c7adb7925a16fab8afa95 Mon Sep 17 00:00:00 2001 From: Yuya Asano <64895419+sukeya@users.noreply.github.com> Date: Mon, 24 Jul 2023 11:57:24 +0900 Subject: [PATCH 10/13] Fix assertion errors and clean up. Signed-off-by: Yuya Asano <64895419+sukeya@users.noreply.github.com> --- config/ImathConfig.h.in | 4 +- src/Imath/ImathVec.h | 57 ++++--------------- src/ImathTest/CMakeLists.txt | 16 +++--- src/ImathTest/main.cpp | 2 - ...or.cpp => testVecTriviallyRelocatable.cpp} | 8 +-- ...ructor.h => testVecTriviallyRelocatable.h} | 2 +- .../vec_trivially_relocatable_main.cpp | 28 +++++++++ 7 files changed, 55 insertions(+), 62 deletions(-) rename src/ImathTest/{testVecUseDefaultConstructor.cpp => testVecTriviallyRelocatable.cpp} (97%) rename src/ImathTest/{testVecUseDefaultConstructor.h => testVecTriviallyRelocatable.h} (72%) create mode 100644 src/ImathTest/vec_trivially_relocatable_main.cpp diff --git a/config/ImathConfig.h.in b/config/ImathConfig.h.in index e4fca5ef..6e1ddab4 100644 --- a/config/ImathConfig.h.in +++ b/config/ImathConfig.h.in @@ -175,8 +175,8 @@ #endif // Whether the copy and move constructors of Vec2, Vec3 and Vec4 are default or not. -#ifndef IMATH_VEC_USE_DEFAULT_CONSTRUCTOR -# define IMATH_VEC_USE_DEFAULT_CONSTRUCTOR 0 +#ifndef IMATH_VEC_BE_TRIVIALLY_RELOCATABLE +# define IMATH_VEC_BE_TRIVIALLY_RELOCATABLE 0 #endif #endif // INCLUDED_IMATH_CONFIG_H diff --git a/src/Imath/ImathVec.h b/src/Imath/ImathVec.h index 6ff65c65..77c474ba 100644 --- a/src/Imath/ImathVec.h +++ b/src/Imath/ImathVec.h @@ -72,23 +72,18 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 IMATH_HOSTDEVICE constexpr Vec2 (T a, T b) IMATH_NOEXCEPT; /// Copy constructor -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 +#if IMATH_VEC_BE_TRIVIALLY_RELOCATABLE != 0 IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT = default; #else IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT; #endif -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 - /// Move constructor - IMATH_HOSTDEVICE constexpr Vec2 (Vec2&& v) IMATH_NOEXCEPT = default; -#endif - /// Construct from Vec2 of another base type template IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT; /// Copy assignment -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 +#if IMATH_VEC_BE_TRIVIALLY_RELOCATABLE != 0 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec2& operator= (const Vec2& v) IMATH_NOEXCEPT = default; #else @@ -96,12 +91,6 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 operator= (const Vec2& v) IMATH_NOEXCEPT; #endif -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 - /// Move assignment - IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec2& - operator= (Vec2&& v) IMATH_NOEXCEPT = default; -#endif - /// Destructor ~Vec2 () IMATH_NOEXCEPT = default; @@ -389,17 +378,12 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 IMATH_HOSTDEVICE constexpr Vec3 (T a, T b, T c) IMATH_NOEXCEPT; /// Copy constructor -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 +#if IMATH_VEC_BE_TRIVIALLY_RELOCATABLE != 0 IMATH_HOSTDEVICE constexpr Vec3 (const Vec3& v) IMATH_NOEXCEPT = default; #else IMATH_HOSTDEVICE constexpr Vec3 (const Vec3& v) IMATH_NOEXCEPT; #endif -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 - /// Move constructor - IMATH_HOSTDEVICE constexpr Vec3 (Vec3&& v) IMATH_NOEXCEPT = default; -#endif - /// Construct from Vec3 of another base type template IMATH_HOSTDEVICE constexpr Vec3 (const Vec3& v) IMATH_NOEXCEPT; @@ -417,7 +401,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 Vec3 (const Vec4& v, InfException); /// Copy assignment -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 +#if IMATH_VEC_BE_TRIVIALLY_RELOCATABLE != 0 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec3& operator= (const Vec3& v) IMATH_NOEXCEPT = default; #else @@ -425,12 +409,6 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec3 operator= (const Vec3& v) IMATH_NOEXCEPT; #endif -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 - /// Move assignment - IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec3& - operator= (Vec3&& v) IMATH_NOEXCEPT = default; -#endif - /// Destructor ~Vec3 () IMATH_NOEXCEPT = default; @@ -730,17 +708,12 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 IMATH_HOSTDEVICE constexpr Vec4 (T a, T b, T c, T d) IMATH_NOEXCEPT; /// Copy constructor -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 +#if IMATH_VEC_BE_TRIVIALLY_RELOCATABLE != 0 IMATH_HOSTDEVICE constexpr Vec4 (const Vec4& v) IMATH_NOEXCEPT = default; #else IMATH_HOSTDEVICE constexpr Vec4 (const Vec4& v) IMATH_NOEXCEPT; #endif -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 - /// Move constructor - IMATH_HOSTDEVICE constexpr Vec4 (Vec4&& v) IMATH_NOEXCEPT = default; -#endif - /// Construct from Vec4 of another base type template IMATH_HOSTDEVICE constexpr Vec4 (const Vec4& v) IMATH_NOEXCEPT; @@ -750,7 +723,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 IMATH_HOSTDEVICE explicit constexpr Vec4 (const Vec3& v) IMATH_NOEXCEPT; /// Copy assignment -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 +#if IMATH_VEC_BE_TRIVIALLY_RELOCATABLE != 0 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec4& operator= (const Vec4& v) IMATH_NOEXCEPT = default; #else @@ -758,12 +731,6 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 operator= (const Vec4& v) IMATH_NOEXCEPT; #endif -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR != 0 - /// Move assignment - IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec4& - operator= (Vec4&& v) IMATH_NOEXCEPT = default; -#endif - /// Destructor ~Vec4 () IMATH_NOEXCEPT = default; @@ -1272,7 +1239,7 @@ IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (T a, T b) IMATH_NOEXCEPT y (b) {} -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 +#if IMATH_VEC_BE_TRIVIALLY_RELOCATABLE == 0 template IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (const Vec2& v) IMATH_NOEXCEPT : x (v.x), @@ -1287,7 +1254,7 @@ IMATH_HOSTDEVICE constexpr inline Vec2::Vec2 (const Vec2& v) y (T (v.y)) {} -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 +#if IMATH_VEC_BE_TRIVIALLY_RELOCATABLE == 0 template IMATH_CONSTEXPR14 IMATH_HOSTDEVICE inline const Vec2& Vec2::operator= (const Vec2& v) IMATH_NOEXCEPT @@ -1682,7 +1649,7 @@ IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (T a, T b, T c) IMATH_NOEXCEPT z (c) {} -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 +#if IMATH_VEC_BE_TRIVIALLY_RELOCATABLE == 0 template IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec3& v) IMATH_NOEXCEPT : x (v.x), @@ -1699,7 +1666,7 @@ IMATH_HOSTDEVICE constexpr inline Vec3::Vec3 (const Vec3& v) z (T (v.z)) {} -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 +#if IMATH_VEC_BE_TRIVIALLY_RELOCATABLE == 0 template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec3& Vec3::operator= (const Vec3& v) IMATH_NOEXCEPT @@ -2161,7 +2128,7 @@ IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (T a, T b, T c, T d) w (d) {} -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 +#if IMATH_VEC_BE_TRIVIALLY_RELOCATABLE == 0 template IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec4& v) IMATH_NOEXCEPT : x (v.x), @@ -2180,7 +2147,7 @@ IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec4& v) w (T (v.w)) {} -#if IMATH_VEC_USE_DEFAULT_CONSTRUCTOR == 0 +#if IMATH_VEC_BE_TRIVIALLY_RELOCATABLE == 0 template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline const Vec4& Vec4::operator= (const Vec4& v) IMATH_NOEXCEPT diff --git a/src/ImathTest/CMakeLists.txt b/src/ImathTest/CMakeLists.txt index 00516ef8..c135240d 100644 --- a/src/ImathTest/CMakeLists.txt +++ b/src/ImathTest/CMakeLists.txt @@ -11,12 +11,6 @@ if("${CMAKE_PROJECT_NAME}" STREQUAL "") find_package(Imath) endif() -add_library(ImathTestVecUseDefaultConstructor - testVecUseDefaultConstructor.h - testVecUseDefaultConstructor.cpp -) -target_link_libraries(ImathTestVecUseDefaultConstructor PRIVATE Imath::Imath) - add_executable(ImathTest main.cpp testBox.cpp @@ -54,7 +48,7 @@ add_executable(ImathTest testNoInterop.cpp ) -target_link_libraries(ImathTest Imath::Imath ImathTestVecUseDefaultConstructor) +target_link_libraries(ImathTest Imath::Imath) set_target_properties(ImathTest PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" ) @@ -84,6 +78,13 @@ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" target_link_libraries(ImathHalfPerfTest Imath::Imath) add_test(NAME Imath.half_perf_test COMMAND $) +add_executable(ImathVecTriviallyRelocatableTest vec_trivially_relocatable_main.cpp testVecTriviallyRelocatable.cpp) +set_target_properties(ImathVecTriviallyRelocatableTest PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" +) +target_link_libraries(ImathVecTriviallyRelocatableTest Imath::Imath) +add_test(NAME Imath.vec_trivially_relocatable_test COMMAND $) + function(DEFINE_IMATH_TESTS) foreach(curtest IN LISTS ARGN) add_test(NAME Imath.${curtest} COMMAND $ ${curtest}) @@ -127,6 +128,5 @@ define_imath_tests( testFrustumTest testInterop testNoInterop - testVecUseDefaultConstructor ) diff --git a/src/ImathTest/main.cpp b/src/ImathTest/main.cpp index 0047aaf7..cc8ab569 100644 --- a/src/ImathTest/main.cpp +++ b/src/ImathTest/main.cpp @@ -40,7 +40,6 @@ #include "testTinySVD.h" #include "testToFloat.h" #include "testVec.h" -#include "testVecUseDefaultConstructor.h" #include #include @@ -89,7 +88,6 @@ main (int argc, char* argv[]) TEST (testFrustumTest); TEST (testInterop); TEST (testNoInterop); - TEST (testVecUseDefaultConstructor) // NB: If you add a test here, make sure to enumerate it in the // CMakeLists.txt so it runs as part of the test suite diff --git a/src/ImathTest/testVecUseDefaultConstructor.cpp b/src/ImathTest/testVecTriviallyRelocatable.cpp similarity index 97% rename from src/ImathTest/testVecUseDefaultConstructor.cpp rename to src/ImathTest/testVecTriviallyRelocatable.cpp index 7f9194bb..a5ed6415 100644 --- a/src/ImathTest/testVecUseDefaultConstructor.cpp +++ b/src/ImathTest/testVecTriviallyRelocatable.cpp @@ -7,9 +7,9 @@ # undef NDEBUG #endif -#define IMATH_VEC_USE_DEFAULT_CONSTRUCTOR 1 +#define IMATH_VEC_BE_TRIVIALLY_RELOCATABLE 1 -#include "testVecUseDefaultConstructor.h" +#include "testVecTriviallyRelocatable.h" #include #include #include @@ -253,9 +253,9 @@ testLength4T () } // namespace void -testVecUseDefaultConstructor () +testVecTriviallyRelocatable () { - cout << "Testing some basic vector operations using default constructor" << endl; + cout << "Testing some basic vector operations when vectors are trivially relocatable." << endl; testLength2T (); testLength2T (); diff --git a/src/ImathTest/testVecUseDefaultConstructor.h b/src/ImathTest/testVecTriviallyRelocatable.h similarity index 72% rename from src/ImathTest/testVecUseDefaultConstructor.h rename to src/ImathTest/testVecTriviallyRelocatable.h index 312c626a..62bdd641 100644 --- a/src/ImathTest/testVecUseDefaultConstructor.h +++ b/src/ImathTest/testVecTriviallyRelocatable.h @@ -3,4 +3,4 @@ // Copyright Contributors to the OpenEXR Project. // -void testVecUseDefaultConstructor (); +void testVecTriviallyRelocatable (); diff --git a/src/ImathTest/vec_trivially_relocatable_main.cpp b/src/ImathTest/vec_trivially_relocatable_main.cpp new file mode 100644 index 00000000..e2e17b0a --- /dev/null +++ b/src/ImathTest/vec_trivially_relocatable_main.cpp @@ -0,0 +1,28 @@ +// +// SPDX-License-Identifier: BSD-3-Clause +// Copyright Contributors to the OpenEXR Project. +// + +#ifdef NDEBUG +# undef NDEBUG +#endif + +#include "testVecTriviallyRelocatable.h" + +#include +#include + +#define TEST(x) \ + if (argc < 2 || !strcmp (argv[1], #x)) x (); + +int +main (int argc, char* argv[]) +{ + // NB: If you add a test here, make sure to enumerate it in the + // CMakeLists.txt so it runs as part of the test suite + TEST (testVecTriviallyRelocatable) + // NB: If you add a test here, make sure to enumerate it in the + // CMakeLists.txt so it runs as part of the test suite + + return 0; +} From 03f055f8b55387b4552487ca21b4dc7021c4c078 Mon Sep 17 00:00:00 2001 From: Yuya Asano <64895419+sukeya@users.noreply.github.com> Date: Wed, 13 Mar 2024 16:49:39 +0900 Subject: [PATCH 11/13] Update src/Imath/ImathVec.h Co-authored-by: Arthur O'Dwyer Signed-off-by: Yuya Asano <64895419+sukeya@users.noreply.github.com> --- src/Imath/ImathVec.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Imath/ImathVec.h b/src/Imath/ImathVec.h index 77c474ba..32159086 100644 --- a/src/Imath/ImathVec.h +++ b/src/Imath/ImathVec.h @@ -73,7 +73,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 /// Copy constructor #if IMATH_VEC_BE_TRIVIALLY_RELOCATABLE != 0 - IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT = default; + IMATH_HOSTDEVICE Vec2 (const Vec2&) = default; #else IMATH_HOSTDEVICE constexpr Vec2 (const Vec2& v) IMATH_NOEXCEPT; #endif From 64674d1b618ab47b1c26d544a5b4c27685055b98 Mon Sep 17 00:00:00 2001 From: Yuya Asano <64895419+sukeya@users.noreply.github.com> Date: Wed, 13 Mar 2024 16:52:17 +0900 Subject: [PATCH 12/13] Updata src/Imath/ImathVec.h rm IMATH_CONSTEXPR14 and IMATH_NOEXCEPT from default constructor and assignment. Co-authored-by: Arthur O'Dwyer Signed-off-by: Yuya Asano <64895419+sukeya@users.noreply.github.com> --- src/Imath/ImathVec.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Imath/ImathVec.h b/src/Imath/ImathVec.h index 32159086..97a9a81e 100644 --- a/src/Imath/ImathVec.h +++ b/src/Imath/ImathVec.h @@ -84,8 +84,8 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 /// Copy assignment #if IMATH_VEC_BE_TRIVIALLY_RELOCATABLE != 0 - IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec2& - operator= (const Vec2& v) IMATH_NOEXCEPT = default; + IMATH_HOSTDEVICE Vec2& + operator= (const Vec2&) = default; #else IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Vec2& operator= (const Vec2& v) IMATH_NOEXCEPT; From 7ad54372b3d7ab7925535bfebd710ee647a54138 Mon Sep 17 00:00:00 2001 From: Yuya Asano <64895419+sukeya@users.noreply.github.com> Date: Wed, 13 Mar 2024 16:53:54 +0900 Subject: [PATCH 13/13] Update src/Imath/ImathVec.h rm IMATH_NOEXCEPT from default destructor. Co-authored-by: Arthur O'Dwyer Signed-off-by: Yuya Asano <64895419+sukeya@users.noreply.github.com> --- src/Imath/ImathVec.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Imath/ImathVec.h b/src/Imath/ImathVec.h index 97a9a81e..c8a3013c 100644 --- a/src/Imath/ImathVec.h +++ b/src/Imath/ImathVec.h @@ -92,7 +92,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 #endif /// Destructor - ~Vec2 () IMATH_NOEXCEPT = default; + ~Vec2 () = default; /// @}