diff --git a/src/OpenFOAM/memory/autoPtr/autoPtrI.H b/src/OpenFOAM/memory/autoPtr/autoPtrI.H index a18ce5a0e8..a8bce75464 100644 --- a/src/OpenFOAM/memory/autoPtr/autoPtrI.H +++ b/src/OpenFOAM/memory/autoPtr/autoPtrI.H @@ -123,6 +123,7 @@ inline void Foam::autoPtr::reset(autoPtr&& ap) noexcept template inline void Foam::autoPtr::swap(autoPtr& other) noexcept { + // Swap is just copy/assign for pointer and enum types // Self-swap is effectively ignored T* p = ptr_; ptr_ = other.ptr_; diff --git a/src/OpenFOAM/memory/refPtr/refPtr.H b/src/OpenFOAM/memory/refPtr/refPtr.H index 700b72e746..c264ddbeb2 100644 --- a/src/OpenFOAM/memory/refPtr/refPtr.H +++ b/src/OpenFOAM/memory/refPtr/refPtr.H @@ -118,7 +118,7 @@ public: inline constexpr refPtr(std::nullptr_t) noexcept; //- Construct, taking ownership of the pointer. - inline explicit refPtr(T* p) noexcept; + inline explicit constexpr refPtr(T* p) noexcept; //- Move construct from autoPtr, transferring ownership. inline explicit refPtr(autoPtr&& ptr) noexcept; @@ -127,7 +127,7 @@ public: inline explicit refPtr(std::unique_ptr&& ptr) noexcept; //- Construct for a const reference to an object. - inline refPtr(const T& obj) noexcept; + inline constexpr refPtr(const T& obj) noexcept; //- Move construct, transferring ownership. inline refPtr(refPtr&& rhs) noexcept; @@ -227,12 +227,6 @@ public: // Member Operators - //- Identical to cref() method. - inline const T& operator()() const; - - //- Cast to underlying data type, using the cref() method. - inline operator const T&() const; - //- Dereferences (const) pointer to the managed object. // Fatal for a null managed pointer. inline const T* operator->() const; @@ -241,6 +235,12 @@ public: // Fatal for a null managed pointer or if the object is const. inline T* operator->(); + //- Return const reference to the object - same as cref() method. + const T& operator()() const { return cref(); } + + //- Cast to underlying data type, using the cref() method. + operator const T&() const { return cref(); } + //- Non-null pointer/reference : valid() explicit operator bool() const noexcept { return ptr_; } diff --git a/src/OpenFOAM/memory/refPtr/refPtrI.H b/src/OpenFOAM/memory/refPtr/refPtrI.H index e9e74da3b5..6e0bfb58a2 100644 --- a/src/OpenFOAM/memory/refPtr/refPtrI.H +++ b/src/OpenFOAM/memory/refPtr/refPtrI.H @@ -73,7 +73,7 @@ inline constexpr Foam::refPtr::refPtr(std::nullptr_t) noexcept template -inline Foam::refPtr::refPtr(T* p) noexcept +inline constexpr Foam::refPtr::refPtr(T* p) noexcept : ptr_(p), type_(PTR) @@ -95,7 +95,7 @@ inline Foam::refPtr::refPtr(std::unique_ptr&& rhs) noexcept template -inline Foam::refPtr::refPtr(const T& obj) noexcept +inline constexpr Foam::refPtr::refPtr(const T& obj) noexcept : ptr_(const_cast(&obj)), type_(CREF) @@ -312,12 +312,8 @@ inline void Foam::refPtr::ref(T& obj) noexcept template inline void Foam::refPtr::swap(refPtr& other) noexcept { - if (&other == this) - { - return; // Self-swap is a no-op - } - // Swap is just copy/assign for pointer and enum types + // Self-swap is effectively ignored T* p = ptr_; ptr_ = other.ptr_; other.ptr_ = p; @@ -330,20 +326,6 @@ inline void Foam::refPtr::swap(refPtr& other) noexcept // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -template -inline const T& Foam::refPtr::operator()() const -{ - return cref(); -} - - -template -inline Foam::refPtr::operator const T&() const -{ - return cref(); -} - - template inline const T* Foam::refPtr::operator->() const { diff --git a/src/OpenFOAM/memory/tmp/tmp.H b/src/OpenFOAM/memory/tmp/tmp.H index 1e33eb475d..f9e0fa52fc 100644 --- a/src/OpenFOAM/memory/tmp/tmp.H +++ b/src/OpenFOAM/memory/tmp/tmp.H @@ -135,7 +135,7 @@ public: inline explicit tmp(T* p); //- Construct for a const reference to an object. - inline tmp(const T& obj) noexcept; + inline constexpr tmp(const T& obj) noexcept; //- Move construct, transferring ownership. // Does not affect ref-count @@ -236,12 +236,6 @@ public: // Member Operators - //- Identical to cref() method. - inline const T& operator()() const; - - //- Cast to underlying data type, using the cref() method. - inline operator const T&() const; - //- Dereferences (const) pointer to the managed object. // Fatal for a null managed pointer. inline const T* operator->() const; @@ -250,6 +244,12 @@ public: // Fatal for a null managed pointer or if the object is const. inline T* operator->(); + //- Return const reference to the object - same as cref() method. + const T& operator()() const { return cref(); } + + //- Cast to underlying data type, using the cref() method. + operator const T&() const { return cref(); } + //- Non-null pointer/reference : valid() explicit operator bool() const noexcept { return ptr_; } diff --git a/src/OpenFOAM/memory/tmp/tmpI.H b/src/OpenFOAM/memory/tmp/tmpI.H index 99babc2f0c..80650e3619 100644 --- a/src/OpenFOAM/memory/tmp/tmpI.H +++ b/src/OpenFOAM/memory/tmp/tmpI.H @@ -108,7 +108,7 @@ inline Foam::tmp::tmp(T* p) template -inline Foam::tmp::tmp(const T& obj) noexcept +inline constexpr Foam::tmp::tmp(const T& obj) noexcept : ptr_(const_cast(&obj)), type_(CREF) @@ -352,12 +352,8 @@ inline void Foam::tmp::ref(T& obj) noexcept template inline void Foam::tmp::swap(tmp& other) noexcept { - if (&other == this) - { - return; // Self-swap is a no-op - } - // Swap is just copy/assign for pointer and enum types + // Self-swap is effectively ignored T* p = ptr_; ptr_ = other.ptr_; other.ptr_ = p; @@ -370,20 +366,6 @@ inline void Foam::tmp::swap(tmp& other) noexcept // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -template -inline const T& Foam::tmp::operator()() const -{ - return cref(); -} - - -template -inline Foam::tmp::operator const T&() const -{ - return cref(); -} - - template inline const T* Foam::tmp::operator->() const {