153 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
3
votes
1
answer
122
views
Does an explicit instantiation declaration allow an explicit template specialization to be only declared in a separate translation unit?
Short version: Does an explicit instantiation declaration guarantee that a visible template definition is never used (unless an explicit instantiation definition is also encountered), and therefore ...
0
votes
1
answer
123
views
How to explicitly instantiate forwarding constructor in C++?
I'm trying to explicitly instantiate a forwarding constructor using C++20 with GCC 13.3 compiler in order not to put its definition in the header file. Here is a minimal example:
Foo.h
#pragma once
...
3
votes
1
answer
144
views
Reduce boilerplate for explicit templates instantiations in .cpp file
In order to hide template function definition in .cpp file, while having the forward declaration in a header file (function is used by a class template), the template has to be instantiated in order ...
1
vote
1
answer
142
views
Resolving compilation error with template specialization
I am having issues in understanding and fixing a compiler error that I see with MinGW (UCRT64) C++20, but that I don't see when I build the code with MSBuild C++11.
header.h: (Only relevant code)
#...
0
votes
0
answers
75
views
Omitting function arguments for instantiating function templates
The short story is I am trying to have function templates and the main function in different compilation units like this (I am using g++ (GCC) 14.2.1 if it matters):
// a.cpp
template<typename T>...
0
votes
1
answer
75
views
How to export SFINAE-constrained ctor defined in cpp file for explicitly instantiated template class?
Here's my attempt:
The header defining the Foo template class and declaring but not defining a ctor only for a given value of the NTTP N,
// foo.hpp
#include <type_traits>
template<int N>...
0
votes
1
answer
99
views
c++ efficient explicit template instantiation for several template parameters
I am writing a c++ library where I deal with plenty of templated classes and free functions . Example (header + source file containing a free function):
#ifndef MY_FUNCTION_HPP
#define MY_FUNCTION_HPP
...
0
votes
0
answers
52
views
Ignoring "#include"s only in the released library?
I have a templated library where all of my classes are explicitly instantiated and built into a static library. The library is structured like this:
repo/
| - include/
| - mylib/
...
0
votes
0
answers
28
views
.lib not generated when building DLL project using template class [duplicate]
I tried to build this C++ CMake project as DLL.
Math.dll generated, but Math.lib did not generated.
This is source code.
Math.h
#pragma once
// Shared library import/export macro
#ifdef _WIN32
#ifdef ...
0
votes
3
answers
160
views
Prevent C++ template codes from being compiled for many times
I coded a message queue template in c++, and I want use it in many different projects, so that I put it into a namespace, for example my_lib.
In order to prevent the codes from being compiled ...
2
votes
1
answer
172
views
Does C++20 support declaring an explicit function template instantiation using constraints after the template has been referenced in another template?
Context
In C++, we seem to be able to declare/define explicit function template instantiations after the function template has been referenced in another template function, if the other template ...
2
votes
2
answers
159
views
C++: Implicit conversion when templates are explicitly instantiated
It is well known that when we want to have the declarations of templated class/functions in a header file and the their definition in a source cpp file, the must add explicit instantiation at the end ...
1
vote
0
answers
55
views
explicit instantiation of static var in class template [duplicate]
I have the following class with a static data member but linking failed with undefined reference to X<int, int>::list
#include <vector>
template < typename T1, typename T2 >
class X
...
0
votes
1
answer
325
views
BOOST Preprocessor BOOST_PP_LOCAL_ITERATE nested loops
I have a templated C++ function:
template<int i, int j> void foo();
I would like to define it in a .cpp file and instantiate it explicitely. The parameters i and j have the same admissible range ...
2
votes
1
answer
135
views
Why can (implicitly) instantiated function templates use undeclared symbols?
I have the following code:
template <typename T>
void fun(T t) {
// foo and bar are not declared yet, but this is okay,
// because they can be found through ADL for a class type T
...