如何创建一个适配器,该适配器将使用键的谓词根据筛选的键返回映射值
how to create an adaptor that will return map values based on filtered key using a predicate for key
如何创建一个适配器,使用键的谓词根据过滤后的键返回映射值?
例如:
std::map<int,int> map_obj;
const int match_value = 0xFF00;
for(auto& i : map_obj | filtered_key_map_values([match_value](key_type& x){ return (x & match_value) > 0; } | indirected )
{
std::copy<typeof(i)>(std::cout," ,");
}
我建议使用Live On Coliru
#define BOOST_RESULT_OF_USE_DECLTYPE
#include <boost/range/adaptors.hpp>
using namespace boost::adaptors;
#include <iostream>
int main()
{
std::map<int, std::string> const map_obj {
{ 0x0001, "one" },
{ 0x0002, "two" },
{ 0x0003, "three" },
{ 0x0404, "four" },
{ 0x0005, "five" },
};
const int match_value = 0xFF00;
for(auto& v : map_obj
| filtered([=](std::pair<const int, std::string> const& p)->bool { return (p.first & match_value) != 0; })
| map_values)
{
std::cout << v << "n";
}
}
相关文章:
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 为什么 STL 容器适配器堆栈中的 top 返回常量引用?
- 创建包装升压适配器的自定义范围类
- 在 C++20 中将多个范围适配器连接到一个范围中
- 递归应用 C++20 范围适配器会导致编译时无限循环
- Lambda 到函数指针适配器的理解
- 返回迭代器以提升适配器转换的容器
- 将 Kleene 运算符解析为一组替代方案,适配器? 与精神 x3
- Boost Range适配器制作集合
- 升压范围适配器
- DXGI 集成适配器
- 克隆设计模式适配器 - 避免切片子项(类似于原型模式)
- 为什么不支持容器适配器中元素的初始化和迭代
- C++ 提升范围:any_range和转换适配器
- 用于隐藏结构细节的迭代器适配器
- 如何在 DirectX 11 应用程序中提供选择图形适配器的选项?
- 适配器模式:支持可以是const或非const的基础数据,优雅
- 如何对VC 17/20的分配适配器现代化
- 对象适配器的类适配器
- 如何创建一个适配器,该适配器将使用键的谓词根据筛选的键返回映射值