在模板化数据结构上调用 begin() 或 end()



我正在尝试使用remove_if STL函数,并且正在传入映射,unordered_map或向量。所有这些都带有返回迭代器的函数.begin().end()。编译器不允许我在模板化变量上调用函数

我尝试使用.begin().end()以及begin()end()

template<typename FUNCTOR, typename datastructure>
void deleteFromHelper(FUNCTOR func, datastructure table)
{
    std::remove_if(table.begin(), table.end(), func);
}

其中 table 是unorded_map、映射或向量。 和 func 是一个自定义函子

编译器说: Error C2228 left of '.begin' must have class/struct/union

看起来像一个 MSVC 错误,gcc 对此非常满意,请参阅:

https://wandbox.org/permlink/KuzZrEriPQerBoou

但是,如果像我的示例那样使用模板推导,您是否指定了/std:c++17?(我认为这在 MSVC 中可能仍然不完整(。

最新更新