Skip to content

Commit 390f6e7

Browse files
committed
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*.
1 parent dd91b90 commit 390f6e7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

platform/SingletonPtr.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ struct SingletonPtr {
113113
return get();
114114
}
115115

116+
/** Get a reference to the underlying singleton
117+
*
118+
* @returns
119+
* A reference to the singleton
120+
*/
121+
T &operator*()
122+
{
123+
return *get();
124+
}
125+
116126
// This is zero initialized when in global scope
117127
T *_ptr;
118128
// Force data to be 4 byte aligned

0 commit comments

Comments
 (0)