STYLE: make some tmp, refPtr constructors constexpr
This commit is contained in:
parent
49ae975b72
commit
2cba04e204
@ -123,6 +123,7 @@ inline void Foam::autoPtr<T>::reset(autoPtr<T>&& ap) noexcept
|
||||
template<class T>
|
||||
inline void Foam::autoPtr<T>::swap(autoPtr<T>& other) noexcept
|
||||
{
|
||||
// Swap is just copy/assign for pointer and enum types
|
||||
// Self-swap is effectively ignored
|
||||
T* p = ptr_;
|
||||
ptr_ = other.ptr_;
|
||||
|
@ -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<T>&& ptr) noexcept;
|
||||
@ -127,7 +127,7 @@ public:
|
||||
inline explicit refPtr(std::unique_ptr<T>&& 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<T>&& 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_; }
|
||||
|
||||
|
@ -73,7 +73,7 @@ inline constexpr Foam::refPtr<T>::refPtr(std::nullptr_t) noexcept
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::refPtr<T>::refPtr(T* p) noexcept
|
||||
inline constexpr Foam::refPtr<T>::refPtr(T* p) noexcept
|
||||
:
|
||||
ptr_(p),
|
||||
type_(PTR)
|
||||
@ -95,7 +95,7 @@ inline Foam::refPtr<T>::refPtr(std::unique_ptr<T>&& rhs) noexcept
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::refPtr<T>::refPtr(const T& obj) noexcept
|
||||
inline constexpr Foam::refPtr<T>::refPtr(const T& obj) noexcept
|
||||
:
|
||||
ptr_(const_cast<T*>(&obj)),
|
||||
type_(CREF)
|
||||
@ -312,12 +312,8 @@ inline void Foam::refPtr<T>::ref(T& obj) noexcept
|
||||
template<class T>
|
||||
inline void Foam::refPtr<T>::swap(refPtr<T>& 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<T>::swap(refPtr<T>& other) noexcept
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
inline const T& Foam::refPtr<T>::operator()() const
|
||||
{
|
||||
return cref();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::refPtr<T>::operator const T&() const
|
||||
{
|
||||
return cref();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline const T* Foam::refPtr<T>::operator->() const
|
||||
{
|
||||
|
@ -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_; }
|
||||
|
||||
|
@ -108,7 +108,7 @@ inline Foam::tmp<T>::tmp(T* p)
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::tmp<T>::tmp(const T& obj) noexcept
|
||||
inline constexpr Foam::tmp<T>::tmp(const T& obj) noexcept
|
||||
:
|
||||
ptr_(const_cast<T*>(&obj)),
|
||||
type_(CREF)
|
||||
@ -352,12 +352,8 @@ inline void Foam::tmp<T>::ref(T& obj) noexcept
|
||||
template<class T>
|
||||
inline void Foam::tmp<T>::swap(tmp<T>& 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<T>::swap(tmp<T>& other) noexcept
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
inline const T& Foam::tmp<T>::operator()() const
|
||||
{
|
||||
return cref();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::tmp<T>::operator const T&() const
|
||||
{
|
||||
return cref();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline const T* Foam::tmp<T>::operator->() const
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user