This works, but it means that each instance has two do_stuff() member functions, only one of which will ever be called, and the other one is dead code. (Admittedly, very little code.)
private:
// Instantiate exactly one of the two release() methods below, depending
// on whether we were instantiated with a shared_ptr or a unique_ptr.
> Function overloading?
This works, but it means that each instance has two do_stuff() member functions, only one of which will ever be called, and the other one is dead code. (Admittedly, very little code.)
Instead, we can use SFINAE:
~GlibPtrAss igner()
release< SP>(smart_ ptr_, ptr_);
{
}
private:
// Instantiate exactly one of the two release() methods below, depending
// on whether we were instantiated with a shared_ptr or a unique_ptr.
template< typename T>
std::is_ same<T, std::shared_ ptr<typename T::element_ type>>: :value, std::shared_ ptr<ElementType >& smart, ElementType* p)
smart. reset(p, GlibDeleter< typename T::element_ type>() );
typename std::enable_if<
void
>::type
release(
{
}
template< typename T>
std::is_ same<T, std::unique_ ptr<typename T::element_type, typename T::deleter_ type>>: :value, std::unique_ ptr<ElementType , GlibDeleter< typename T::element_type>>& smart, ElementType* p)
smart. reset(p) ;
typename std::enable_if<
void
>::type
release(
{
}
Pete, I've pushed this change here:
https:/ /code.launchpad .net/~unity- api-team/ unity-api/ add-glib- assigner- class
It's now possible to use the same glib_assign method, whether the argument is a shared_ptr or a unique_ptr:
EXPECT_ FALSE(g_ key_file_ get_boolean( gkf.get( ), "group", "key", glib_assign( error)) );