Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • A ADIOS2
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 97
    • Issues 97
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 9
    • Merge requests 9
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Podhorszki, Norbert
  • ADIOS2
  • Issues
  • #1188
Closed
Open
Issue created Feb 15, 2019 by Podhorszki, Norbert@pnbOwner

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?

Assignee
Assign to
Time tracking