Search code examples
c++11templatesusing

Can I have partial template specialization with the using keyword?


In the code of the OpenCV library I find this:

template<typename _Tp, int cn> class Vec
{
  ...
}

typedef Vec<int, 2> Vec2i;
typedef Vec<int, 3> Vec3i;
typedef Vec<float, 2> Vec2f;
typedef Vec<float, 3> Vec3f;

I would like to have a Vec of type float and variable length N. Is it possible to write something like

using Vecf<N> = Vec<float, N>;

?


Solution

  • Yes, and you are nearly there. The correct syntax would be

    template<int N>
    using Vecf = Vec<float, N>;