Explicit Template Specification for Template Template Template Template

This question may coincide with this: Explicit specification of a template template template template template in C ++ . However, I did not find a solution in this thread.

I have a template template with a template constructor:

template<typename First, typename ... Rest> class var {
    public:
        template<typename T> var(T& t) {
            std::cout << "general" << std::endl;
        }
};

But in case this class is created using an object of the same class as the parameter (i.e. we would like to call the copy- (or move-) constructor), something concrete must be done. So I tried the following:

template<typename First, typename ... Rest> template<> 
var<First, Rest...>::var(var<First, Rest...>& v) {
    std::cout << "copy" << std::endl;
}

When I try to compile this with g ++ 4.6, I get the error: invalid specification explicitly before '> token Error: closing class templates are not explicitly specialized confused by earlier errors, salvation

, , ...

, , , . ?

+3
2

:

template<typename First, typename ... Rest> class var {
    public:
    var() {};
    var(const var& v) {
        std::cout << "copy" << std::endl;
    }
    template<typename T>
    var(const T& t) {
        std::cout << "general" << std::endl;
    }
};

int main()
{
    var<int> i0;
    var<int> i1(i0);
    var<int> i2("Hello");
}

copy
general

: ​​

.

12,8:

X , X &, const X &, X & const volatile X &, , (8.3.6).

+1

, . ++.

/, .

0

All Articles