variadic

Is Boost.Tuple compatible with C++0x variadic templates?

强颜欢笑 提交于 2019-11-30 15:12:18
I was playing around with variadic templates (gcc 4.5) and hit this problem : template <typename... Args> boost::tuple<Args...> my_make_tuple(Args... args) { return boost::tuple<Args...>(args...); } int main (void) { boost::tuple<int, char> t = my_make_tuple(8, 'c'); } GCC error message : sorry, unimplemented: cannot expand 'Arg ...' into a fixed-length argument list In function 'int my_make_tuple(Arg ...)' If I replace every occurrence of boost::tuple by std::tuple , it compiles fine. Is there a problem in boost tuple implementation? Or is this a gcc bug ? I must stick with Boost.Tuple for

C++ overloading operator comma for variadic arguments

大城市里の小女人 提交于 2019-11-30 13:54:13
is it possible to construct variadic arguments for function by overloading operator comma of the argument? i want to see an example how to do so.., maybe something like this: template <typename T> class ArgList { public: ArgList(const T& a); ArgList<T>& operator,(const T& a,const T& b); } //declaration void myFunction(ArgList<int> list); //in use: myFunction(1,2,3,4); //or maybe: myFunction(ArgList<int>(1),2,3,4); It is sort-of possible, but the usage won't look very nice. For exxample: #include <vector> #include <iostream> #include <algorithm> #include <iterator> template <class T> class list

Arbitrary dimensional array using Variadic templates

左心房为你撑大大i 提交于 2019-11-30 09:20:57
问题 How can I create an Array class in C++11 which can be used like Array < int, 2, 3, 4> a, b; Array < char, 3, 4> d; Array < short, 2> e; and access it in a way like a[2][1][2] = 15; d[1][2] ='a'; I also need to overload operator as T &operator[size_t i_1][size_t i_2]...[size_t i_D]; which does not exist. How can I do this? 回答1: The simplest way to do this is by nesting std::array : #include<array> template<class T, size_t size, size_t... sizes> struct ArrayImpl { using type = std::array

Golang Join array interface

安稳与你 提交于 2019-11-30 09:14:53
问题 I try to create bulk insert. I use gorm github.com/jinzhu/gorm import ( "fmt" dB "github.com/edwinlab/api/repositories" ) func Update() error { tx := dB.GetWriteDB().Begin() sqlStr := "INSERT INTO city(code, name) VALUES (?, ?),(?, ?)" vals := []interface{}{} vals = append(vals, "XX1", "Jakarta") vals = append(vals, "XX2", "Bandung") tx.Exec(sqlStr, vals) tx.Commit() return nil } But I got an error: Error 1136: Column count doesn't match value count at row 1 becuse i return wrong query INSERT

A clean way to store a function and its (arbitrary-type, arbitrary-number) arguments

旧街凉风 提交于 2019-11-30 07:16:12
问题 For a library, I'd like a function to accept another function and its arguments, then store them all for calling later. The arguments must allow for any mixture of types, but the functions only need to return void. Something like this: void myFunc1(int arg1, float arg2); void myFunc2(const char *arg1); class DelayedCaller { ... public: static DelayedCaller *setup(Function func, …); }; ... DelayedCaller* caller1 = DelayedCaller::setup(&myFunc1, 123, 45.6); DelayedCaller* caller2 =

Check if parameter pack contains a type

亡梦爱人 提交于 2019-11-30 07:16:06
问题 I was wondering if C++0x provides any built-in capabilities to check if a parameter pack of a variadic template contains a specific type. Today, boost:::mpl::contains can be used to accomplish this if you are using boost::mpl::vector as a substitute for variadic templates proper. However, it has serious compilation-time overhead. I suppose, C++0x has compiler-level support for std::is_same. So I was thinking if a generalization like below is also supported in the compiler. template <typename.

Does Haskell have variadic functions/tuples?

泄露秘密 提交于 2019-11-30 01:37:13
The uncurry function only works for functions taking two arguments: uncurry :: (a -> b -> c) -> (a, b) -> c If I want to uncurry functions with an arbitrary number of arguments, I could just write separate functions: uncurry2 f (a, b) = f a b uncurry3 f (a, b, c) = f a b c uncurry4 f (a, b, c, d) = f a b c d uncurry5 f (a, b, c, d, e) = f a b c d e But this gets tedious quickly. Is there any way to generalize this, so I only have to write one function? Try uncurryN from the tuple package. Like all forms of overloading, it's implemented using type classes. In this case by manually spelling out

How do I pass each element of a slice as a separate argument to a variadic C function?

倖福魔咒の 提交于 2019-11-29 15:22:28
I'm building a Redis Module in Rust. I've found some good examples, but I'm stuck when dealing with interfacing a C function that is supposed to accept variadic arguments. The Redis Module C SDK has a function called RedisModule_Call which accepts a few specific arguments then n arguments that represent a Redis command. From the Redis Module SDK documentation (in C): RedisModuleCallReply *reply; reply = RedisModule_Call(ctx,"INCR","sc",argv[1],"10"); RedisModule_Call 's first three arguments are specific, but the rest represent Redis commands that could easily have hundreds of arguments. In

Arbitrary dimensional array using Variadic templates

随声附和 提交于 2019-11-29 14:58:15
How can I create an Array class in C++11 which can be used like Array < int, 2, 3, 4> a, b; Array < char, 3, 4> d; Array < short, 2> e; and access it in a way like a[2][1][2] = 15; d[1][2] ='a'; I also need to overload operator as T &operator[size_t i_1][size_t i_2]...[size_t i_D]; which does not exist. How can I do this? The simplest way to do this is by nesting std::array : #include<array> template<class T, size_t size, size_t... sizes> struct ArrayImpl { using type = std::array<typename ArrayImpl<T, sizes...>::type, size>; }; template<class T, size_t size> struct ArrayImpl<T, size> { using

Golang Join array interface

余生长醉 提交于 2019-11-29 13:56:01
I try to create bulk insert. I use gorm github.com/jinzhu/gorm import ( "fmt" dB "github.com/edwinlab/api/repositories" ) func Update() error { tx := dB.GetWriteDB().Begin() sqlStr := "INSERT INTO city(code, name) VALUES (?, ?),(?, ?)" vals := []interface{}{} vals = append(vals, "XX1", "Jakarta") vals = append(vals, "XX2", "Bandung") tx.Exec(sqlStr, vals) tx.Commit() return nil } But I got an error: Error 1136: Column count doesn't match value count at row 1 becuse i return wrong query INSERT INTO city(code, name) VALUES ('XX1','Jakarta','XX2','Bandung', %!v(MISSING)),(%!v(MISSING), %!v