samedi 19 août 2017

How to define template selections depends on the parameter class has a typedef or not

What I need:

template <class Context/*if Context has a Buffer typedef*/>
struct Buffer {
    typedef typename Context::Buffer type;
};

template <class Context/*if Context doesn't have a Buffer typedef*/>
struct Buffer {
    typedef std::shared_ptr<void> type;
};

If the parameter class Context has a Buffer typedef, then it's used, otherwise shared_ptr would be used.

How to write the templates? thanks in advance.

Aucun commentaire:

Enregistrer un commentaire