mercredi 27 avril 2022

How to get the type of the first parameter of a dependent function pointer template parameter in C++11?

Current code:

#include <utility>

template <typename T, void (*D)(T *)>
std::pair<T *, void (*)(T *)> f(T * const t)
{
    // ...
    return std::make_pair(t, D); // need `T` and `D` here
}

void d(int *t);

void g()
{
    auto something = f<int, d>(new int {5});        
}

What I'd like:

#include <utility>

template </* fill here: only `D` */>
std::pair<T *, void (*)(T *)> f(T * const t)
{
    // ...
    return std::make_pair(t, D); // need `T` and `D` here
}

void d(int *t);

void g()
{
    auto something = f<d>(new int {5});        
}

Is this possible in C++11?

Aucun commentaire:

Enregistrer un commentaire