How do I pass a template as a template parameter to a template?

后端 未结 2 472
说谎
说谎 2021-02-05 08:34

I\'m trying to write something like:

          // I don\'t know how this particular syntax should look...
template Functo         


        
2条回答
  •  爱一瞬间的悲伤
    2021-02-05 09:00

    This is just a "template template argument". The syntax is very close to what you imagined. Here it is:

    template< template class FunctorT>
    Something MergeSomething(const Something& lhs, const Something& rhs)
    {
        Something result(lhs);
        if (lhs.IsUnsigned() && rhs.IsUnsigned())
        {
            result.SetUnsigned(FunctorT()(lhs.UnsignedValue(), rhs.UnsignedValue()));
        }
        else
        {
            result.SetSigned(FunctorT<__int64>()(lhs.SignedValue(), rhs.SignedValue()));
        }
        return result;
    }
    

    Your use-case should work like you posted it.

提交回复
热议问题