1

On python I can group arguments into a tuple, something like

def func((a, b, c, d), x):
    print a, b, c, d, x

I was wondering if it is possible to group arguments in the same way on C++, something like:

void func((int a, int b, int c, int d), float x)
{
    cout << a << b << c << d << x << endl;
};
shackra
  • 113

1 Answers1

6

it can be done with std::tuple

#include <iostream>
#include <tuple>
using namespace std;

void func(tuple<int, int, int, int> tup, float x)
{
    int a, b, c, d;
    tie(a, b, c, d) = tup;
    cout << a << b << c << d << x << endl;
}

int main() {
    func(make_tuple(1, 2, 3, 4), 5.5f);
    return 0;
}
Bryan Chen
  • 1,095
  • On some (conformant, not VS2013) C++11 compilers, the function call can be made as func({1, 2, 3, 4}, 5.5f);. Note that the using namespace std; statement is not necessary for the solution, just a habit of the answerer. – Lars Viklund Jan 07 '14 at 10:14