tinystl实现(第二步:TypeTraits.h)

2023-11-03

经过长时间的学习终于可以开始tinystl的仿(chao)写工作了,本文参考了这位大佬的github,坦白讲我只是补充了注释,因为tinystl的代码真的非常经典而我又没什么这种大型项目的经验,所以只能这样做,不过相信能够有助于大家的学习
TypeTraits.h文件其实应该是最基础的部分,这部分完成了很多以后要用到的东西的定义,理解比较困难,可以先不理解,以后回头就会发现这些设置有何用处
阅读本文你需要:
了解SFINAE:通过这篇文章了解
了解类型萃取:通过这篇文章
了解何为pod类型:通过这篇文章

#pragma once
#ifndef  _TYPE_TRAITS_H_
#define _TYPE_TRAITS_H_
namespace mySTL {
	namespace {
		template<bool, class  Ta,class Tb>
		struct IfThenElse;
		template<class Ta,class Tb>
		struct IfThenElse<true, Ta, Tb>
		{
			using result = Ta;
		};
		template<class Ta, class Tb>
		struct IfThenElse<false, Ta, Tb>
		{
			using result = Tb;
		};
	}//对namespace的定义
}
struct _true_type{};
struct _false_type{};
//萃取传入的T类型的类型特性
template<class T>
struct _type_traits
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<bool>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<char>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<unsigned char>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<signed char>//在32位系统中一个char类型一般为8个bit,所以能存储的数据范围为-128~127,而unsigned char则是0~255,存储范围相同
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<wchar_t>//wchar_t的表示范围远远大于char
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<short>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<unsigned short>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<int>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<unsigned int>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<long>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<unsigned long>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<long long>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<unsigned long long>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<double>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits< long double>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<class T>
struct _type_traits< T*>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<class T>
struct _type_traits<const T*>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits< char *>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<const char *>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<const unsigned char *>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
template<>
struct _type_traits<const signed char *>
{
	typedef _false_type has_trivial_default_constructor;
	typedef _false_type has_trivial_copy_constructor;
	typedef _false_type has_trivial_assaignment_operator;
	typedef _false_type has_trivial_destructor;
	typedef _false_type is_POD_type;
};
#endif // ! _TYPE_TRAITS_H_
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

tinystl实现(第二步:TypeTraits.h) 的相关文章

