Add * operator to SingletonPtr

Sometimes you want don't want to directly call a method on your
SingletonPtr-wrapped object, but you want to pass it to something
else.

For example

    SingletonPtr<PlatformMutex> mutex;
    mutex->lock();

is fine, but what about

    SingletonPtr<PlatformMutex> mutex;
    ScopedLock<PlatformMutex> lock(*mutex.get());

Add an overload for operator* to make this more elegant:

    SingletonPtr<PlatformMutex> mutex;
    ScopedLock<PlatformMutex> lock(*mutex);

This addition is consistent with standard C++ classes such as
`unique_ptr` and `shared_ptr`, which likewise have
get, operator-> and operator*.
pull/8001/head
Kevin Bracey 2018-08-29 16:36:55 +03:00
parent dd91b90149
commit 390f6e7a7b
1 changed files with 10 additions and 0 deletions

View File

@ -113,6 +113,16 @@ struct SingletonPtr {
return get();
}
/** Get a reference to the underlying singleton
*
* @returns
* A reference to the singleton
*/
T &operator*()
{
return *get();
}
// This is zero initialized when in global scope
T *_ptr;
// Force data to be 4 byte aligned