随笔分类 - C++
摘要:准备 准备一下安装程序,并添加到PATH环境变量。 Perl 选择64位 Portable: Perl Portable Ruby 选择64位版本进行安装:ruby 64bit Python 安装Python jom nmake不支持并行编译,使用jom进行并行编译。 下载jom,解压并添加到PAT
阅读全文
摘要:参考文章: boost多索引容器的使用介绍 multi_index_container多索引容器 代码: test_boost_multi_index_container
阅读全文
摘要:vscode在windows下使用Ninja编译配置,使用Visual Studio编译环境。来源:CMakePresets.json 参考:在 Visual Studio 中使用 CMake 预设进行配置和生成 -- 示例 文件CMakePresets.json { "version": 2, "
阅读全文
摘要:转自 C++ lambda 内 std::move 失效问题的思考 | 编程沉思录 (cyhone.com) 最近在写 C++ 时,有这样一个代码需求:在 lambda 中,将一个捕获参数 move 给另外一个变量。看似一个很简单常规的操作,然而这个 move 动作却没有生效。 具体代码如下: st
阅读全文
摘要:使用std::unique_ptr<>定义(声明)一个对象的时候,需要知道这个对象的Deleter,std::unique_ptr的原型如下: template< class T, class Deleter = std::default_delete<T> > class unique_ptr;
阅读全文
摘要:通过 pthread_self 及 std::this_thread::getid函数获取的线程ID,跟使用top/htop命令呈现的线程ID不对应。 通过如下代码获取跟top/htop一致的TID: #include <syscall.h> pid_t gettid(void) { return
阅读全文
摘要:使用示例 #include <atomic> #include <iostream> #include <thread> #include <vector> int main(int argc, char** argv) { constexpr size_t kLoopNum = 10; std::
阅读全文
摘要:static_cast static_cast相当于C语言里面的强制转换,适用于: 用于类层次结构中基类(父类)和派生类(子类)之间指针或引用的转换。进行上行转换(把派生类的指针或引用转换成基类表示)是安全的;进行下行转换(把基类指针或引用转换成派生类表示)时,由于没有动态类型检查,所以是不安全的。
阅读全文
摘要:#include <iostream> #include <stdlib.h> #define CHECK2(condition, message) \ (!(condition)) ? (std::cerr << "Assertion failed: (" << #condition << "),
阅读全文
摘要:#include <atomic> #include <chrono> #include <condition_variable> #include <iostream> #include <mutex> #include <thread> int main() { constexpr size_t
阅读全文
摘要:https://blog.csdn.net/songthin/article/details/1703966 https://cplusplus.com/reference/new/operator%20new/ https://en.cppreference.com/w/cpp/memory/ne
阅读全文
摘要:class baseA { public: virtual float mulTwo(float a, float b) = 0; virtual ~baseA() = default; }; class vClassA : public baseA { public: ~vClassA() ove
阅读全文
摘要:科学计算用优化 经过实验证明这个命令优化效果最好,把我的 1.2S 的 FFT 优化到了 0.4S使用 pragma 命令优化程序: #pragma GCC optimize("Ofast,no-stack-protector") 实用优化项: #pragma GCC optimize("Ofast
阅读全文
摘要:构造时直接使用初始化列表 T object { arg1, arg2, ... }; (1) T { arg1, arg2, ... } (2) new T { arg1, arg2, ... } (3) Class { T member { arg1, arg2, ... }; }; (4) Cl
阅读全文
摘要:概念 std::ref :针对std::thread,需要把实参显式转换为引用类型; std::move :无条件把参数转换为右值;但是右值赋值给新变量时,实际还要看是否满足右值条件,如const std::string&& 赋值后,实际调用的是左值构造/赋值; std::forward :根据实参
阅读全文
摘要:#include <algorithm> #include <array> #include <iostream> #include <iterator> #include <random> template <class Iter> void fill_with_random_int_values
阅读全文
摘要:shared_ptr std::shared_ptr<int> sp1 = new int(); // shared count = 1, weak count = 0 std::shared_ptr<int> sp2(sp1); // shared count = 2, weak count =
阅读全文
摘要:C++中的 volatile, atomic, memory barrier 应用场景对比 | -- | volatile | memory barrier | atomic | | : : | :--: | :--: | :--: | | 抑制编译器重排 | Yes | Yes | Yes | |
阅读全文
摘要:1. GCOV GCOV 是 GCC 自带的代码覆盖工具,GCOV。 在 GCC 编译的时加入特殊的编译选项,生成可执行文件,和 *.gcno; 运行(测试)生成的可执行文件,生成了 *.gcda 数据文件; 有了 *.gcno 和 *.gcda,通过源码生成 gcov 文件,最后生成代码覆盖率报告
阅读全文
摘要:Linux编译boost sudo apt install -y python3-pip sudo apt install -y build-essential libssl-dev libffi-dev python3-dev # 先禁用venv虚拟环境,否则可能找不到pyconfig.h ./b
阅读全文