为什么这个std::map键提取函数需要——std=c++
Why does this std::map keys extraction function need --std=c++?
我认为在没有为gcc(4.6)指定——std=c++0x标志的情况下,std::map键提取到std::vector应该可以工作,但是它没有。知道为什么吗?
template <typename Map, typename Container>
void extract_map_keys(const Map& m, Container& c) {
struct get_key {
typename Map::key_type operator()
(const typename Map::value_type& p) const {
return p.first;
}
};
transform(m.begin(), m.end(), back_inserter(c), get_key());
}
谢谢!
原因是您使用本地类型get_key
作为最后一个参数。这在c++ 98中是不允许的,并且在c++ 11中已经更改/放宽了规则。
template <class T> bool cpp0X(T) {return true;} //cannot be called with local types in C++03
bool cpp0X(...){return false;}
bool isCpp0x()
{
struct local {} var;
return cpp0X(var);
}
相关文章:
- 使用std::multimap迭代器创建std::list
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从持续时间构造std::chrono::system_clock::time_point
- std::具有相同基类的类的变体
- std::向量与传递值的动态数组
- 使用std::vector的OpenCL矩阵乘法
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- std::condition_variable::wait()如何评估给定的谓词
- 如何获取std::result_of函数的返回类型
- std::原子加载和存储都需要吗
- 将对象移动到std::shared_ptr
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 使用一个考虑到std::map中键值的滚动或换行的键
- 如何从 std::atomic 中提取指针 T<T>?
- 为什么 std::unique 不调用 std::sort?
- 使用std::函数映射对象方法
- 可组合的lambda/std::函数与std::可选