K
krunalbauskar
Hi,
Explicit instantiation of STL vector demands explicit instantiation of
all the templates it using internally.
For example -
<snippet>
#include <iostream>
#include <vector>
using namespace std;
template class vector<int>;
int main()
{
vector<int>* vec = new vector<int>();
for(int i= 0; i < 10; i++)
vec->push_back(i* 10);
for(int i= 0; i < 10; i++)
cout << " Number " << i << " :" << (*vec) << endl;
}
</snippet>
If compiled with
gcc -fno-implicit-templates vector.cc -lstdc++
throws an error as vector internally uses some more function templates.
Corrected version:
<snippet>
#include <iostream>
#include <vector>
using namespace std;
template class vector<int>;
template class vector<int>;
template void std::fill<__gnu_cxx::__normal_iterator<int*,
std::vector<int, std::
:allocator<int> > >, int>(__gnu_cxx::__normal_iterator<int*,
std::vector<int, stt
d::allocator<int> > >, __gnu_cxx::__normal_iterator<int*,
std::vector<int, std:::
allocator<int> > >, int const&);
template __gnu_cxx::__normal_iterator<int*, std::vector<int,
std::allocaa
tor<int> > >, unsigned int, int>(__gnu_cxx::__normal_iterator<int*,
std::vector<<
int, std::allocator<int> > >, unsigned int, int const&);
template int* std::fill_n<int*, unsigned int, int>(int*, unsigned int,
int constt
&);
int main()
{
vector<int>* vec = new vector<int>();
for(int i= 0; i < 10; i++)
vec->push_back(i* 10);
for(int i= 0; i < 10; i++)
cout << " Number " << i << " :" << (*vec) << endl;
}
</snippet>
But I need to manually look at error and copy paste all the required
templates.
Is there an automated way/option using which I can avoid this.
Explicit instantiation of STL vector demands explicit instantiation of
all the templates it using internally.
For example -
<snippet>
#include <iostream>
#include <vector>
using namespace std;
template class vector<int>;
int main()
{
vector<int>* vec = new vector<int>();
for(int i= 0; i < 10; i++)
vec->push_back(i* 10);
for(int i= 0; i < 10; i++)
cout << " Number " << i << " :" << (*vec) << endl;
}
</snippet>
If compiled with
gcc -fno-implicit-templates vector.cc -lstdc++
throws an error as vector internally uses some more function templates.
Corrected version:
<snippet>
#include <iostream>
#include <vector>
using namespace std;
template class vector<int>;
template class vector<int>;
template void std::fill<__gnu_cxx::__normal_iterator<int*,
std::vector<int, std::
:allocator<int> > >, int>(__gnu_cxx::__normal_iterator<int*,
std::vector<int, stt
d::allocator<int> > >, __gnu_cxx::__normal_iterator<int*,
std::vector<int, std:::
allocator<int> > >, int const&);
template __gnu_cxx::__normal_iterator<int*, std::vector<int,
std::allocaa
tor<int> > >, unsigned int, int>(__gnu_cxx::__normal_iterator<int*,
std::vector<<
int, std::allocator<int> > >, unsigned int, int const&);
template int* std::fill_n<int*, unsigned int, int>(int*, unsigned int,
int constt
&);
int main()
{
vector<int>* vec = new vector<int>();
for(int i= 0; i < 10; i++)
vec->push_back(i* 10);
for(int i= 0; i < 10; i++)
cout << " Number " << i << " :" << (*vec) << endl;
}
</snippet>
But I need to manually look at error and copy paste all the required
templates.
Is there an automated way/option using which I can avoid this.