mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: support pointer cast from autoPtr
This commit is contained in:
committed by
Andrew Heather
parent
8b6f4a4bcf
commit
675aa8053a
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
@ -121,17 +121,19 @@ public:
|
||||
inline explicit autoPtr(autoPtr<U>&& ap);
|
||||
|
||||
//- A move construct disguised as a copy construct (transfers ownership)
|
||||
// \remark This is a non-standard definition, and should ideally be
|
||||
// marked as deleted - pending cleanup of code currently relying
|
||||
// on this behaviour.
|
||||
// \remark This should ideally be deleted - pending cleanup of code
|
||||
// currently relying on this behaviour.
|
||||
#ifdef Foam_autoPtr_copyConstruct
|
||||
inline autoPtr(const autoPtr<T>& ap) noexcept;
|
||||
autoPtr(const autoPtr<T>& ap) noexcept
|
||||
:
|
||||
ptr_(const_cast<autoPtr<T>&>(ap).release())
|
||||
{}
|
||||
#else
|
||||
autoPtr(const autoPtr<T>& ap) = delete;
|
||||
#endif
|
||||
|
||||
|
||||
//- Destructs the managed object if such is present
|
||||
//- Deletes the managed object if such is present
|
||||
inline ~autoPtr() noexcept;
|
||||
|
||||
|
||||
@ -179,16 +181,8 @@ public:
|
||||
inline void reset(T* p = nullptr) noexcept;
|
||||
|
||||
//- Delete managed object and set to new given pointer
|
||||
// \remark This is a non-standard definition, but may provide better
|
||||
// code documentation than a simple move assign would.
|
||||
inline void reset(autoPtr<T>&& other) noexcept;
|
||||
|
||||
//- Delete managed object and set to new given pointer
|
||||
//- Identical behaviour to reset().
|
||||
// \note Provided for backward compatibility - the older version
|
||||
// enforced a run-time check (Fatal if pointer was already set)
|
||||
// but this was rarely used.
|
||||
inline void set(T* p) noexcept;
|
||||
// \remark Same as move assign, but better for code documentation
|
||||
inline void reset(autoPtr<T>&& ap) noexcept;
|
||||
|
||||
//- Swaps the managed object with other autoPtr.
|
||||
inline void swap(autoPtr<T>& other) noexcept;
|
||||
@ -239,6 +233,12 @@ public:
|
||||
operator const T&() const = delete;
|
||||
#endif
|
||||
|
||||
//- Cast to pointer type
|
||||
operator const T*() const noexcept { return get(); }
|
||||
|
||||
//- Cast to pointer type
|
||||
operator T*() noexcept { return get(); }
|
||||
|
||||
//- True if the managed pointer is non-null
|
||||
explicit inline operator bool() const noexcept;
|
||||
|
||||
@ -252,17 +252,27 @@ public:
|
||||
#ifdef Foam_autoPtr_copyAssign
|
||||
//- A move assignment disguised as a copy assignment
|
||||
// \remark Non-standard definition - should just be movable
|
||||
inline void operator=(const autoPtr<T>& ap) noexcept;
|
||||
void operator=(const autoPtr<T>& ap) noexcept
|
||||
{
|
||||
operator=(std::move(const_cast<autoPtr<T>&>(ap)));
|
||||
}
|
||||
#else
|
||||
void operator=(const autoPtr<T>& ap) = delete;
|
||||
#endif
|
||||
|
||||
//- Allow reset via assignment from literal nullptr
|
||||
//- Clear via assignment from literal nullptr
|
||||
inline void operator=(std::nullptr_t) noexcept;
|
||||
|
||||
|
||||
// Housekeeping
|
||||
|
||||
//- Deprecated(2018-02) Identical to reset().
|
||||
// \note Provided for backward compatibility - the older version
|
||||
// enforced a run-time check (Fatal if pointer was already set)
|
||||
// but this was rarely used.
|
||||
// \deprecated(2018-02) Identical to reset().
|
||||
void set(T* p) noexcept { reset(p); }
|
||||
|
||||
//- Deprecated(2018-02) No copy assignment from plain pointer
|
||||
// \deprecated(2018-02) Convenient, but uncontrolled access
|
||||
void operator=(T* p) = delete;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
@ -84,15 +84,6 @@ inline Foam::autoPtr<T>::autoPtr(autoPtr<U>&& ap)
|
||||
{}
|
||||
|
||||
|
||||
#ifdef Foam_autoPtr_copyConstruct
|
||||
template<class T>
|
||||
inline Foam::autoPtr<T>::autoPtr(const autoPtr<T>& ap) noexcept
|
||||
:
|
||||
ptr_(const_cast<autoPtr<T>&>(ap).release())
|
||||
{}
|
||||
#endif
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
@ -177,13 +168,6 @@ inline void Foam::autoPtr<T>::reset(autoPtr<T>&& ap) noexcept
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::autoPtr<T>::set(T* p) noexcept
|
||||
{
|
||||
reset(p);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::autoPtr<T>::swap(autoPtr<T>& other) noexcept
|
||||
{
|
||||
@ -290,15 +274,6 @@ inline void Foam::autoPtr<T>::operator=(autoPtr<U>&& ap) noexcept
|
||||
}
|
||||
|
||||
|
||||
#ifdef Foam_autoPtr_copyAssign
|
||||
template<class T>
|
||||
inline void Foam::autoPtr<T>::operator=(const autoPtr<T>& ap) noexcept
|
||||
{
|
||||
operator=(std::move(const_cast<autoPtr<T>&>(ap)));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::autoPtr<T>::operator=(std::nullptr_t) noexcept
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user