Date: Sun, 8 Oct 2023 16:25:15 +0100
For quite a while now, a few people have been saying that we should
have simple shorthand for 'forward', for example the following:
template<typename T>
void Func(T &&arg)
{
SomeOtherFunc( forward<T>(arg) );
}
could be simplified to something like:
template<typename T>
void Func(T &&arg)
{
SomeOtherFunc( ^^arg );
}
Well today I thought of another reason why we should have this.
Consider the following lambda:
auto forwardingLambda = [](auto&& param) { f(std::forward<T>(param)); };
It doesn't compile because we don't have 'T'. In order to keep the
'auto' in there, we would need to write:
auto forwardingLambda = [](auto&& param) {
f(std::forward<std::conditional<std::is_rvalue_reference<decltype(param)>::value,
std::remove_reference<decltype(param)>::type,
decltype(param)>::type>(param));
};
Ain't nobody got time for that. It would be better if we could just do:
auto forwardingLambda = [](auto&& param) { f(^^param); };
have simple shorthand for 'forward', for example the following:
template<typename T>
void Func(T &&arg)
{
SomeOtherFunc( forward<T>(arg) );
}
could be simplified to something like:
template<typename T>
void Func(T &&arg)
{
SomeOtherFunc( ^^arg );
}
Well today I thought of another reason why we should have this.
Consider the following lambda:
auto forwardingLambda = [](auto&& param) { f(std::forward<T>(param)); };
It doesn't compile because we don't have 'T'. In order to keep the
'auto' in there, we would need to write:
auto forwardingLambda = [](auto&& param) {
f(std::forward<std::conditional<std::is_rvalue_reference<decltype(param)>::value,
std::remove_reference<decltype(param)>::type,
decltype(param)>::type>(param));
};
Ain't nobody got time for that. It would be better if we could just do:
auto forwardingLambda = [](auto&& param) { f(^^param); };
Received on 2023-10-08 15:25:28