C++
Salted_Sun
这个作者很懒,什么都没留下…
展开
-
【C++】随手记录
降序排序std::sort( XX.rbegin() , XX.rend() ) ;创建反转字符串std::string(s.rbegin() , s.rend() ) ;字符串转 unsigned long long (uint64)std::stoull(str) -> ullstd::map 可实现简单的switch … case 功能eg: 实现简单的二元加减乘除std::map<char, std::function<int(int , int)> &g原创 2022-01-31 21:11:44 · 580 阅读 · 0 评论 -
【C++】尝试实现 `is_constructible`
目前的测试用例都通过了,但可能还有行为和 std::is_constructible 不一致#include <cstdint>#include <type_traits>template<class T>struct is_reference : std::is_same<T,std::remove_reference_t<T> > {};template<class T>inline constexpr bool i原创 2022-05-10 11:23:59 · 726 阅读 · 0 评论 -
【C++】模板元编程 学习笔记
利用模板推导来判断类型是否为整数?首先用一个非特化的模板来标记非数字的情形.template<typename T>struct st_integer{ static const bool value = false ;};下面用各种整数类型来(完全) 特化模板st_integer , 并增加类型字段来记录具体的整数类型:template<>struct st_integer<int> { static const bool value = true原创 2022-03-29 22:28:26 · 850 阅读 · 0 评论 -
【C++】模板 备忘
类型退化 std::decaytemplate<class T>struct decay;若T是 类型U的**数组** / 对类型U的**数组的引用**, 则退化后的类型为U*若T为一个函数类型F/对函数的引用, 则退化后的类型为std::add_pointer<F>::type否则, 对其余所有类型, 其退化后的类型为 std::remove_cv<std::remove_reference<T>::type>::type因此粗略来讲, d原创 2022-03-25 21:28:34 · 1067 阅读 · 0 评论 -
【C++】十六进制显示文件内容
#include <iostream>#include <string>#include <iomanip>#include <fstream> #include <cctype>#include <cstdlib>int main(int argc ,char* argv[] ){ if(argc<2){ std::cerr << "usage: " << ...原创 2021-12-09 08:44:21 · 1278 阅读 · 1 评论 -
【C++】函数容器实现
#include <iostream>#include <thread>#include <map>#include <functional>#include <stdlib.h>#include <tuple>#include <type_traits>//// https://github.com/qicosmos/cosmos/blob/master/function_traits.hpp// ht原创 2021-11-25 11:57:18 · 687 阅读 · 0 评论 -
RTTI 运行时类型识别
安全的类型转换 dynamic_cast<子类*> (父类指针)#include <iostream>//RTTIclass Human{public : Human(){} virtual ~Human(){} //为了使用dynamic_cast将父类指针转换为子类,父类中至少有一个为虚函数,通常是虚析构函数 void func() { std::cout << "parent class!"<<std::e原创 2021-11-20 17:14:04 · 186 阅读 · 0 评论 -
定义C++迭代器
定义C++迭代器所有的STL容器都定义了:该容器的迭代器类型,如:iterator、const_iterator该容器的begin() end() 方法没有定义上面两种的容器被看做二等公民,他们不能和泛型算法一起使用,为你的容器定义迭代器类型和begin、end方法,无论他们是否是泛型容器来自被嵌套的STL容器的迭代器若你的容器中使用了STL容器作为内部数据成员,那么只需要将迭代器和两个方法的实现托付给STL容器即可。例如,假如你有一个类CourseList,它表示学生参加的课程的列表,在原创 2021-10-17 20:15:48 · 2249 阅读 · 0 评论 -
面向对象C++
1#include <iostream>/*面向过程:将问题解决转化为函数1 将问题分解成几个部分2 设计数据结构保存数据3 实现函数来操作这些数据结构其中的核心在于数据结构,它在整个进程执行过程中不断改变。*///例子:银行账户:typedef unsigned long AccountNum;//对外的操作接口bool makeDesposit(AccountNum whichAccount, float amount);float withDraw(Acc原创 2021-10-07 10:19:08 · 280 阅读 · 0 评论 -
C++杂记
数组#include <iostream>int main() { int a[5]; //在当前栈帧上为其分配内存 int* b = new int[5]; //在堆中为其分配空间 //数组的大小最好用一变量手工记录,而不是用sizeof(a)/sizeof(int) 因为这种方式有可能出错 delete[] b; // 释放堆中的数组空间 exit(0);}/*C++中的可见性只有三个级别:private 只有该类与其友元类可以访问原创 2021-10-07 10:03:20 · 94 阅读 · 0 评论