55,732 questions
1
vote
1
answer
62
views
Is it possible to distinguish an instantiation of a primary template from instantiation of a (partial) specialization?
Given a template T and some type U, I can write a trait to see if U is an instantiation of T. For a simple case of a single template argument the trait could look like this:
#include <type_traits&...
0
votes
0
answers
25
views
Issue with Template.Json not excluding files
I have built a template project with a Template.json and this will generate the template fine ( no errors at all )
ive also managed to add some choices to the symbols that will add or hide code ...
7
votes
1
answer
210
views
Line location as default value for an argument and template argument of a function
Suppose the following foo function has a function parameter and a template parameter, both with the same default value:
template<int Line=std::source_location::current().line()>
auto foo (int ...
Best practices
0
votes
3
replies
90
views
Code design conundrum: runtime polymorphism, templates, compile times, and OpenMP
I'm struggling to finalise the design of my C++17 library.
One of the primary goals is to use runtime polymorphism to allow users to extend or rewrite default features of the library for their own use ...
0
votes
1
answer
36
views
“Invalid Order” error when generating second custom PDF template
I’m using the WooCommerce PDF Invoices & Packing Slips plugin by WP Overnight.
I’ve successfully:
Created a second custom PDF template (a voucher version without
prices).
Added a button on the ...
1
vote
0
answers
122
views
Why does C++ treat the same static member differently when accessed through a dependent base class versus a complete type? [duplicate]
I'm confused by how C++ handles static member access in templates when inheritance and dependent names are involved. Look at this code:
struct Global {
static int value;
};
template<typename T&...
17
votes
3
answers
874
views
Necessity of `typename` for naming of local nested classes in function templates
I have a function template f, defining in its body a local class A with another nested class B. Both classes are not templates. Must I name the inner class as typename A::B or shorter variant A::B is ...
-1
votes
1
answer
66
views
Virtualization using VirtualizingStackPanel inside custom ControlTemplates
I'm tasked with implementing a custom DataGrid-like control in one of my projects.
This is due to many specific features it needs to have implemented, and also the large amounts of data that have to ...
2
votes
1
answer
87
views
Replace strings in files when using a .NET item template
I am creating my first template for a .NET solution. For the most part it works, but I have a string "MyService" at some places in the Program.cs that I would like to replace with "...
6
votes
2
answers
315
views
Is there a way to explicitly instantiate many template classes all with the same set of parameters?
I've got many templated classes which all need to be explicitly instantiated on the same set of parameters e.g.
template class A<double, size_t>;
template class A<double, unsigned int>;
...
8
votes
6
answers
852
views
Template for function with N inputs
If it's possible, I would like to define a macro that would take number of arguments in function template ARGS_COUNT and make a template with all argument types being enumerated and output being ...
4
votes
2
answers
175
views
Define a concept in C++ for specific members
I have several structs in the form
struct MyStruct1 {
std::string myName;
// ...
}
but not all of them have a member of type std::string and variable named myName.
I'm writing a function template,...
-1
votes
2
answers
85
views
How to use gorazor and iterate over a slice
I want to use gorazor a viewengine written in go that uses razor-Syntax. They provide an example which i tried to understand and adapt.
What is working
I want to iterate over a slices of movies and ...
2
votes
2
answers
195
views
derived class cannot call recursively inherited member functions C++
I'm making it using multi inheritance with a pair struct that contains
an index and the type of the element in a recursive structure like this:
template<int index, typename... ts>
struct ok;
...
0
votes
0
answers
135
views
Is this Visual Studio 2026 Item Template supposed to be here?
In Visual Studio 2026 Insiders, while right clicking on my xUnit Test Project, and clicking to add a new file, I found this weird item template at the bottom which does not appear to be visible in ...
1
vote
2
answers
96
views
Does SONAR's cpp:S5213 rule imply that functions accepting lambdas must be implemented in the .h file?
SONAR's cpp:S5213 rule says that
Template parameters should be preferred to "std::function" when configuring behavior at compile time
We have tried implementing that by replacing std::...
0
votes
0
answers
27
views
EJS error: include is not a function when using <%- include('partials/sidebar', { user: user, page: 'invoice' }) %>
I'm working on an Express + EJS project and getting this error when rendering my invoice.ejs view:
TypeError: C:\Users\naray\OneDrive\Desktop\Invoice-saas\invoice-generator\views\invoice.ejs:17
>&...
2
votes
1
answer
185
views
C++ templates and undeclared identifiers
I'm using some templates in my project. I prefer the approach of putting the declarations in a .h file and the definitions in a .tpp file.
Currently it's set up like this:
// myclass.h
class myClass
{
...
6
votes
2
answers
182
views
Enforce CRTP via Constraint in C++
I'd like to enforce a CRTP template parameter to be an actual derived type. Unfortunately it seems to be impossible to express that as a constraint.
The problem is that the constrained type is ...
1
vote
1
answer
108
views
Is it possible to expand/deduce a parameter pack to/from array dimensions?
I am using the following code for automatic vector/matrix template parameter deduction (I am particullarily interested in automatic deduction from passing initializer lists)
template<class T, ...
5
votes
2
answers
262
views
Function templates leave out debug lines
I am working in a codebase that makes heavy use of templates. This causes many issues with debugging, because the compiler leaves almost no debugging information behind to tie object code back to ...
1
vote
1
answer
154
views
Template : How to change a default typename to a typename that can't be changed?
struct ResultDeleter
{
typedef HANDLE pointer;
void operator()(pointer ptr) noexcept
{
ResultFree(ptr);
}
};
template<typename P = std::unique_ptr<std::remove_pointer_t&...
0
votes
0
answers
89
views
Decltype not able to pick a template function based on its concept
Here's the minimal example for the issue I'm trying to solve
#include <iostream>
template<class F_TYPE, F_TYPE F, class T>
auto func(const T &value)
{
return F(value);
}
template&...
10
votes
0
answers
176
views
Out of line definitions for members of constrained partial specializations
MSVC doesn't accept this code, even the latest version on Godbolt:
#include <type_traits>
template <class R>
struct A {
A();
};
template <class R>
requires std::is_reference_v&...
5
votes
1
answer
147
views
Is an "inline function template" considered a "inline function" with respect to ODR rules?
In the C++20 draft (N4868) there are two relevant rules about definition reachability:
Inline functions must have their definition reachable in every translation unit in which they are ODR-used:
[...