Questions tagged [template-instantiation]
80 questions
2
votes
1 answer
Method in template class only for certain template parameters correct
Consider the following template class
template
struct Caller {
void func(const T &t) { t.func(); }
void gunc(const T &t) { t.gunc(); }
};
Now let some class Target only provide the member function func() but not gunc(),…

phlipsy
- 2,899
- 1
- 21
- 37
2
votes
1 answer
Template instantiation in different translation units compiled with different optimization levels
Suppose I have two translation units, both of which use std::string. I compile one of them with -O3, and the other without optimizations, then link the result together. Both object files would contain instantiated std::string, but I would expect one…

dragonroot
- 5,653
- 3
- 38
- 63
1
vote
1 answer
Template instantiation reaches depth of 900
In the following code I..
create test list using my custom list struct (which works as expected)
push some test ints into it
want to call a function that takes as parameters every list element (observe())
To achieve this I tried to recursively…

glades
- 3,778
- 1
- 12
- 34
1
vote
0 answers
Do same C++ template usages in different .cpp files duplicate code?
Assume you use the same template_function() in two other .cpp files (a_uses_template.cpp and b_uses_template.cpp), which both instanciate the template implicitly.
As I understand it, this should cause code duplication, because a_uses_template.cpp…

Daniel S.
- 6,458
- 4
- 35
- 78
1
vote
0 answers
Qt Creator doesn't stop on a breakpoint in the templated code with multiple instantiations
I've faced a problem in Qt Creator that looks like a bug, but prior to submitting a ticket I wish to collect more info: is that reproducible, known (maybe there are fixes already), etc.
I'm using Qt Creator 4.11.0 based on Qt 5.14.0 (MSVC 2017). If…

Dmitry Kuzminov
- 6,180
- 6
- 18
- 40
1
vote
1 answer
Is it possible to define both const and regular version of the function with a single definition? (using templates, auto, decltype, etc)
Suppose that I am writing an iterator and const_iterator for singly linked list.
Suppose that I have a following classes:
template
struct Node
{
T value;
Node* next;
}
template
struct NodePtr
{
private:
…

Myrddin Krustowski
- 701
- 3
- 13
1
vote
1 answer
Check whether a default-deleted function template is explicitly specialized for a specific type?
(This question has been significantly edited, sorry.)
Suppose I have several non-constexpr function templates, which default to being deleted:
template void foo() = delete;
template int bar(int x) = delete;
// etc.
and…

einpoklum
- 118,144
- 57
- 340
- 684
1
vote
2 answers
Is there a trick to explicitly instantiate deep template classes?
I have a problem; I want to explicitly instantiate a class like Datatype in:
using Layout = some::namespaces::Meat_Layout;
using Datatype = other::namespaces::Meta_Datatype;
For explicit instantiation I need to use…
user9400869
1
vote
0 answers
gcc compilation error during template instantiation
I am currently doing an upgrade from gcc 4.9 (c++1) to gcc 8.2 (c++14) and I have an issue on gcc 8.2 with the following code
#include
#include
template
struct has_foo_method
{
struct not_found {};
…

chapuilo
- 31
- 2
1
vote
1 answer
Explicit instantiation of function template with `using` or otherwise
using for class templates works like a charm
template
struct VecNT{ T arr[N]; };
using Vec5d = VecNT; // doing great job!
but it seems it does not work for functions at all
template
T sumNT(T* xs){…

Prokop Hapala
- 2,424
- 2
- 30
- 59
1
vote
1 answer
Implementing pimpl-friendly unique_ptr
It is widely known that std::unique_ptr may not be conveniently used to implement pimpl idiom: one may not default destructor and move operator right in the header file (e.g., std::unique_ptr with an incomplete type won't compile). Some people…

Nikita Petrenko
- 1,068
- 1
- 7
- 10
1
vote
2 answers
Does default argument of template class, instantiate the template?
Does the following default argument for the template instantiates a template with type EmptyClass?
class EmptyClass{};
template
class Sample
{
public:
static void test()
{
TYPE::Serialize();
}
};

Sabhareesh Ravichandran
- 145
- 1
- 10
1
vote
1 answer
Why is this member function a duplicate?
I have some code that's worked on VS10 and works on several other platforms, but causes a strange error on VS2015. The error (in a template expansion inside Boost) is very strange because it points to a form without const and tells me that it…

JDługosz
- 5,592
- 3
- 24
- 45
1
vote
1 answer
Dependency injection via template specialization
lib.h:
#include
namespace lib {
template
void f(T t)
{
std::cout << "lib f " << t << std::endl;
}
}
client.cpp:
#include "lib.h"
// explicit instantiation
template
void lib::f(char);
int main()
{
…

feuGene
- 3,931
- 2
- 33
- 46
1
vote
3 answers
Template function for full specialization
I have a function template declared in an header file. This function is an archiver which is supposed to support several other types (classes) implemented through the project. The idea is to have a base template declaration which each class then…

André Fratelli
- 5,920
- 7
- 46
- 87