owner<T*> p syntax in cpp core guidelines

Viewed 5602

In cpp core guidelines: Example of non owning raw pointer I do not understand the following code:

 template<typename T>
class X2 {
    // ...
public:
    owner<T*> p;  // OK: p is owning
    T* q;         // OK: q is not owning
};

what is this syntax owner<T*> p ?

2 Answers

As Rakete1111 mentioned, owner<T*> is the same as T*. So we can have owner as a type alias for T.

template<class T>
using owner = T;

Now we can have a convention for our code that pointers are defined by owner when the class containing them is responsible for deleting them.

A simple example that owner acts as a raw pointer:

owner<int*> p = new int;
*p = 1;
std::cout<<*p; // 1

Related