I'm writing a function for counting elements of multi dimensional vector
template<class T>
int real_size(const std::vector<T>& vec)
{
int size=0;
for(const auto& v : vec)
{
if(std::is_integral<T>::value ||
std::is_floating_point<T>::value){
size+=1;
}
else{
size +=real_size(v);
}
}
return size;
}
int main()
{
std::vector<std::vector<int>> a(10);
a[0]=std::vector<int>(10);
std::cout<<real_size(a);
}
Which give me these errors :
error: no matching function for call to 'real_size(const int&)'
size +=real_size(v);
^
That code seem's fine and error is irrelevant...the else statement should never become size +=real_size(int);
because I'm checking the type of template parameter with std::is_integer
.
But it seems that compiler fails to understand it at compile time !! Is it a compiler bug or I'm making a mistake ?
*I'm using gcc 4.8.1. g++ -std=c++11 *