c++类型推导

c++类型推导
  • C++14中,你可以使用std::is_same<T, std::string>::value来检查类型:std::is_same<T, std::string>::value是一个常量,用于检查类型T是否string类型一致
  • 然后在C++17中,你需要使用std::is_same_v<T, std::string>来检查类型;std::is_same_v<T, std::string>是一个宏,它会返回一个布尔值,表示类型T是否与std::string类型相同
  • std::enable_if<std::is_same<T, Json::Value>::value, bool>::type是一个模板类型,它会根据类型T是否与Json::Value类型相同来返回一个bool类型。
  • std::is_same_v的返回值是布尔值,而std::enable_if的返回值是一个模板类型。
  • std::is_same_v主要用于类型检查,而std::enable_if主要用于根据条件返回不同的类型。
class Config
{
   
	friend class Singleton<Config>;
public:
	Config(){
   }
	~Config(){
   }
	
	bool ReadConfig(const std::string config_path)
	{
   
		std::cout << config_path  << "---" << config_path.empty() << std::endl;
		if (config_path.empty())
		{
   
			std::cout << "congfig file does not exist." << std::endl;
			return false;
		}
		std::ifstream input(config_path);
		input >> config_info_;
		input.close();
		return true;
	}
#if 1
	// c++14 
	template<typename T>
	typename std::enable_if<std::is_same<T, int>::value, bool>::type
	GetConfig(std::string key_str, T& value)
	{
   
        bool ret = false;
		if 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值