
C++
最后冰吻free
不在沉默中死亡,就在沉默中爆发
展开
-
C++封装mutex condtion sem
【代码】C++封装mutex condtion sem。原创 2023-06-04 22:50:01 · 128 阅读 · 0 评论 -
c++ noexcept
【代码】c++ noexcept。原创 2023-03-29 19:14:11 · 141 阅读 · 0 评论 -
C++ 新特性mutex封装
【代码】C++ 新特性mutex封装。原创 2023-03-21 16:21:48 · 227 阅读 · 0 评论 -
c++ 问题集锦
c++常见问题集锦,用于以后重复性问题快速解决原创 2022-12-15 18:28:54 · 274 阅读 · 0 评论 -
模板类型萃取
使用模板偏特化进行类型萃取,使用萃取类型进行一些属性的重新定义,也可以使用标准std::iterator_traits::value_type获取值类型原创 2022-12-14 23:07:38 · 158 阅读 · 0 评论 -
静态多态校验接口
函数模板,实现静态多态,但有时与接口绑定对象的接口并不符合,需要进行校验或过滤,就需要用到concepts原创 2022-12-01 10:52:46 · 117 阅读 · 0 评论 -
智能指针作为模板参数并校验是否子类
有些场景智能指针作为模板参数,并判断所管理的对象类型是否为某个类的子类原创 2022-11-30 10:52:42 · 322 阅读 · 0 评论 -
c++ 生成dll并引用
解决dll生成和引用问题原创 2022-09-01 20:34:47 · 1254 阅读 · 0 评论 -
C++ 校验指针&引用类型
根据类模板校验传入类型是否文件指针、引用类型原创 2022-07-21 18:01:03 · 471 阅读 · 0 评论 -
C++ 校验类型是否相互转换
使用模板类实现,模板参数类型是否可以进行转换原创 2022-07-19 20:39:26 · 351 阅读 · 0 评论 -
C++ int2Type&type2Type
int2Type, type2Type原创 2022-07-19 19:45:33 · 425 阅读 · 0 评论 -
enable_if和偏特化
enable_if原创 2022-07-18 16:25:19 · 244 阅读 · 0 评论 -
C++ 函数偏特化
函数偏特化不支持,全特化可以原创 2022-07-18 10:52:30 · 431 阅读 · 0 评论 -
C++ 校验是否是堆区
校验是否是堆区原创 2022-07-03 12:36:39 · 314 阅读 · 0 评论 -
C++ 类对象只在heap中
私有析构原创 2022-07-02 15:37:44 · 329 阅读 · 0 评论 -
C++ 预定义属性[[noreturn]]
[[noreturn]]原创 2022-06-25 23:49:51 · 1593 阅读 · 0 评论 -
C++ map自定义类型遍历查询
find_if原创 2022-06-18 23:41:43 · 547 阅读 · 0 评论 -
C++ nolhmann/json
诺依曼json原创 2022-06-08 23:34:30 · 723 阅读 · 0 评论 -
C++ 抽象类
#include <iostream>class AbstractBase{public: explicit AbstractBase(int b): b_(b){} virtual int GetMember()=0; int b_;};class Derived: public AbstractBase{public: explicit Derived(int d, int b): AbstractBase(b), d_(d){} int原创 2022-05-27 22:14:06 · 117 阅读 · 0 评论 -
C++ 前置和后置
#include <iostream>// 重载前置和后置操作符class UInt{public: UInt():m_id(0) {} friend std::ostream& operator<<(std::ostream& cout, const UInt &it); // 前置自增 UInt& operator++() { std::cout<<"prefix++"<&l原创 2022-05-01 22:50:17 · 1281 阅读 · 0 评论 -
C++ 四大类型转换操作符
#include <iostream>#include <vector>/** 转型操作符static_cast, const_cast,dynamic_cast,reinterpret_cast*/// static_castvoid Test1(){ // C语言转型:(type)expression; double a = 10.5; int b = 20; int c = (int)a; double d = (原创 2022-04-23 22:53:05 · 1063 阅读 · 0 评论 -
C++ pointer&reference
#include <iostream>#include <vector>/** pointer与reference区别: 引用必须被初始化,初始化后不被改动,pointer没有这个要求, 可以初始化(初始化后可以被改动),也可以不初始化(但存在风险) 指针一般用于指向某个对象后,可以修改它指向另一个对象。而指向某一个对象后不再改变其指向 其它对象,则应该使用引用*/void Test1(){ int a = 10原创 2022-04-21 22:29:24 · 1097 阅读 · 0 评论 -
C++ Jsoncpp
#include <json/json.h>#include <iostream>// create Json::value and serial to stringvoid Test(){ Json::Value root; root.append("tom"); root.append("jerry"); root.append(true); root.append(20); Json::Value subArray;原创 2022-04-13 22:59:50 · 1211 阅读 · 1 评论 -
C++新特性initializer_list
#include <iostream>#include <vector>/* std::initializer_list轻量级模板类型可以进行任意相同类型的长度的数据初始化 size: 获取列表参数个数 begin/end:容器元素迭代操作*/// 用于普通函数void Func(std::initializer_list<int> ls){ std::cout << "size:" << ls.size原创 2022-04-09 21:32:45 · 926 阅读 · 0 评论 -
C++ 新特性委托构造和继承构造
#include <iostream>/** 委托构造函数作用时调用其他构造函数进行初始化,优点是优化代码,看起来精简 * 在初始化列表中调用构造函数,函数体中调用构造函数会报参数重复定义问题 */struct Test{ Test(){}; Test(int max) { this->m_max = max; } Test(int max, int min) : Test(max) { thi原创 2022-04-07 23:00:23 · 1047 阅读 · 0 评论 -
C++ 新特性using
#include <iostream>/*typedef 像声明一个变量一样,声明一个重定义类型,之后在声明之前加上 typedef 即可这种写法凸显了 C/C++ 中的语法一致性*/template <typename T>struct STFunc{ typedef T(*type)(T, T);};int add(int l, int r) { return (l)+(r);}double add(double l, dou原创 2022-03-05 23:34:08 · 465 阅读 · 0 评论 -
C++ std::move
#include <iostream>using namespace std;/* 右值引用只能指向右值,但想指向左值,则可以通过std::move函数将左值转换为右值(调用左值的移动构造函数),std::forward也可以*/class movedemo{public: movedemo():num(new int(0)){ cout<<"construct!"<<endl; } //拷贝构造函数 moved原创 2022-03-04 10:06:13 · 545 阅读 · 0 评论 -
C++ 左值右值及引用
万能引用原创 2022-03-03 14:22:12 · 68 阅读 · 0 评论 -
C++调用子类函数
#include <iostream>class Base{public: // 在父类方法中调用重写函数,若子类实现父类的方法,则会调用子类方法 void DoSomeThing() { SameFunc(); } virtual void SameFunc() { std::cout << "parent" << std::endl; }};class Devied : .原创 2022-03-02 18:53:31 · 2841 阅读 · 0 评论 -
C++ source_location
#include <iostream>#include <string_view>#include <source_location>/* 若想查看源代码对应的信息,之前都是使用log类,或宏__FILE__, __LINE__等,C++20中新增source_location类,可以更友好的展示文件名称、行号、列号、函数名称*/void log(const std::string_view message, const std::sour原创 2021-12-23 22:19:15 · 1217 阅读 · 0 评论 -
C++ enable_if
// enable_if example: two ways of using enable_if#include <iostream>#include <type_traits>// 1. 如果T是一个整数类型,则返回值类型为bool是有效类型:template <class T>typename std::enable_if<std::is_integral<T>::value, bool>::typeis_odd(T i) {原创 2021-12-06 22:24:10 · 401 阅读 · 0 评论 -
vscode C++ debug
// launch.json{ "version": "0.2.0", "configurations": [ { "name": "g++.exe - Build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",原创 2021-11-13 22:55:56 · 1294 阅读 · 0 评论 -
C++ 浮点数与0比较
#include <iostream>#include <type_traits>#include <limits>template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type>bool IsEqualZero(T value){ if (value > -std::numeric原创 2021-09-23 10:15:32 · 776 阅读 · 0 评论 -
C++ 新特性noexcept
/*noexcept关键字主要用于对一个函数做出不抛出异常的说明,不抛出异常可以优化函数代码在函数声明或定义后面加上noexcept或noexcept(false)(参数为false代表可以抛异常,否则反之)*/#include <iostream>struct Throw_0_Exception{ std::string what(){ return "The divisible cannot be 0"; }};template <type原创 2021-09-19 23:19:22 · 444 阅读 · 0 评论 -
C++新特性unordered_map和tuple
#include <iostream>#include <map>#include <unordered_map>#include <tuple>void test1(){ /* map、mutimap都是安装key进行排序的容器,内部实现是红黑树 插入和搜索的时间复杂度是O(log(size)),区别是map中key不可重复 */ std::map<int, std::string> map1原创 2021-09-16 23:28:27 · 663 阅读 · 0 评论 -
C++新特性array
#include <iostream>#include <vector> // std::vector#include <array> // std::array#include <algorithm> //std::sortvoid test1(){ /* vector容器会自动扩张,当size操过3/4 * capacity容量后,会新申请2倍 容量内存空间,将原空间元素拷贝到新空间中,并clea原创 2021-09-16 23:03:28 · 119 阅读 · 0 评论 -
C++新特性function
#include <iostream>#include <functional>/*std::function 是一种通用、多态的函数封装,它的实例可以对任何可以调用的目标实体进行存储、复制和调用操作换句话说,就是函数的容器,有了函数的容器就可以更方便的将函数、函数指针作为对象进行处理*/typedef std::function<int(int,int)> addPtr;int add(int a, int b){ return (a)+(b原创 2021-09-15 23:02:36 · 150 阅读 · 0 评论 -
C++新特性lambda
#include <iostream>#include <memory> // std::make_unique#include <utility> // std::move/*lambda:[捕获列表](参数列表) mutable(可选) 异常属性 -> 返回类型 {// 函数体}捕获列表:[] 代表空捕获列表 [name_var1, name_var2, ...] 捕获指定变量(值捕获),函数体中可以读取(值拷贝)原创 2021-09-13 22:57:51 · 142 阅读 · 0 评论 -
C++新特性overrid final default delete
#include <iostream>class Base{public: virtual void do_something() { std::cout<<"Person"<<std::endl; } virtual void print_self() final { std::cout<<"Person"<<std::endl; }};class Su原创 2021-09-12 23:15:43 · 137 阅读 · 0 评论 -
C++新特性委托和继承构造
#include <iostream>struct Person{ Person() { m_id = 1; } Person(int id, int age):m_id(id), m_age(age){} Person(int age):Person()// 委托Person()构造函数,运行同一个类中一个构造函数调用另一构造函数 { m_age = age; } int m_id;原创 2021-09-12 22:00:46 · 137 阅读 · 0 评论