不接受将unordered_map <K,V> :: value_type作为参数类型的std :: function

时间:2020-05-14 14:21:20

标签: c++ std-function

我正在练习C ++技能,并试图模仿C ++ unordered_map的C#IEnumerable.Where扩展名时遇到了我无法理解的错误。

我使用的是我从另一个StackOverflow帖子中获得的示例,该示例实现了一个尽可能优雅的扩展方法。它没有使用->来调用函数,而是使用了<-,这可能会造成混淆,但是我比使用两个参数的静态方法更好。 链接为here

所以我的实现是这样:

template<class K, class V>
class Where2 {
    std::function<bool(std::unordered_map<K, V>::value_type)> m_Predicate;
public:

    Where2(std::function<bool(std::unordered_map<K, V>::value_type)> i_Predicate) : m_Predicate(i_Predicate) {}

    Where2<K, V>& operator-(void) {
        return *this;
    }

    friend std::unordered_map<K, V> operator< (const std::unordered_map<K, V>& i_Obj, const Where2<K, V>& i_Ext) {
        std::unordered_map<K, V> result;
        std::copy_if(i_Obj.begin(), i_Obj.end(), std::inserter(result, result.end()), i_Ext.m_Predicate);
        return result;
    }
};

我得到的错误是: 错误C2974:“ std :: function”:“ _ Fty”的模板参数无效,请键入

有什么建议吗?

0 个答案:

没有答案
相关问题