Questions tagged [explicit-instantiation]

Explicit instantiation lets you create an instantiation of a C++ templated class or function without actually using it in your code.

Explicit instantiation lets you create an instantiation of a C++ templated class or function without actually using it in your code.

It is designed to optimize template libraries usage providing some of (mostly used) template instances in compiled binary form instead of source code form. This will reduce compile and link time for end-user applications.

Also it could be used to encapsulate template function definition in translation unit instead of included header.

136 questions
2
votes
1 answer

Some explicit instantiations not being generated in G++

I am building a library that handles several different types of binary "languages", which has a "Processor" type for each language. The library builds fine, and I've narrowed down the issue so far to the following template code: //…
Cloud
  • 18,753
  • 15
  • 79
  • 153
2
votes
2 answers

Confusions around explicit template instantiation

Well, I think I just get extremely confused by explicit template instantiation ~>_<~ Could an explicit instantiation declaration exploit an implicit instantiation definition? What if both explicit and implicit instantiation definitions exist in a…
Lingxi
  • 14,579
  • 2
  • 37
  • 93
2
votes
2 answers

Multiple instantiation of specialized templates

I have an explicitly instantiated template class with specializations: // a.hh #pragma once template struct A { int foo(); }; // a.in #include "a.hh" template<> int A<1>::foo() { return 1; } // specialization for N=1 template<> int…
2
votes
1 answer

explicit instantiation of a function template having integers as template parameters

I am trying to explicitly instantiate a function template. Please see the code snippet main.cpp: void func(int * ); int main() { int m = 3, n = 5; int *ptr; ptr = &m; func(ptr); //function call ..... …
Goutham
  • 53
  • 1
  • 8
2
votes
1 answer

Using function-templated code across the g++-nvcc boundary (including kernels)

Suppose I compile the following with NVIDIA CUDA's nvcc compiler: template __global__ void fooKernel(T t1, T t2) { Operator op; doSomethingWith(t1, t2); } template __device__ __host__ void T bar(T…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
2
votes
1 answer

Dynamical use of explicitly instantiated templates

Possible Duplicate: Dynamic dispatching of template functions? I would like to use non-type templates to create grid cells with different memory footprints without having to use dynamically allocated memory on the heap, e.g. template
1
vote
3 answers

How can I avoid recompiling a specific template function each time I compile my project?

Say I have a file foo.hpp with a template template void foo() { // Complex function } which I use in my main.cpp: #include "foo.hpp" int main() { // quickly compiled code // ... foo<3>(); // more quickly compiled…
SirVivor
  • 85
  • 7
1
vote
0 answers

Explicit instantiation definition: constructor template of class template -- is it possible? (Clang versus GCC)

Consider the following class template: template struct S { template void f(T) { /* ... */ } }; It is possible to provide a explicit instantiation definition (or declaration via extern template) of both S itself and…
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
1
vote
1 answer

How to take address of templated member function instance in C++?

I was trying to take address of templated member function instance. For some reason, it is not working. Here is minimal reproducible example: class X { public: template inline void f() {} const decltype(f)* truef =…
1
vote
0 answers

Is this a defect of C++ that allow to break access control?

Declaring a member private means there should never be a legal way to access it directly from outside. But template explicit instantiation breaks the law. What's the consideration of this? Or it's a defect? Example: #include #include…
zclll
  • 77
  • 7
1
vote
2 answers

ODR violation if template is defined in multiple translation units for different types?

I recently got to know that the following code is ill-formed, NDR: // foo.h template void foo(); // foo_bar.cpp template <> void foo() { /* Implementation for bar */ } // foo_baz.cpp template <> void foo() { /*…
1
vote
1 answer

Explicit instantiation of a deleted function template in C++

If a function template is marked as deleted, is it allowed to explicitly instantiate it as in the example: template int foo(T) = delete; template int foo(int); Clang and GCC allows it, while MSVC prints the error: error C2280: 'int…
Fedor
  • 17,146
  • 13
  • 40
  • 131
1
vote
0 answers

Ask the compiler to dump the implicitly instantiated templates

I am working on a library which use intensively Eigen for its dense algebra operations. We have a database of 'end-to-end' tests, each one of them being a translation unit in which tens (hundreds, thousands?) of Eigen's functions are instanciated.…
janou195
  • 1,175
  • 2
  • 10
  • 25
1
vote
1 answer

Explicit template instantiation and debug load time

I have been wondering if the use of explicit template instantiation can help reduce the time that it takes the debugger to load binaries. Something similar to reducing link time by the same mechanisms. In the same vein, are there any ways to measure…
Paul Floyd
  • 5,530
  • 5
  • 29
  • 43
1
vote
1 answer

Explicitly instantiate template method of explicitly instantiated template class

I have a class A with template argument T, which is limited to two types: T1 and T2. Because of this, I explicitly instantiated class A for types T1 and T2 such that A's functionality can be defined in a source file and doesn't need to be recompiled…
Wout12345
  • 91
  • 5