-1

I have a vector, length of it is n. A function looks like int foo(int x_1, int x_2, ..., int x_n). Are there any ways to turn this vector to a nice object?

I don't know what I should do

Python has the simple construction which helps to separate smth. May be C++ has the same one?

a, b = map(int, input().split())

I expect for a kind of this construction

sergevkim
  • 7
  • 1
  • 1
    you tag C++ but in you code snippet you have python. Which one is it? – bolov Jul 16 '19 at 13:11
  • 1
    @bolov The way I understand this question (and which makes it a valid one) is "how to achieve in C++ what this Python code would do in Python". – Angew is no longer proud of SO Jul 16 '19 at 13:12
  • 1
    @Angew great. He should [edit] the question to specify this if that is indeed the case. – bolov Jul 16 '19 at 13:13
  • also `int foo(int x_1, int x_2, ..., int x_n)` doesn't make much sense in C++ – bolov Jul 16 '19 at 13:14
  • 1
    This would mean, that you know at compile-time, which function you want to call. So you need to know the number of arguments at compile-time. Then you can go the happy path of templates. There has to be a combination of variadic templates and https://en.cppreference.com/w/cpp/utility/integer_sequence –  Jul 16 '19 at 13:14
  • 2
    [Related](https://stackoverflow.com/q/55281612/3233393). – Quentin Jul 16 '19 at 13:17
  • 1
    "Are there any ways to turn this vector to a nice object?" ??? – Aykhan Hagverdili Jul 16 '19 at 13:23

1 Answers1

0
std::vector<int> my_vec;

// here init my_vec

// now pass it to foo

if(my_vec.size() != n){
    // handle invalid input
}
else{
   int return_val = foo(my_vec[0], my_vec[1], .... , my_vec[n-1]);
}

// enjoy!
nivpeled
  • 1,810
  • 5
  • 17