Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ partial template template specialization

I want to pass a partial template specialization to template template parameter but I'm getting an error. Im not sure why excatly this doesent work.

template<template<typename, int> class V, typename T, int N, int... Indexes>
class Swizzle
{
    // ...
};

template<typename T, int N>
struct Vector;

template<typename T>
struct Vector<T, 3>
{
    // ...

    union
    {
        // ...
        Swizzle<Vector, T, 3, 0, 0, 0> xxx;
    };
};

Error:

'Vector': invalid template argument for template parameter 'V', expected a class template 'Swizzle': use of class template requires template argument list

Problem appears only on MSVC

like image 517
sorte33 Avatar asked Dec 14 '25 16:12

sorte33


1 Answers

Within the class template Vector, Vector refers to both the type of this instance of the template and the template itself.

This should compile:

template<class X, int M>
using Self = Vector<X,M>;
// ...

union
{
    // ...
    Swizzle<Self, T, 3, 0, 0, 0> xxx;
};

I suspect MSVC is wrong here, but am uncertain.

like image 99
Yakk - Adam Nevraumont Avatar answered Dec 17 '25 10:12

Yakk - Adam Nevraumont



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!