随机推荐

  • 【UE4】Replay游戏回放 for UE4.26

    前言 UE4 26的回放教程 最近有用到 So梳理了整个构建流程 希望能帮到你 结尾有视频版教程 时长较长 1 准备工作 创建一个UE4C 项目 添加第一人称和第三人称功能包 关闭引擎 找到项目目录 ContentDir Config De
  • 【windows系统同时安装配置不同版本java环境】,以及双击jar包问题总结

    1 下载jdk 官方网站 Java Downloads Oraclehttps www oracle com java technologies downloads我这边需要运行冰蝎是需要一个java8的环境 以及原有的高版本的java环境
  • JS 函数

    JS 函数 关键字形式的函数
  • Mysql 中级篇-索引

    123
  • C++ 基本的7种数据类型和4种类型转换(C++复习向p3)

    文章目录 基本内置类型 存储范围 typedef 声明新名字 enum 枚举类型 类型转换 基本内置类型 bool char int float double void wchar t short int 存储范围 可以这样 sizeof
  • 全卷积网络(FCN)与图像分割

    从图像分类到图像分割 卷积神经网络 CNN 自2012年以来 在图像分类和图像检测等方面取得了巨大的成就和广泛的应用 CNN的强大之处在于它的多层结构能自动学习特征 并且可以学习到多个层次的特征 较浅的卷积层感知域较小 学习到一些局部区域的
  • CentOs7 修复 引导启动

    一 修复MBR MBR Master Boot Record主引导记录 硬盘的0柱面 0磁头 1扇区称为主引导扇区 其中446Byte是bootloader 64Byte为Partition table 剩下的2Byte为magic num
  • 配置hadoop各个节点之间免密码登录实践笔记

    前言 最近在搭建Hadoop环境需要设置无密码登陆 所谓无密码登陆其实是指通过证书认证的方式登陆 使用一种被称为 公私钥 认证的方式来进行ssh登录 在linux系统中 ssh是远程登录的默认工具 因为该工具的协议使用了RSA DSA的加密
  • 使用Python,OpenCV缩放照片(忽略宽高比,保持宽高比)

    使用Python OpenCV缩放照片 忽略宽高比 保持宽高比 1 效果图 1 1 保持宽高比效果图 1 2 忽略宽高比效果图 1 3 opencv各插值效果图 2 原理 3 源码 参考 这篇博客将介绍如何使用OpenCV调整图像大小 调整
  • EEPROM的学习和使用方法

    EEPROM的学习和使用方法 https blog csdn net bornpride article details 87894400 一 概述 在实际的应用中 保存在单片机RAM中的数据 掉电后就丢失了 保存在单片机的FLASH中的数
  • 使用 K-means 算法进行客户分类

    本文为 AI 研习社编译的技术博客 原标题 Customer segmentation using Machine Learning K Means Clustering 翻译 吕鑫灿 就2 校对 就2 整理 志豪 原文链接 http ww
  • 快上车!第十七届全国大学生智能汽车竞赛百度创意组来啦

    全国大学生智能汽车竞赛 是教育部倡导的大学生科技A类竞赛 是2021年全国普通高校大学生竞赛榜单内竞赛 中国高等教育学会将其列为含金量最高的大学生竞赛之一 在全国数百所高校的支持下 全国大学生智能汽车竞赛至今已成功举办了十六届 参赛学生总规
  • 安装pytorch_geometric

    前些时候了解了python下的 dgl库来进行图谱的计算 最近看到pytorch geometric 比dgl快很多 于是打起了pytorch geometric的主意 然而pytorch geometric 并没有dgl 安装这么方便 大
  • gcc与glibc关系

    gcc与glibc关系 glibc是什么 以及与gcc的关系 glibc是gnu发布的libc库 也即c运行库 glibc是linux 系统中最底层的api 应用程序开发接口 几乎其它任何的运行库都会倚赖于glibc glibc除了封装li
  • Git & GitHub入门3:修改文件后提交(modify, stage, commit)

    用atom 打开当前目录下的文件 修改这个文件 在其中加一行注释后保存 运行git add Practice BaiduBaike py 表示我们希望将保存修改后的Practice BaiduBaike py文件 现在我们可以使用git c
  • 毕业N年后,请不要像我一样被档案烦死——转自一位已经毕业的学姐

    转 转自一位已经毕业的学姐 今天在QQ空间里看见有一个毕业了很久的学姐写下了下面这段很干货的经历 加上现在大学生确实对毕业生档案问题不够重视和了解 也很迷茫 所以打算做个搬运工 把这种经历转发出来 提前知道毕业了之后档案到底会有什么影响 毕
  • HAProxy的安装及常用配置中文注释

    一 HAProxy的安装 1 Centos安装 yum install haproxy 2 Ubuntu 安装 apt get install haproxy 3 编译安装 1 安装前准备 yum install gcc gcc c gli
  • Linux TCP客户端、服务器编程模型及实例

    Linux TCP客户端 服务器编程模型及实例 服务器模型 1 绑定IPv4的地址 INADDR ANY 和端口号 8888 int listenfd sockfd opt 1 struct sockaddr in server clien
  • php根据类型重定向跳转

    核心代码 elseif REQUEST act print iftaochan next qid intval REQUEST custqid if empty qid sys msg 非法参数 row where row where cu
  • tinystl实现(第二步:TypeTraits.h)

    经过长时间的学习终于可以开始tinystl的仿 chao 写工作了 本文参考了这位大佬的github 坦白讲我只是补充了注释 因为tinystl的代码真的非常经典而我又没什么这种大型项目的经验 所以只能这样做 不过相信能够有助于大家的学习