Question

Consider the code

template <typename... Args>
void foo (Args&& ...)
{
}

template <typename... Args>
void bar (Args&& ... args)
{
   foo (std::forward (args)...);
}

int main ()
{
  bar (true);
}
~                   

gcc 4.7.2 gives the error

error: no matching function for call to ‘forward(bool&)’
note: candidates are:

template<class _Tp> constexpr _Tp&& std::forward(typename std::remove_reference<_Tp>::type&)
note:   template argument deduction/substitution failed:

note: template<class _Tp> constexpr _Tp&& std::forward(typename std::remove_reference<_Tp>::type&&)
note:   template argument deduction/substitution failed:

Why isn't a literal deduced as an rvalue?

Was it helpful?

Solution

You don't use std::forward() correctly: you need to give the deduced type as an argument to std::forward():

foo (std::forward<Args>(args)...);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top