variadic

C++0x passing arguments to variadic template functions

What does it mean to take a variable number of arguments by reference? Does it mean that each of the arguments are passed by reference? Consider for example the following functions which performs some processing on each its arguments: void f() // base case for recursion { } template <typename Head, typename ... Tail> void f(Head& he...

What does this compiler warning generated by `-pedantic` mean?

What does this GCC warning mean? cpfs.c:232:33: warning: ISO C99 requires rest arguments to be used The relevant lines are: __attribute__((format(printf, 2, 3))) static void cpfs_log(log_t level, char const *fmt, ...); #define log_debug(fmt, ...) cpfs_log(DEBUG, fmt, ##__VA_ARGS__) log_debug("Resetting bitmap"); The last line bei...

Solving the mixin constructor problem in C++ using variadic templates

I've recently tackled the constructor problem, where various mixins classes that decorate each other (and a topmost host class) have different constructor signatures. To maintain a single constructor in the resulting decorated class, and without adding init functions, I've found the following solution. The only restriction it places on a...

Strange behavior (SEGFAULT) of a C program using stdargs (va_start)

Hi folks, I wrote a variadic C function which mission is to allocate the needed memory for a buffer, and then sprintf the args given to this function in that buffer. But I'm seeing a strange behavior with it. It works only once. If I have two calls for this function it segfaults. #include <stdio.h> #include <string.h> #include <stdlib....

Does c++0x tuple use the new variadic templates or Boost's macro-fied tuple implementation?

I read it was based on Boost's version, but I wasn't quite sure what that meant when it came down to implementation. I know Boost does their own variadic template, but I would assume c++0x would use its own variadic templates for the new tuple. ...

Disambiguating argument-less function calls in variadic class hierarchies

I am trying to provide users of a class (MyGizmo below) that derives from a variadic hierarchy (ObjGetter below) with a simple, uncluttered way to unambiguously call a member function that takes no arguments (check() below). I can make this work with functions that take arguments (like tune() below) but I have not found a way to make it ...

Variadic Macro with 3 terms

I am trying to understand a c++ code that reads a dll explicitly. Does any one know how the line "#define LFE_API(name) LFE_##name name" bellow actually works? I understand "#define LFE_API(name) LFE_##name" but get confused about the last "name". struct Interface { # ifdef LFE_API # error You can't define LFE_API be...

Variadic macros with zero arguments, and commas

Consider this macro: #define MAKE_TEMPLATE(...) template <typename T, __VA_ARGS__ > When used with zero arguments it produces bad code since the compiler expects an identifier after the comma. Actually, VC's preprocessor is smart enough to remove the comma, but GCC's isn't. Since macros can't be overloaded, it seems like it takes a se...

Variadic macros with 0 arguments in C99

I have some debugging code that looks like the following: #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) #define AT __FILE__ ":" TOSTRING(__LINE__) void __my_error(const char*loc, const char *fmt, ...); #define my_error(fmt, ...) __my_error(AT, fmt, ##__VA_ARGS__) The last macro is used so I can insert the location into the ...

Function overloading where parameters only differ by ellipses

I've got this logging system for which I'm looking to shortcut some of the string manipulation. The logging system is used via functional macros which then forward to a single function call. E.g. #define Warning(...) LogMessage(eWarning, __VA_ARGS__);. LogMessage then does a snprintf into a new buffer and then presents that message to...

Count of parameters in a parameter pack? Is there a C++0x std lib function for this?

I was just wondering if there was anything in the C++0x std lib already available to count the number of parameters in a parameter pack? I'd like to get rid of the field_count in the code below. I know I can build my own counter, but it just seems like this would be an obvious thing to include in the C++0x std lib, and I wanted to be s...

Variadic templates

Hi all, I have seen a lot of links introduced the variadic templates. But I have never seen one compilable example that demonstrates this approach? Could someone provides me some links in which such compilable examples can be found? regards Sami ...

Passing variadic class template's sub-classes to function that only accepts the base class (via parameter pack deduction/inference)

**I've gotten a few suggestions to make my function pure generic, which would work, but I'd prefer limiting the function to only accept Base and its children. Having trouble making a function that can accept arguments of a variadic template class base type, while the function will actually be called with classes that derive from Base. ...

C Error Checking Function (Not really homework, but don't say I said it wasn't)

For my systems programming class we're doing a lot of programming in C and are required to error check most functions as we are currently learning to program with pthreads. The reason I say this is not really homework, is that it is far above and beyond what is expected for this class. Simply checking each function individually is more ...

char and initializer lists

I'd like to pass some numeric byte values via an initializer list a variadic template into an array. Is that possible? template < int N > struct a { char s[N]; template < typename ... A > a (A ... _a) : s {_a...} {} }; int main () { // g++-4.5: error: narrowing conversion of »_a#0« from »int« to »char« inside { } a < 3 > x { ...

Accepting nested variadic class templates as arguments to function template.

I'm trying to make a function template that will accept two (or more) of the nested variadic class templates listed below, as arguments, and put them into another data structure that will accept different types (pair or tuple is what I'll most likely use). Here are the classes and subclasses, along with the usage of my function (the fun...

expanded parameter list for variadic template

I'm working on an Event based architecture for a research project. The system currently uses Qt signalling, but we are trying to move away from Qt, so I need something that will work almost as well as the Qt event loop and signals across threads. Probably against my better judgement, I've chosen to use variadic templates to create a gen...