随笔分类 - C/CPP
摘要:Let's address your three questions one by one with a hardware-oriented, low-level perspective: 1️⃣ Pointer dereference overhead vs direct member acces
阅读全文
摘要:libcxx/include/__memory/pointer_traits.h中有两个常用的指针类型转换的模板 rebind_pointer 接受两个模板参数 From和To,将From类型的指针转换为To类型的指针 __rebind_pointer<From,To>::type pointer_
阅读全文
摘要:来看allocator定义,首先是两个void特化版本 // include/__memory/allocator.h template <class _Tp> class allocator; #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_
阅读全文
摘要:模板偏特化对参数列表的要求 cpp官方文档会搞混parameter list和argument list的区别,因此不要只看文字描述 模板偏特化的声明方式 1.argument list不能和主模板的argument list相同 对于下面这份声明,argument list即syntax中的部分
阅读全文
摘要:通过阅读libcxx源码,学习stl实现方式,以及高级cpp技巧. 这是第一篇 目录红黑树背景知识1. 二叉搜索树(BST)2. AVL 树3. 红黑树4. 三者对比小结5. 在脑海中的映射6. zig-zig / zig-zaglibcxx源码cpp学习rbtree具体操作的代码 红黑树背景知识
阅读全文
摘要:```cpp #include #include #include #include using namespace std; struct B { int v = 100; ~B() { v = 0; } }; struct A { A(B* p) { aa = p; } B* aa = null
阅读全文
摘要:EXAMPLE ONE template <typename T, T b, uint32_t e> struct pow : std::integral_constant<decltype(b * 1), b * pow<T, b, e - 1>::value> {}; template <typ
阅读全文
摘要:
阅读全文
摘要: 
阅读全文
摘要:静态变量a地址的高20位加载到a5中, a5的值(static a的高20位地址) + 偏移值(static a的低12位地址) -> 加载到a5中(现在a5中保存了静态变量a的32位地址) 把静态变量a的地址写入到返回值中。 如果声明为返回类型为&,实际也一样 如果使用返回void的方式来实现静态
阅读全文
摘要:https://en.cppreference.com/w/cpp/language/copy_initialization.html /* ASM generation compiler returned: 0 Execution build compiler returned: 0 Progra
阅读全文
摘要:
阅读全文
摘要:#include <iostream> #include <iomanip> #include <type_traits> class A {}; enum E : int {}; template <class T> T f(T i) { static_assert(std::is_integra
阅读全文
摘要:这里用一个lambda来作为shared ptr的删除器,lambda没有做任何操作,保证这份数据的内存管理不受这个sharedptr影响。 编译器报错:static assertion failed due to requirement ***deleter expression is well-
阅读全文
摘要:/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger t
阅读全文
摘要:只是将p指针的操作改为store byte,即reinterpret之后的操作指令
阅读全文
摘要:ref : https://github.com/wuye9036/CppTemplateTutorial#323-%E7%89%B9%E5%8C%96%E4%B8%80%E4%BA%9B%E5%85%B6%E5%AE%83%E9%97%AE%E9%A2%98 这段就是说: 这个int实参在替换第一
阅读全文
摘要:模板中的行参类型推断会省略引用 在这两种模板中,行参的引用都会在推断过程中被省略 template<typename T> //template A void f(T ¶m); template<typename T> // template B void f(T param); 而temp
阅读全文
摘要:普通enum enum中的枚举值位于enum本身所在的作用域中 这两个enum都位于全局作用域中,因此A和B的枚举值也位于全局作用域中,就会引发命名冲突 而把A和B分离在两个作用域中,就不会引发命名冲突 存在枚举值向整数类型的隐式转换,但不存在整数类型向枚举的隐式转换 enum -> integer
阅读全文
摘要:https://stackoverflow.com/questions/47666913/template-specialization-for-enum-values https://stackoverflow.com/questions/1619993/template-specializati
阅读全文

浙公网安备 33010602011771号