vendredi 30 septembre 2016

Template only for smart pointer

Hi I am not sure that this is possible since but I thought of asking since there might be better ways of achieving something similar that I am not aware of. For simplicity lets just consider that VectorT is

template<class T>
class VectorT: private std::vector<T>`

An attempt to what I wanted to have is something along the lines of.

namespace detail
{
template<class SmartPtr>
class MyClassVectorBase : public VectorT<SmartPtr>
{
public:
    MyClassVectorBase() = default;

    // all common functions of MyVectorView and MyVector
};
}

using MyClassVectorView = detail::MyClassVectorBase<nonstd::observer_ptr<SomeClass>>;

class MyVector : public detail::MyClassVectorBase<std::unique_ptr<SomeClass>>
{
    // only functions related to the actual owner vector
};

What I am hoping is that MyClassVectorBase can be templated only on the smart pointer type and only accept SomeClass. I thought that it might be possible with a specialization but I got no idea what the syntax for something like that would be

template<class T, class SmartPtr>
class MyClassVectorBase : public VectorT<SmartPtr<T>>
{
};

template<SomeClass T, typename SmartPtr>
class MyClassVectorBase : public VectorT<SmartPtr<T>>
{   
};

Is something like that even possible ?

Aucun commentaire:

Enregistrer un commentaire