I'm not familiar with C++ language features ( updated almost every year). There is a piece of code shows something about template reference but with two & characters. For one, It mainly means the reference of the object, but two ?
Here the code:
Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(...);
template<typename TDelegateInterface, typename TLambda>
ComPtr<typename Details::DelegateArgTraitsHelper<TDelegateInterface>::Interface> Callback(TLambda&& callback) throw()
{
using DelegateHelper = Details::DelegateArgTraitsHelper<TDelegateInterface>;
return DelegateHelper::Traits::Callback<TDelegateInterface, DelegateHelper::Interface>(Details::Forward<TLambda>(callback));
}
template<class T>
struct Identity
{
typedef T Type;
};
template<class T>
inline T&& Forward(typename Identity<T>::Type& arg) throw()
{
return (T&&)arg;
}
inline T&& Forward(typename Identity<T>::Type& arg) throw()
{
return (T&&)arg;
}
It sounds like a template function , to me. But the return result ,
(T&&)arg .
What does it mean? What the exactly difference between one & and two & ?
What I have tried:
Sorry, nothing tried yet. This is some code from a tutorial about how to write webview2 with win32.
Callback should be a template function with an function parameter. The caller passed an anonymous function which is a lambda function(I use ... refer).
Forward seems like to make an explicit convert of the function reference, but why two &?
what is the difference with C callback function pointer?
Can this code be written by C callback function pointer style?