Pardon the very vague question but I am struggling with even finding the proper words to describe what I'm trying to do. Basically, when I write a class I like having:
class A
{
public:
using uptr = std::unique_ptr<A>;
using sptr = std::shared_ptr<A>;
using wptr = std::weak_ptr<A>;
};
So I can use A::uptr and such.
Now I am starting to have a lot of classes with this mechanism and I was wondering if it was posssible to generalize it, somehow like this:
template <typename T>
class Ptrs
{
public:
using uptr = std::unique_ptr<T>;
using sptr = std::shared_ptr<T>;
using wptr = std::weak_ptr<T>;
};
class A : public Ptrs<A>
{
};
This seems to work properly but as soon as I introduce inheritance, it breaks. For example:
class B : public A
{
};
B::uptr b; // this is a unique_ptr<A>
class B : public Ptrs<B>, public A // does not compile
{
};
So I was wondering if there was any way to do this. I am using C++20, I am just not very familiar with templates / concepts / SFINAE and such. I am also not sure if this is even a good idea, I just thought it would be nice to have a way to do this.