随笔分类 -  C/C++

摘要:现在的写框架的都流行使用链式调用,链式调用需要重载括号运算符,还需要控制好对象的生命周期。 阅读全文
posted @ 2022-10-08 16:03 cyssmile 阅读(157) 评论(0) 推荐(0)
摘要:int align(int x, int a) { return (x + (a-1)) & (~(a-1)); } 阅读全文
posted @ 2022-06-15 21:05 cyssmile 阅读(72) 评论(0) 推荐(0)
摘要:class A { A() { std::cout << " init" << std::endl; } ~A() { std::cout << "close" << std::endl; } }; int main () { std::shared_ptr<A> ptr = std::make_s 阅读全文
posted @ 2022-06-15 09:30 cyssmile 阅读(158) 评论(0) 推荐(0)
摘要:这种情况可能在控制台出现Trap字样 示代码 #include <memory> class A { public: int Close() {} ~A() { Close();} }; int main() { std::shared_ptr<A> = std::make_shared<A>(); 阅读全文
posted @ 2022-05-20 22:16 cyssmile 阅读(1640) 评论(0) 推荐(0)
摘要:#pragma once #ifdef __cplusplus #include <memory> #include <cstdint> #include <cstddef> #else #include "stdint.h" #include "stddef.h" #endif // __cplu 阅读全文
posted @ 2022-03-28 23:38 cyssmile 阅读(80) 评论(0) 推荐(0)
摘要:#include <iostream> template<typename T, std::size_t N> constexpr std::size_t GetArrySize(T (&)[N]) noexcept { return N; } template<typename T> conste 阅读全文
posted @ 2022-02-18 21:58 cyssmile 阅读(56) 评论(0) 推荐(0)
摘要:c++类中不允许复制构造函数是传值参数 #include <iostream> class A { private: int value; public: A(int n) { value = n; } A(A a) { // erro: 传值参数 value = a.value; } void p 阅读全文
posted @ 2022-02-14 13:19 cyssmile 阅读(37) 评论(0) 推荐(0)
摘要:对于全局静态的数据可以这样写 inline const char* GetDigitsLut() { static const char cDigitsLut[200] = { '0','0','0','1','0','2','0','3','0','4','0','5','0','6','0',' 阅读全文
posted @ 2021-06-30 16:43 cyssmile 阅读(69) 评论(0) 推荐(0)
摘要:今天遇到这样一个现象,我打印bitset中的数据,输出本身顺序相反 而实际使用GLOG输出时是这样的 后面我用标准输出,发现也是一样的。 我反复调试了几组结果,发现就是倒序打印的。 阅读全文
posted @ 2021-06-30 11:21 cyssmile 阅读(173) 评论(0) 推荐(0)
摘要:模板元递归展开 template <typename T> void SetParams(const std::string& param_name, T&& param) { params_[param_name] = std::forward<T>(param); } /** * @brief 阅读全文
posted @ 2021-06-11 17:12 cyssmile
摘要:#include <io.h> #include <cstring> #include <iostream> #include <glog/logging.h> #include <string> #include <vector> // Get All Files by Dir void GetA 阅读全文
posted @ 2021-04-12 15:01 cyssmile 阅读(908) 评论(0) 推荐(0)
摘要:##1.拼接字符串 #include <functional> #include <iostream> #define BUILD_INT_ADD 1 using func = std::function<void(int, int)>; func f; void add_int(int a, in 阅读全文
posted @ 2021-04-10 18:28 cyssmile 阅读(309) 评论(0) 推荐(0)
摘要:怎么理解nms? 非极大值抑制,简单的说就是给出一大堆bbox和相应的得分,对于其中区域重合的box,如果两个box重合部分大于设定的theshold,就抛弃小的那个,直到所有的box 都判定完了。 struct anchor_box { float x1; float y1; float x2; 阅读全文
posted @ 2021-04-08 11:27 cyssmile 阅读(961) 评论(0) 推荐(0)
摘要:1、c++中使用离散均匀分布可以引用这个有文件 #include <random> 2、在使用std::uniform_int_distribution类模板构造一个分布对象。 static constexpr int __MIN_CNT__ = 200; std::uniform_int_dist 阅读全文
posted @ 2021-04-05 12:50 cyssmile 阅读(495) 评论(0) 推荐(0)
摘要:接触到一段读写锁代码是用pthread.h实现的,我就在想如何在windows系统上使用读写锁呢。我查阅资料发现c++14就可以使用shared_mutex和mutex实现读写锁,没必要再进行封装了。 linux下使用pthread封装的读写锁 #include <pthread.h> #inclu 阅读全文
posted @ 2021-03-24 16:31 cyssmile 阅读(1273) 评论(0) 推荐(0)
摘要:linux系统中access #include <unistd.h> int access(const char *pathname, int mode); access函数用来判断指定的文件或目录是否存在(F_OK),已存在的文件或目录是否有可读(R_OK)、可写(W_OK)、可执行(X_OK)权 阅读全文
posted @ 2021-03-09 14:45 cyssmile 阅读(2579) 评论(0) 推荐(0)
摘要:带限定作用域的枚举型别通过enum class声明,非限定作用域的枚举型别通过enum声明。 1、非限定作用域的枚举型别可能导致枚举量泄漏到所在的作用域空间 namespace TestSpace { enum Color { red = 0, green, blue, }; auto red = 阅读全文
posted @ 2021-01-11 17:41 cyssmile 阅读(822) 评论(0) 推荐(1)
摘要:1. value metafunction #include <assert> template<int X> struct IntIdentity { static constexpr int my_value = X; }; int main() { static_assert(42 == In 阅读全文
posted @ 2020-12-29 21:04 cyssmile 阅读(139) 评论(0) 推荐(0)
摘要:容器创建时[]与``` #include <iostream> #include <vector> int main() { std::vector<int> vec[2]; vec[0].push_back(1); vec[1].push_back(2); //vec[0].push_back(1 阅读全文
posted @ 2020-12-24 15:55 cyssmile 阅读(479) 评论(0) 推荐(0)
摘要:在项目中通常会使用第三方库,然后在使用三方库时会出现许多编译警告,可以通过下面的方式忽略 #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #e 阅读全文
posted @ 2020-12-10 11:17 cyssmile 阅读(465) 评论(0) 推荐(0)