alias of a function template

In C (or C++) I would do something like this:

typedef float MyFuncType(float a);

MyFuncType  myfunc_SSE2, myfunc_SSE41, myfunc_AVX, myfunc_AVX2, myfunc_AVX512

But now I want function templates. My real code currently looks more like this

template <typename TYPE, unsigned N, typename VALUES>
void foo_SSE2(int32_t *buffer, VALUES & v);

template <typename TYPE, unsigned N, typename VALUES>
void foo_SSE41(int32_t *buffer, VALUES & v);
...
template <typename TYPE, unsigned N, typename VALUES>
void foo_AVX512(int32_t *buffer, VALUES & v);

But it’s annoying (and error prone) to repeat this for every change in function name. I want something like the following (which I know does not work).

template <typename TYPE, unsigned N, typename VALUES>
typedef void foo(int32_t *buffer, VALUES & v);

foo foo_SSE2, foo_SSE41, foo_SSE_AVX, foo_AVX2, foo_AVX512

Is there a ideal way to do this?

These are only declarations in a header file. The function definitions are in a separate source file which is compiled to a different object file for each function name.


Source: c++

Leave a Reply