passing tuple to a function

Hi Guys,

I want to pass tuple as a function argument. Do I have to specify the exact contents of tuple which I will be passing or is there any other better way of doing it?

Right now I am doing it as :

1
2
3
4
5
6
7
8
9
10
11
12
void manageData(tuple< map<string, userInfo>&, int, fd_set&, map<string, userInfo>& > &tupl) { 

} 

int main() { 

    tuple < map<string, userInfo>&, int, fd_set&, map<string, userInfo>& > tupl(localDB, i, maxSfdSet, onlineUsers) ; 

      manageData(tupl); 
      return 0 ;
}


Is there a better way to do what I am doing above? I mean it feels kind off weird to specify the exact type of tuple as function argument.

Please let me know

Thanks
C++ is still a statically typed language. Tuples are static types. They are just generalizations of std::pair.

Usually, when one creates something like this, a typedef is used so that one only has to specify the types contained in the tuple once.
Thanks for the reply PanGalactic.

Is there a tuple pointer?
Not sure what you mean?
Couldn't manageData be a template function? For example:
1
2
3
4
template <typename T1, typename T2, typename T3, typename T4>
void manageData(tuple<T1, T2, T3, T4> &tupl) { 
    //...
} 


I believe that it could deduce the template arguments from the function call. This would, of course, limit the function to taking a tuple of four types (and any other requirements set in the body of the function). This doesn't seem to buy you much, though--I'd stick with typedefs.
Last edited on
@PanGalactic: Sorry for not being clear, I meant is there a pointer that I can use to point to tuple object?

@moorecm: Thanks for the reply. Yes, finally I am using typedefs.
You mean like this?

1
2
3
4
5
6
7
8
9
typedef tuple<int, string, float> MyTuple;

MyTulple* ptr;

typedef shared_ptr<MyTuple> MyTuplePtr;

MyTuplePtr sptr(new MyTuple);

if (sptr->get<2>() == 0.0) ...


There's nothing magic about tuples.
Thanks so much PanGalactic. That's exactly what I was looking for.
Topic archived. No new replies allowed.