template <typename T>
class CopyablePtr
Defined at line 40 of file ../../third_party/perfetto/include/perfetto/protozero/copyable_ptr.h
This class is essentially a std::vector
<T
> of fixed size = 1.
It's a pointer wrapper with deep copying and deep equality comparison.
At all effects this wrapper behaves like the underlying T, with the exception
of the heap indirection.
Conversely to a std::unique_ptr, the pointer will be always valid, never
null. The problem it solves is the following: when generating C++ classes
from proto files, we want to keep each header hermetic (i.e. not #include
headers of dependent types). As such we can't directly instantiate T
field members but we can instead rely on pointers, so only the .cc file needs
to see the actual definition of T. If the generated classes were move-only we
could just use a unique_ptr there. But they aren't, hence this wrapper.
Converesely to unique_ptr, this wrapper:
- Default constructs the T instance in its constructor.
- Implements deep comparison in operator== instead of pointer comparison.
Public Methods
void CopyablePtr<T> ()
Defined at line 42 of file ../../third_party/perfetto/include/perfetto/protozero/copyable_ptr.h
void ~CopyablePtr<T> ()
Defined at line 43 of file ../../third_party/perfetto/include/perfetto/protozero/copyable_ptr.h
void CopyablePtr<T> (const CopyablePtr<T> & other)
Copy operators.
Defined at line 46 of file ../../third_party/perfetto/include/perfetto/protozero/copyable_ptr.h
CopyablePtr<T> & operator= (const CopyablePtr<T> & other)
Defined at line 47 of file ../../third_party/perfetto/include/perfetto/protozero/copyable_ptr.h
void CopyablePtr<T> (CopyablePtr<T> && other)
Move operators.
Defined at line 53 of file ../../third_party/perfetto/include/perfetto/protozero/copyable_ptr.h
CopyablePtr<T> & operator= (CopyablePtr<T> && other)
Defined at line 57 of file ../../third_party/perfetto/include/perfetto/protozero/copyable_ptr.h
T * get ()
Defined at line 63 of file ../../third_party/perfetto/include/perfetto/protozero/copyable_ptr.h
const T * get ()
Defined at line 64 of file ../../third_party/perfetto/include/perfetto/protozero/copyable_ptr.h
T * operator-> ()
Defined at line 66 of file ../../third_party/perfetto/include/perfetto/protozero/copyable_ptr.h
const T * operator-> ()
Defined at line 67 of file ../../third_party/perfetto/include/perfetto/protozero/copyable_ptr.h
T & operator* ()
Defined at line 69 of file ../../third_party/perfetto/include/perfetto/protozero/copyable_ptr.h
const T & operator* ()
Defined at line 70 of file ../../third_party/perfetto/include/perfetto/protozero/copyable_ptr.h
Friends
template <typename T>
bool CopyablePtr (const CopyablePtr<T> & lhs, const CopyablePtr<T> & rhs)
template <typename T>
bool CopyablePtr (const CopyablePtr<T> & lhsconst CopyablePtr<T> & rhs)