惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Palo Alto Networks Blog
D
Docker
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Schneier on Security
Engineering at Meta
Engineering at Meta
I
InfoQ
L
LangChain Blog
Cyberwarzone
Cyberwarzone
T
Tenable Blog
WordPress大学
WordPress大学
P
Privacy & Cybersecurity Law Blog
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Jina AI
Jina AI
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
Know Your Adversary
Know Your Adversary
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Last Watchdog
The Last Watchdog
Last Week in AI
Last Week in AI
Cloudbric
Cloudbric
S
SegmentFault 最新的问题
爱范儿
爱范儿
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
AI
AI
T
Tor Project blog
I
Intezer
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
N
News and Events Feed by Topic
Latest news
Latest news
S
Security Affairs
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog RSS Feed
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
S
Securelist

Jia Yue Hua

完美转发不完美 闲散颂 adapting c++20 ranges algorithms for most metaprogramming Reproducible github Developer Environments 使用mpmcpipeline和jthread实现软流水 在其它线程周期回调函数 在当前线程周期回调函数 for_each cpo和tag_invoke
transparent,为关联容器增加查找成员
Jia Yue Hua · 2023-05-18 · via Jia Yue Hua

folly::transparent 模板类可以用比较器实例化,从而支持异型查找:

#include <set>
struct S {
  template<class T, class U>
  bool operator()(T& a, U& b) const { return a < b; }
};
struct Man {
  int id_;
  auto operator<=>(const Man&) const = default;
};
struct ManComp {
  bool operator()(const Man &l,const int& r)const
  {
    return l.id_ < r;
  }
  bool operator()(const int& l, const Man& r)const
  {
    return l < r.id_;
  }
  bool operator()(const Man& l, const Man& r)const
  {
    return l.id_ < r.id_;
  }
};
void f() {
  std::set<Man,ManComp> m;
  m.find(11);//将报错
}
void g()
{
std::set<Man,folly::transparent<ManComp>> m;
  m.find(11);
}

上述f()中的m.find(11)将报错,因为find的参数只能接受Man类型,而int类型并不能隐式转化为Man,而g()将成功,因为比较器为folly::transparent一个实例,m.find()的查找重载成员将增加一成员模板函数,理论上模板函数的参数只要能和Key也就是Man比较就可。故而使用folly::transparent后成功.

Posted 2023-05-18