They don't have to.
What is necessary is for the template definition to be visible at the point of instantiation (where it's used) so that the compiler can derive the class / function from the template at this point.
However it is extremely common to use two header files for template classes:
// foo_fwd.hpp
template struct Foo;
// foo.hpp
#include "foo_fwd.hpp"
template struct Foo { typedef std::pair type; };
This allows those who do not need the full template definition to include a somewhat lighter header, for example:
//is_foo.hpp
#include
#include "foo_fwd.hpp"
template
struct is_foo: boost::mpl::false_ {};
template
struct is_foo< Foo >: boost::mpl::true_ {};
which can speed up compilation-time a bit.