当前位置:网站首页>Some applications of std:: bind and std:: function
Some applications of std:: bind and std:: function
2022-07-27 06:44:00 【Mr FF】
#include <functional>
#include <iostream>
#include <typeinfo>
#include <typeindex>
#include <unordered_map>
class Type {
};
class A {
public:
static A* instance = nullptr;
Type GetUint32Type()
{
Type type;
// your businsee
return type;
}
Type GetInt32Type()
{
Type type;
// your businsee
return type;
}
Type* GetInstance()
{
if (instance == nullptr) {
instance = new A();
}
return instance;
}
};
using CreateType = std::function<Type()>;
std::unordered_map<std::type_index, CreateType> g_typeTable =
{
{typeid(uint32_t), std::bind(&A::GetUint32Type, A::GetInstance())},
{typeid(int32_t), std::bind(&A::GetInt32Type, A::GetInstance())}
};
Application scenarios : Use typeid Method fetch type , Create corresponding packages according to different types .
Avoid a lot of if/else
边栏推荐
- About the use of TestNG related tags
- Constraints and design of database
- Vscode solves the problem of using stuck ipynb files when running
- About the problem that Druid can't connect to the database
- 2021-06-26
- 如何避免漏洞?向日葵远程为你讲解不同场景下的安全使用方法
- Summary of frequently asked questions in the interview [summarized after painstaking work all night]
- Solve the problems of CONDA install stop and interruption
- Common font and color settings of markdown documents
- Basic knowledge of English: juxtaposition structure
猜你喜欢

Shell script loop

QGIS series (1) -qgis (server APACHE) win10 installation

px4源码编译之 建立自己的程序模块

shell--变量的运算

网站服务器被攻击怎么办?向日葵提示防范漏洞是关键

LVM与磁盘配额

源码编译安装LAMP和DISCUZ论坛

Use of getattr, hasattr, delattr and setattr in reflectors

一键修复漏洞可行吗?向日葵来告诉你一键修复漏洞可行吗?向日葵来告诉你一键修复漏洞可行吗?向日葵来告诉你一键修复漏洞可行吗?向日葵来告诉你一键修复漏洞可行吗?向日葵来告诉你一键修复漏洞可行吗?向日葵来告

PXE高效批量网络装机
随机推荐
Establishment of FTP server
面试常问的问题总结【呕心沥血熬了一个晚上总结的】
Compatibility test knowledge points
项目实训经历2
自己动手实现容器
Packaging of logging logs
Shell script delete automatically clean up files that exceed the size
How to write yaml file in a standard way
iptables防火墙
LVM and disk quota
项目实训经历1
FTX US推出FTX Stocks,向主流金融行业迈进
DNS fault analysis optimization
Installation, configuration and use of gradle
keras-ocr实例测试
Use of getattr, hasattr, delattr and setattr in reflectors
Shell -- operation of variables
Vscode solves the problem of using stuck ipynb files when running
RAID详解与配置
备忘录 @RestControllerAdvice与异常拦截类示例