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

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

Question

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.

Était-ce utile?

La solution

template<int I>
void doSomething(A<int, I> & value)
{...}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top