is it possible to overload a function to accept all instances of with a non-type template parameter

StackOverflow https://stackoverflow.com/questions/16870168

문제

template<typename T,int I=5> struct A{

    T _store[I];

};

template<typename T,int I>
void doSomething(A<T,I>& a){

  std::cout << "basic template for all other types" << std::endl;

}

template<>
void doSomething(A<int>& a){

 std::cout << "specialized integer template" << std::endl;

}

int main(int argc, char** argv){


    A<char> a;
    A<int> i;
    A<int,10> i10;

    doSomething(a);
    doSomething(i);
    doSomething(i10); //this does not call any specialized version yet

    return 0;

}

is there a way to declare the doSomething specialization to accept all A<int,...> instances regardles of what the second parameter is, and even though each different A<int,...> is a different type in stricter terms,

this would actually make this feasible to use, if i did not have to theoretically declare and keep track of each different specialization that would be needed

i have not been able to determine this.

도움이 되었습니까?

해결책

template<int I>
void doSomething(A<int, I> & value)
{...}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top