problem using std::forward

Mar 2, 2016 at 6:09pm
Hi,

I have these overloaded functions which signature is:

// VERSION 1
template<typename Control, typename...Args>
auto addWidget( unsigned height, const Args&...arguments );


// VERSION 2
template<typename Control, typename...Args>
auto addWidget( string field_name, unsigned height, const Args&...arguments );


// NOW: version 2 calls VERSION 1 like so:
template<typename Control, typename...Args>
auto addWidget( string field_name, unsigned height, const Args&...arguments ) {

auto widget = addWidget( height, std::forward<const Args>(arguments)... );
// other stuff
return widget;
}


//// I am getting the following compiler warning:
/Users/juandent/Programs/C++/With Qt/sqlwidgetmapper/dialogcreator.h:94: error: no matching function for call to 'forward'
height, std::forward<const Args&...>(arguments...) );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~


WHAT IS GOING ON? I just want to perfect-forward the variable number of arguments received by both versions!!

Thanks,
Juan









auto widget = addWidget( associated_label, name, field_name,
x, y, width, height, std::forward<const Args&...>(arguments...) );
Last edited on Mar 2, 2016 at 6:52pm
Mar 2, 2016 at 7:29pm
I just want to perfect-forward the variable number of arguments received by both versions


in order to forward an argument, you need to do two things:
1) pass it as T&& arg
2) forward it using std::forward<T>(arg)

in order to forward a parameter pack, you need to do the same:
1) pass them as T&&...args
2) forward as std::forward<T>(args)...

anything else is not forwarding

see complete examples at http://en.cppreference.com/w/cpp/utility/forward
Topic archived. No new replies allowed.