variadic

How can a template parameter pack have other trailing arguments?

女生的网名这么多〃 提交于 2019-12-23 16:45:50
问题 In the C++14 draft standard, [temp.param]/11 says: If a template-parameter of a primary class template or alias template is a template parameter pack, it shall be the last template-parameter. If you try compiling the following template, then the compiler will complain. template< typename ...Args, void(*f)(Args...) > // ERROR struct Bar {}; But how does it work in this case? template< typename F, F > struct Bar; template< typename ...Args, void(*f)(Args...) > // OK ??? struct Bar< void(*)(Args

How to override a variadic method in Objective-C

青春壹個敷衍的年華 提交于 2019-12-23 11:54:12
问题 I'm trying to extend a class that has a variadic method such as: - (void)someMethod:(id)arguments, ... ; and in the subclass override it by calling the original method like: - (void)someMethod:(id)arguments, ... { [super someMethod:arguments, ...]; // override implementation ... } but this doesn't work. Anyone know how to work this? Thanks. 回答1: similar to printf / vprintf , the base would declare: - (void)someMethod:(id)arguments, ... ; the subclass would implement: - (void)vsomeMethod:(id

Templates accepting “anything” in C++

断了今生、忘了曾经 提交于 2019-12-23 08:49:31
问题 I have a simple template struct associating a string with a value template<typename T> struct Field { std::string name; T self; } I have a function that I want to accept 1-or-more Fields of any type, and the Fields may be of possible different types, so I'm using a std::initializer_list because C++, to my knowledge, lacks typed variadic arguments, cannot determine the size of variadic arguments, and must have at least one other argument to determine where to start. The problem is that I don't

pre-typedef'ing a variadic-function-pointer argument

六眼飞鱼酱① 提交于 2019-12-23 06:57:04
问题 I have a function foo that takes a variadic function pointer as its argument. I would like to use "using" to define the argument's type prior to the function declaration. template <typename ... vARGS> using TFuncType = void(*)(vARGS ... V_args); template <typename ... vARGS> void foo(TFuncType<vARGS ...> funcptr) {} void bar(int i) {} int main() { foo(&bar); // This line fails to compile. } This doesn't compile. The error (via clang using c++1z) is: /make/proj/test/variadic-funcparam-deduce2

How to declare an “implicit conversion” in a variadic template?

本小妞迷上赌 提交于 2019-12-23 05:11:30
问题 My aim is to send a data to several streams. It is possible by using boost::tee. But I want to write a wrapper with variadic template for using several streams. The problem is that I need an implicit convertation from descendant struct to ancestor struct. Or something like that. #include <boost/iostreams/tee.hpp> #include <boost/iostreams/stream.hpp> #include <fstream> #include <iostream> using namespace std; namespace bio = boost::iostreams; using bio::tee_device; using bio::stream; template

Variadic C function printing multiple 2-D char arrays

家住魔仙堡 提交于 2019-12-23 01:24:39
问题 I need to set up a variadic function in C that prints a variable number of 2-D char arrays side-by-side. I'm having a hard time figuring out how to initialize the boards variable with va_arg() . The key problematic line is: boards[i] = va_arg(ap, char*[][BOARDSIZE]); The line produces a compiler error (currently, Second argument to 'va_arg' is of incomplete type 'char *[][10]' ), but basically I'm sure I'm not doing something right. I'm just not sure what that something is. I've tried several

Swift 3.0 closure expression: what if the variadic parameters not at the last place in the parameters list?

旧街凉风 提交于 2019-12-23 00:53:08
问题 Update at 2016.09.19 There is a tricky, indirect way to use variadic parameters before some other parameters in closure expression parameters list, haha let testClosure = { (scores: Int...) -> (_ name: String) -> String in return { name in return "Happy" } } let k = testClosure(1, 2, 3)("John") And I found some related issues in bugs.swift.org: SR-2475 SR-494 Original Post According to the document of Swift 3.0, for a closure expression, "variadic parameters can be used if you name the

How to make a “variadic” vector like class

£可爱£侵袭症+ 提交于 2019-12-22 10:39:38
问题 I am trying to make class that acts as multidimensional vector. It doesn't have to do anything fancy. I basically want to have a "container" class foo where I can access elements by foo[x][y][z]. Now I would also need similar classes for foo[x][y] and foo[x]. Which lead me to ponder about the following (more general) question, is there a way to make something like this where you can just initialize as foo A(a,b,c,...) for any n number of arguments and get a n-dimensional vector with elements

Cocoa - Calling a variadic method from another variadic one (NSString stringWithFormat call)

微笑、不失礼 提交于 2019-12-21 20:48:32
问题 I have a problem with [NSString strigWithFormat:format] because it returns an id, and I have a lot of code where I changed a NSString var to an other personal type. But the compiler does not prevent me that there are places where a NSString is going to be set into another type of object. So I'm writing a category of NSString and I'm goind to replace all my calls to stringWithFormat to myStringWithFormat . The code is : @interface NSString (NSStringPerso) + (NSString*) myStringWithFormat:

expanded parameter list for variadic template

六眼飞鱼酱① 提交于 2019-12-21 06:39:27
问题 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 generic event that will be used to perform the callback in the destination thread. template<typename dest, typename... args> class Event { public: Event(dest* d,