why extern template?
Created by: germasch
As I've been dealing with lots of ADIOS2_FOREACH_* uses, I've come to wonder why extern template
is used (pretty frequently).
Example from bindings/CXX11/cxx11/Types.h
template <class T>
std::string GetType() noexcept;
// LIMIT TEMPLATE TYPES FOR adios2::GetType
#define declare_template_instantiation(T) \
\
extern template std::string GetType<T>() noexcept;
ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
My understanding is that extern template
is used to prevent the compile from creating instantiations of the given template on use (ie., in later in the file which includes this header). That makes sense in that the necessary instantiations are explicitly generated in Types.cpp
, so one doesn't need them elsewhere, and, if this was a long function at least, one could save compile time and disk space during the build.
However, since adios puts template definitions into .tcc
files in the case where they are explicitly instantiated, there is no way that the template could be instantiated elsewhere in the first place. So considering how you prescribe to organize the source files, the extern template
seem to be redundant?