template-specialization

    2热度

    2回答

    我需要为散列表提供插入/查找/删除接口。我只写了散列表来提供内部存储桶/入口管理。散列函数应该从外部提供。我现在坚持如何公开接口,以便哈希表可以处理字节数组以及固定长度的数据类型。问题在于,对于字节数组,哈希函数需要知道数组的长度,而对于其他类型,它可以没有这些信息。我的问题是我不能为字节数组实现operator[],因为散列函数需要两个参数。我想保持operator[]。有没有什么办法解决这个问

    1热度

    2回答

    模板函数匹配不明原因的变化我有一个包含一个模板函数下面的代码。当我使用枚举的第二个参数调用此函数时:在某些情况下,它会查找模板特化,并且在某些情况下它不会。 我已经验证了枚举在两种情况下都是相同的枚举(例如没有重定义)并且其他参数具有正确的值,我发现一个编译是使用-Winline集合完成的(我没有尝试更改它)还有什么要看? class A { public: template <typ

    4热度

    1回答

    这是家庭作业,虽然它已经提交了不同的方法。 我越来越从Visual Studio以下2008 error C2893: Failed to specialize function template 'void std::sort(_RanIt,_RanIt,_Pr)' 的代码如下 main.cpp Database<> db; db.loadDatabase();

    0热度

    1回答

    我很难得到接受常规c风格字符串的模板专业化的正确语法。例如 namespace RubyUtils { template<class T> VALUE toValue(const T& v); }; template<> VALUE toValue(char const* & v) { return toValue<string>(v); } ,然后在调用点 r

    11热度

    3回答

    专业函数模板为什么这code的输出: #include <iostream> template<typename T> void f(T param) { std::cout << "General" << std::endl ; } template<> void f(int& param) { std::cout << "int&" << std::endl ;

    3热度

    2回答

    总类专业化可以说我有一个模板类 template <typename T> struct Widget { //generalized implementation } 但我想完全专注.. 为接受的一个参数模板? template <> struct Widget< TemplateThatAcceptsParameter<N> > { //implementa

    1热度

    2回答

    我得到一个令人沮丧的编译器错误,我似乎无法解决。这是与模板专门做的,但我看不出有什么不对...... ../../include/thread/lock_guard.inl:23: error: template-id 'lock_guard<>' for 'thread::lock_guard<thread::null_mutex>::lock_guard(thread::null_mutex&

    2热度

    2回答

    我有一个模板功能,我希望在不同的地方为不同类型的模板化。 问题是,我想知道在编译时是否有专门的给定类型以两种不同的方式生成另一个模板。 template<typename T> bool tobool(const T&){ throw Exception("Can't cast to bool");}; template<> bool tobool<bool>(const bool &valu

    2热度

    3回答

    我有一个串行类是这样的: class Serializer { public: // Func 1 (default) template <class T> void Serialize(T* pValue) { SerializeInternal(reinterpret_cast<char*>(pValue), sizeof(*pValue

    3热度

    4回答

    我目前正在重构一些代码,明确地专门化了具有两个模板参数的类模板的成员函数。 template <class S, class T> class Foo { void bar(); }; template <class S, class T> void Foo<S, T>::bar() { /* Generic stuff */ } template <> void F