首页 > 解决方案 > 模板参数的类型无效

问题描述

我的模板有什么问题以及如何修复它?鉴于谓词功能,这应该从 Qt-ish 容器中删除所有项目。编译器产生错误'std::function': 'T::value_type' is not a valid template type argument for parameter '_Fty'

template <typename T>
void eraseIf( T &container, std::function<bool(T::value_type)> predicate)
{
    auto it = container.begin();
    while( it != container.end() )
    {
        if( predicate( *it ) )
        {
            it = container.erase( it );
        }
        else
        {
            ++it;
        }
    }
}

标签: c++c++11

解决方案


推荐阅读