variadic

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

给你一囗甜甜゛ 提交于 2019-11-27 17:30:48
问题 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 sure it wasn't already there :) Home-grown counter implementations are most welcome too. template<const int field_count, typename... Args> struct Entity { const

C++11 type trait to differentiate between enum class and regular enum

扶醉桌前 提交于 2019-11-27 14:38:41
I'm writing a promotion template alias similar to boost::promote but for C++11. The purpose of this is to avoid warnings when retrieving arguments from varidic functions. e.g. template <typename T> std::vector<T> MakeArgVectorV(int aArgCount, va_list aArgList) { std::vector<T> args; while (aArgCount > 0) { args.push_back(static_cast<T>(va_arg(aArgList, Promote<T>))); --aArgCount; } return args; } The Promote template alias promotes the type following the default argument promotion for variadic arguments: 1) An integer that's smaller than an int is promoted to int 2) A float is promoted to

Macro to count number of arguments

送分小仙女□ 提交于 2019-11-27 13:20:38
I have a variadic function from a third-party C library: int func(int argc, ...); argc indicates the number of passed optional arguments. I'm wrapping it with a macro that counts the number of arguments, as suggested here . For reading convenience, here's the macro: #define PP_ARG_N( \ _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \ _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \ _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \ _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \ _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \ _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \ _61, _62,

How do I handle an unspecified number of parameters in Scheme?

走远了吗. 提交于 2019-11-27 12:17:21
问题 For example ((fn-stringappend string-append) "a" "b" "c") I know how to handle this (f x y z) . But what if there's an unknown number of parameters? Is there any way to handle this kind of problem? 回答1: In Scheme you can use the dot notation for declaring a procedure that receives a variable number of arguments (also known as varargs or variadic function): (define (procedure . args) ...) Inside procedure , args will be a list with the zero or more arguments passed; call it like this:

Is it possible to trigger compile time error with custom library in golang?

强颜欢笑 提交于 2019-11-27 07:59:26
问题 Let's say, I have min() (just for example) a variadic function to define the smallest value from multiple values provided. If the caller don't provided any parameter, I want to halt compile process (as this would be the bug in the caller, not error in my function). How to do that? 回答1: Calling a function which has variadic parameter and passing no arguments is valid by the language spec. So you can't make it a compile-time error. However, you may modify the signature of your function to have

Passing parameters dynamically to variadic functions

跟風遠走 提交于 2019-11-27 05:21:30
I was wondering if there was any way to pass parameters dynamically to variadic functions. i.e. If I have a function int some_function (int a, int b, ...){/*blah*/} and I am accepting a bunch of values from the user, I want some way of passing those values into the function: some_function (a,b, val1,val2,...,valn) I don't want to write different versions of all these functions, but I suspect there is no other option? Variadic functions use a calling convention where the caller is responsible for popping the function parameters from the stack, so yes, it is possible to do this dynamically. It's

C++11 variable number of arguments, same specific type

為{幸葍}努か 提交于 2019-11-27 04:21:42
问题 Question is simple, how would I implement a function taking a variable number of arguments (alike the variadic template), however where all arguments have the same type, say int. I was thinking about something alike this; void func(int... Arguments) Alternatively wont a recursive static assert on the types work? 回答1: A possible solution is to make the parameter type a container that can be initialized by a brace initializer list, such as std::initializer_list<int> or std::vector<int>. For

Objective-C passing around … nil terminated argument lists

强颜欢笑 提交于 2019-11-27 03:51:21
Having some issues with the ... in ObjectiveC. I'm basically wrapping a method and want to accept a nil terminated list and directly pass that same list to the method I am wrapping. Here's what I have but it causes an EXC_BAD_ACCESS crash. Inspecting the local vars, it appears when otherButtonTitles is simply a NSString when it is passed in with otherButtonTitles:@"Foo", nil] + (void)showWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... { UIAlertView *alert = [[

Variadic compose function?

两盒软妹~` 提交于 2019-11-27 02:41:48
问题 I'm trying to write a variadic function composition function. Which is basically the (.) except that the second argument function is variadic. This should allow expressions like: map even . zipWith (+) or just map even . zipWith Currently what I've reached works if I add IncoherentInstances and requires a non-polymorphic instance for the first argument function. {-# LANGUAGE FlexibleInstances, OverlappingInstances, MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances,

C++/C++11 - Switch statement for variadic templates?

一世执手 提交于 2019-11-27 00:15:22
问题 Let's say I have a few structs like this: struct MyStruct1 { inline void DoSomething() { cout << "I'm number one!" << endl; } }; struct MyStruct2 { static int DoSomething() { cout << "I'm the runner up." << endl; return 1; } }; struct MyStruct3 { void (*DoSomething)(); MyStruct3() { DoSomething = &InternalFunction; } static void InternalFunction() { cout << "I'm the tricky loser." << endl; } }; As you can see, for all three structs, I can call DoSomething() on an object of that struct and