title: STL, GCC and explicit template instantiation
body: <p>Question: Why does the code below not work?</p>
  <p>I want to use explicit template instantiation for my project. However, when I try to instantiate a standard algorithm (<code>std::find</code>) it seems like I also need to instantiate some internal routine. It says:</p>
  <pre><code>undifined reference to Foo* std::__find&lt;Foo const*, unsigned int&gt;(Foo const*, 
      Foo const*, unsigned int const&amp;, std::random_access_iterator_tag)
  </code></pre>
  <p>when I</p>
  <pre><code>template
  Foo* std::find&lt;Foo*,unsigned int&gt;(Foo*,Foo*,const unsigned int&amp;);
  </code></pre>
  <p>More precicly, I am trying to do the following:</p>
  <pre><code>#include &lt;algorithm&gt;
  #include &lt;cstdio&gt;
  
  class Foo
      {
      public:
          unsigned int id;
          bool operator==(unsigned int b)
              {return id==b;}
  };
  
  
  template
  Foo* std::find&lt;Foo*,unsigned int&gt;(Foo*,Foo*,const unsigned int&amp;);
  
  int main()
      {
      Foo bar[4]={1,2,3,4};
      Foo* p_bar=std::find(bar,bar+4,3);
      printf(&quot;%p    %u\n&quot;,p_bar,*p_bar);
      return 0;
      }
  </code></pre>
  <p>And it compile using</p>
  <pre><code>g++ -fno-explicit-templates test.cpp
  </code></pre>
  <p>to force explicit template instantiation.</p>
  <p>The compiler output is as follows:</p>
  <pre><code>ccWFduTJ.o:test.cpp:(.text$_ZSt4findIP3FoojET_S2_S2_RKT0_[Foo* std::find&lt;Foo*, unsigned int&gt;(Foo*, Foo*, unsigned int const&amp;)]+0x2a): undefined reference to `Foo* std::__find&lt;Foo*, unsigned int&gt;(Foo*, Foo*, unsigned int const&amp;, std::random_access_iterator_tag)'
  ccWFduTJ.o:test.cpp:(.text$_ZSt4findIP3FooiET_S2_S2_RKT0_[Foo* std::find&lt;Foo*, int&gt;(Foo*, Foo*, int const&amp;)]+0x2a): undefined reference to `Foo* std::__find&lt;Foo*, int&gt;(Foo*, Foo*, int const&amp;, std::random_access_iterator_tag)'
  collect2: ld returned 1 exit status
  </code></pre>
  <p>If it helps, here is what g++ --version outputs:</p>
  <blockquote>
  <p>g++ (tdm-1) 4.5.2</p>
  <p>Copyright (C) 2010 Free Software Foundation, Inc.</p>
  <p>This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</p>
  </blockquote>