New functions for creating cvf::refs to avoid "naked new" in App code

This commit is contained in:
Gaute Lindkvist 2020-10-22 08:55:06 +02:00
parent 4fe11949a1
commit 558bee72af
2 changed files with 32 additions and 2 deletions

View File

@ -137,8 +137,6 @@ template<typename T> inline void swap(ref<T>& a, ref<T>& b) { a.swap(b); }
/// @}
//==================================================================================================
//
// Smart pointer class for const pointers
@ -181,6 +179,17 @@ template<typename T1, typename T2> inline bool operator!=(const cref<T1>& a, T2*
template<typename T1, typename T2> inline bool operator==(T1* a, const cref<T2>& b) { return a == b.p(); } ///< Returns true if the naked pointer \a a is equal to the internal pointer of ref \a b.
template<typename T1, typename T2> inline bool operator!=(T1* a, const cref<T2>& b) { return a != b.p(); } ///< Returns true if the naked pointer \a a is different from the internal pointer of ref \a b.
//==================================================================================================
//
// Creation of smart pointers.
//
//==================================================================================================
template<typename T, class... Args>
ref<T> make_ref(Args&&... args);
template<typename T, class... Args>
cref<T> make_cref(Args&&... args);
/// @}
}

View File

@ -566,5 +566,26 @@ void cref<T>::swap(cref& other)
}
//--------------------------------------------------------------------------------------------------
/// Creation of smart pointers.
//--------------------------------------------------------------------------------------------------
template<typename T, class... Args>
ref<T> make_ref(Args&&... args)
{
return cvf::ref(new T(args...));
}
//--------------------------------------------------------------------------------------------------
/// Creation of const smart pointers.
//--------------------------------------------------------------------------------------------------
template<typename T, class... Args>
cref<T> make_cref(Args&&... args)
{
return cvf::cref(new T(args...));
}
} // namespace cvf