Skip to main content
17 votes
2 answers
870 views

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 ...
Jarod42's user avatar
  • 230k
0 votes
4 answers
170 views

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(...
one_two_three's user avatar
0 votes
3 answers
139 views

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 ...
Peter VARGA's user avatar
  • 5,353
4 votes
3 answers
372 views

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 ...
emacs drives me nuts's user avatar
1 vote
3 answers
179 views

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 ) : ...
user2015802's user avatar
Best practices
2 votes
5 replies
149 views

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 ...
asdfsdgf's user avatar
0 votes
2 answers
174 views

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 ...
Sailanarmo's user avatar
  • 1,231
Advice
0 votes
1 replies
28 views

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 ...
Jeff G's user avatar
  • 4,729
6 votes
6 answers
283 views

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>...
Miguel Horta's user avatar
3 votes
6 answers
220 views

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 ...
Guillaume Racicot's user avatar
2 votes
1 answer
121 views

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>) -> ...
sthlm58's user avatar
  • 1,274
1 vote
5 answers
246 views

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...)....
armagedescu's user avatar
  • 2,435
1 vote
1 answer
135 views

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, ...
Xenos's user avatar
  • 223
0 votes
1 answer
98 views

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 ...
Pippin's user avatar
  • 333
8 votes
1 answer
387 views

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&...
Erciyuanshagou's user avatar

15 30 50 per page
1
2 3 4 5
274