I'm trying to write something like:
// I don't know how this particular syntax should look...
template<typename template<typename Ty> FunctorT>
Something MergeSomething(const Something& lhs, const Something& rhs)
{
Something result(lhs);
if (lhs.IsUnsigned() && rhs.IsUnsigned())
{
result.SetUnsigned(FunctorT<unsigned __int64>()(lhs.UnsignedValue(), rhs.UnsignedValue()));
}
else
{
result.SetSigned(FunctorT<__int64>()(lhs.SignedValue(), rhs.SignedValue()));
}
return result;
}
which would be used like:
Something a, b;
Something c = MergeSomething<std::plus>(a, b);
How do I do that?
This is just a "template template argument". The syntax is very close to what you imagined. Here it is:
template< template<typename Ty> class FunctorT>
Something MergeSomething(const Something& lhs, const Something& rhs)
{
Something result(lhs);
if (lhs.IsUnsigned() && rhs.IsUnsigned())
{
result.SetUnsigned(FunctorT<unsigned __int64>()(lhs.UnsignedValue(), rhs.UnsignedValue()));
}
else
{
result.SetSigned(FunctorT<__int64>()(lhs.SignedValue(), rhs.SignedValue()));
}
return result;
}
Your use-case should work like you posted it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With