55,732 questions
Best practices
0
votes
3
replies
83
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 ...
4
votes
0
answers
139
views
Weird differences between compilers regarding SFINAE and overload resolution
Here's a snippet that does not depend on any external includes, and behaves differently on msvc/gcc/clang.
I left two alternatives inside main.
It compiles with gcc on both alternatives; does not ...
0
votes
1
answer
29
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 ...
0
votes
1
answer
66
views
Why can't Go, html/template, and Fiber collaborate to compose templates?
I want to render a template using a base template and one of two partial templates, based on the context. Something like:
Patial A Base Template
|──...
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&...
2
votes
1
answer
132
views
How to apply a concept to a trailing return type
Here is some basic example:
template <typename T, typename Callable>
constexpr auto foo(T arg, Callable&& make)
-> decltype(make(std::declval<T>())) {
return make(arg);
}...
17
votes
3
answers
860
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 ...
Best practices
1
vote
3
replies
84
views
Angular Signals and methods in templates
It is good practice to use signals in templates and bad practice to use methods.
But signals and methods?
Example (using the get method from Map):
userStatuses: WritableSignal<Map<string, string&...
-1
votes
1
answer
64
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 ...
1
vote
1
answer
58
views
Why is my project controller doesn't see my templates views?
I started new project with spring boot starter web and ran into a problem.
package com.example.project2;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind....
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 "...
10
votes
4
answers
1k
views
C++ template dispatching not calling the correct function
The program test tag dispatching pattern, where the function process_data(tag, a, b) can accept 2 tags int_tag, float_tag. There are 3 case:
int_tag and a, b are int -> print a + b
float_tag and a,...
6
votes
2
answers
314
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>;
...
-1
votes
0
answers
53
views
Why this template function needs to be defined in the header file [duplicate]
I have a function called secure_entry() declared in templates_intro.hpp and defined in templates_intro.cpp
template <typename T> T secure_entry()
{
T variable {};
while(!(std::cin>>...
8
votes
6
answers
848
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 ...
2
votes
0
answers
38
views
Symfony 6 - EasyAdmin - Custom form type canvas
I use Symfony 6 with EasyAdmin,
I've been trying for several hours to understand how form types work in Symfony, and more specifically how to set up a custom form field, but I can't find a simple, ...
4
votes
2
answers
174
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,...
0
votes
2
answers
74
views
How to assign single product template to product by its category (WordPress/ WooCommerce/ Block theme)
I tried to assign single product template to product by its category. I had searched for similar questions but found answers in classic theme. Below are 2 examples of several codes that Gemini gave me ...
-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 ...
0
votes
1
answer
110
views
Unable to use Airflow variable with function in Jinja template
I'm trying to pass Airflow logical_date to dbt model so that I can use it in the model (sql). I'm using Airflow 2.11.0. I'm doing below, but the dag couldn't get constructed, with an error says:
'...
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;
...
1
vote
2
answers
113
views
Partial specialization for a wrapper type
Suppose we have the following struct templates:
template <typename A, typename B>
struct Foo { }; // (1) library
template <typename T>
struct Bar { }; // (2) library
template <...
0
votes
0
answers
111
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 ...
5
votes
1
answer
151
views
Unused short circuit result with side effects
To avoid recursive template programming I am relying on the short circuit evaluation of the result of lambdas combined with logical && using a fold expression. Is that safe to do or will the ...
1
vote
2
answers
95
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::...
3
votes
6
answers
199
views
Generalize a self referential struct construction using a variadic template
I have some tricky code that I need to initialize many objects that refer to each other. I want to allocate and construct them all at once, so I put them all in a struct.
It looks like this:
// User ...
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
>&...
1
vote
1
answer
117
views
Pass mixed references to function: value for small types, and reference for large types
I want to define a templated function that admits parameters by value only when they are "cheap to copy" and by reference when they are not.
For example, given function F, the goal is to ...
2
votes
1
answer
184
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
{
...
0
votes
0
answers
44
views
Problem creating new Blazor Template in Visual Studio after Windows 11 upgrade
Update
I see what is happening, but I am not sure what the cause is or how to resolve it:
When I use a template that was previously 'installed' in Visual Studios before we upgraded to Windows 11 - ...
6
votes
2
answers
180
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 ...
0
votes
0
answers
45
views
Using std::span in a template function parameter [duplicate]
This won't compile in a template function but the non-template version works fine. I can't find why?
#include <windows.h>
#include <iostream>
#include <span>
#include <vector>
...
1
vote
1
answer
107
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, ...
21
votes
1
answer
1k
views
Can I pass a pointer to a consteval function as an NTTP in C++?
Is it legal to pass a pointer to a consteval function as an NTTP? Assuming that the pointer doesn't escape to runtime.
Given the following code, GCC trunk compiles it but Clang trunk rejects it:
#...
5
votes
2
answers
261
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 ...
2
votes
0
answers
187
views
Why implement a template function as free instead of member?
Is there any good reason why some STL functions are implemented as free functions instead of members?
I understand the benefit when you need to provide explicit template parameters, like std::get<N&...
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
25
views
Can't load .yml files from the data folder to a template
My Goal is to use a template (card_gallery.html) to display different content depending on the specific page using the template. My info about what should be on each card is stored in a data structure ...
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&...
0
votes
1
answer
45
views
Per-type constants depending on type parameter
I have a value-parametric struct
struct T{p}
...
end
where p::Int is expected. For each concrete type T{p}, I want to maintain a global(!) constant with value f(p) for some function f. The point ...
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&...
3
votes
2
answers
147
views
Template template with container argument in C++17
To create a C++ class template that takes a standard container as a template argument I would do something like
#include <vector>
template <template<typename U,typename A=std::allocator&...
5
votes
1
answer
144
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:
[...
0
votes
1
answer
96
views
Variadic template function that I can't fix on my own [closed]
I can't implement correctly the function I need.
That function should take one or more parameters, convert each parameter into QString, and append them all together, with a provided separation ...
-3
votes
1
answer
157
views
String replace function with a new string lazy-evaluated, from a value or a functor
I want to create a universal template function that replaces all occurrences of a search string in a given string object with the replace text lazy-evaluated, possibly by calling a functor.
The main ...
1
vote
1
answer
152
views
generic growable buffer / array type template with non-trivial types
How would you create a generic buffer or array type template (not using STL) that may be used on a struct type that includes a class or non-trivial type. Something this, which uses memcpy and such ...
2
votes
2
answers
118
views
How to partially specialize for a type nested in a template?
I have a template struct with a nested class, eg.
template <typename T>
struct example {
struct type { };
};
template <typename T>
using example_t = typename example<T>::type;
...
-4
votes
2
answers
136
views
Compile time ternary expression [closed]
In the following:
template <int num_components>
struct EntityInfo
{
int indices[num_components];
};
template <typename ... Types>
struct Foo
{
EntityInfo<sizeof ... (Types)>...
0
votes
0
answers
29
views
Visual Studio Templates - Multi Projects - Files not loading
I am trying to create a template for projects. I have followed the Microsoft Tutorial on how to create project templates with multi projects: Link below:
https://learn.microsoft.com/en-us/visualstudio/...
0
votes
1
answer
105
views
std::basic_string_view with one template argument
In MSVC's Standard Library and in libc++ std::basic_string_view is declared like this:
template <class _Char, class _Traits>
class basic_string_view {
// ...
};
Note, that there is no ...