4,097 questions
17
votes
2
answers
870
views
Rationale of variadicity of std::function_ref
Whereas:
std::function has a single type, i.e template <typename Sig> std::function<Sig>;
std::function_ref is variadic, i.e template< class...> class function_ref; (and all ...
0
votes
4
answers
170
views
Shall I use macros or variadic templates to manage output? [closed]
I want to manage output in consistent manner. For example, for error message -- print it to std:err, adding "[ERROR] " prefix.
I can do it straightforwardly via macros:
#define LOG_ERR(...
0
votes
3
answers
139
views
CTAD in a variadic template function
I refer to this question: How to use source_location in a variadic template function?
The solution is perfect because it keeps the function name and line number where the function was called and there ...
4
votes
3
answers
372
views
Correct syntax for function template with an even number of `int` arguments?
When rewriting a C varargs function as a function template, I am struggling to find the right syntax. xfun() should be a function with a double parameter followed by an even number of ints. Something ...
1
vote
3
answers
179
views
How to create alias to template function wrapper
I have a class template with a static wrapper function that returns a shared_ptr.
class bar {};
template < class T >
class foo : public bar
{
public:
T variable ;
foo ( T t ) : ...
Best practices
2
votes
5
replies
149
views
C++ Varadic Template Class
I am trying to generalise a class that can accept different types, but also optionally accept multiple types. The class must use virtual functions.
For a single type a specialised class might look ...
0
votes
2
answers
174
views
How to help the compiler deduce the arguments of a variadic function?
I have been working on trying to convert some legacy software to use variadic templates. However, I have been really struggling on overhauling one of the classes, which provides logging, and keeping ...
Advice
0
votes
1
replies
28
views
Variadic Template Class Generate One Abstract Method Per Parameter Pack Argument
What is the syntax to conditionally generate one pure virtual method per parameter pack argument? E.g., the following illustrates what I would like to accomplish, but can't because template functions ...
6
votes
6
answers
283
views
How to ensure order of template parameter pack with static_assert?
Let's say I have the following code:
#include <array>
#include <string>
#include <variant>
using namespace std::literals;
using known_types_t = std::variant<int, double, char>...
3
votes
6
answers
220
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 ...
2
votes
1
answer
121
views
How to emulate variadic template type parameters in Rust?
I'm want to be able to avoid code duplication when writing Rust template code to work with variadic number of template parameters, like so:
fn to_c_function_0<C>(closure: Box<C>) -> ...
1
vote
5
answers
246
views
Variadic template function doesn't infer the correct type of the template argument
I have a template function with variadic arguments, which is supposed to take an argument of a type and return a result of a longer type (ie long long for int, double for float, int for short, etc...)....
1
vote
1
answer
135
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, ...
0
votes
1
answer
98
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 ...
8
votes
1
answer
387
views
Different compiler behaviours regarding variadic template - Error C3520 / C3543
This code snippet compiles in GCC & Clang but not in MSVC:
template<int...n> struct StrStuff {
explicit StrStuff(char const(&...s)[n]) {}
};
int main() {
StrStuff g("apple&...