对于模板,我看到了两个声明:
template < typename T >
template < class T >
Run Code Online (Sandbox Code Playgroud)
有什么不同?
这些关键字在下面的例子中究竟是什么意思(取自德国维基百科关于模板的文章)?
template < template < typename, typename > class Container, typename Type >
class Example
{
Container< Type, std::allocator < Type > > baz;
};
Run Code Online (Sandbox Code Playgroud) 我正在研究一些具有高级接口的低级代码,并且需要比较运算符来进行普通旧数据类型(如FILETIME struct)的单元测试,但由于C++甚至不提供成员比较,所以我写了这样的:
template <typename Type>
std::enable_if_t<std::is_pod<Type>::value, bool> operator==(const Type& a,
const Type& b) {
return std::memcmp(&a, &b, sizeof(Type)) == 0;
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,这是一个好方法还是有一些隐藏的恶魔会让我在开发周期后期遇到麻烦,但它现在有点工作.