随笔分类 -  C++

摘要:编译期类型名获取 C++20 标准,使用库 std::source_location。 #include <source_location> C++ 20 之前 在 C++ 20 前有两种方法 __PRETTY_FUNCTION__ __FUNCSIG__ 通过截取函数签名中的 T = ... 获取 阅读全文
posted @ 2023-11-20 21:51 Violeshnv 阅读(488) 评论(0) 推荐(0)
摘要:class Rational { static inline int gcd(int a, int b) { if (!b) return abs(a); while ((a %= b) && (b %= a)) ; // do in while return a + b; } public: st 阅读全文
posted @ 2022-10-27 11:51 Violeshnv 阅读(21) 评论(0) 推荐(0)
摘要:在C++中实现Python的range 代码在最后,可以先看代码再看说明 在实现过程中几个应该注意的问题 整型溢出 for (auto i : irange(1e9, -2e9, -2e9)) std::cout << i << "\n"; std::cout << '\n'; // 如果不注意溢出 阅读全文
posted @ 2022-10-27 11:50 Violeshnv 阅读(111) 评论(0) 推荐(0)
摘要:C++ 与 C 语言相比有着更强的类型检查,包括四种 cast,左值右值之分,reference,以及最重要的——对 const 的要求。 const 是一个相当麻烦的要求,比如其强大的“传播性”——只要在一个地方使用,就可能蔓延到各个角落,出现各种编译错误。但编程实践证明 const 的使用是值得 阅读全文
posted @ 2022-10-27 11:50 Violeshnv 阅读(58) 评论(0) 推荐(0)