Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++0x variadic template pass by reference

I want to use variadic template feature for my application but I don't want the objects to be passed by value (as objects are quite complex in my case). I want to pass them by reference (not as pointers).

void func() { }  template<typename Function1, typename... FurtherFunctions> void func(Function1 f1, FurtherFunctions... further_functions) {     // doing some processing here... } 

How could I pass the arguments by reference and ensure that they are not copied?

like image 425
usman Avatar asked Jun 15 '11 17:06

usman


1 Answers

Just say:

template <typename ...Args> int myfunction(Args & ... args) {   /* ... */ } 

Same for const Args & ... args, Args && ... args etc.

like image 67
Kerrek SB Avatar answered Oct 20 '22 13:10

Kerrek SB