随笔分类 - C/C++
摘要:现在的写框架的都流行使用链式调用,链式调用需要重载括号运算符,还需要控制好对象的生命周期。
阅读全文
摘要:int align(int x, int a) { return (x + (a-1)) & (~(a-1)); }
阅读全文
摘要:class A { A() { std::cout << " init" << std::endl; } ~A() { std::cout << "close" << std::endl; } }; int main () { std::shared_ptr<A> ptr = std::make_s
阅读全文
摘要:这种情况可能在控制台出现Trap字样 示代码 #include <memory> class A { public: int Close() {} ~A() { Close();} }; int main() { std::shared_ptr<A> = std::make_shared<A>();
阅读全文
摘要:#pragma once #ifdef __cplusplus #include <memory> #include <cstdint> #include <cstddef> #else #include "stdint.h" #include "stddef.h" #endif // __cplu
阅读全文
摘要:#include <iostream> template<typename T, std::size_t N> constexpr std::size_t GetArrySize(T (&)[N]) noexcept { return N; } template<typename T> conste
阅读全文
摘要:c++类中不允许复制构造函数是传值参数 #include <iostream> class A { private: int value; public: A(int n) { value = n; } A(A a) { // erro: 传值参数 value = a.value; } void p
阅读全文
摘要:对于全局静态的数据可以这样写 inline const char* GetDigitsLut() { static const char cDigitsLut[200] = { '0','0','0','1','0','2','0','3','0','4','0','5','0','6','0','
阅读全文
摘要:今天遇到这样一个现象,我打印bitset中的数据,输出本身顺序相反 而实际使用GLOG输出时是这样的 后面我用标准输出,发现也是一样的。 我反复调试了几组结果,发现就是倒序打印的。
阅读全文
摘要:模板元递归展开 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
阅读全文
摘要:##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
阅读全文
摘要:怎么理解nms? 非极大值抑制,简单的说就是给出一大堆bbox和相应的得分,对于其中区域重合的box,如果两个box重合部分大于设定的theshold,就抛弃小的那个,直到所有的box 都判定完了。 struct anchor_box { float x1; float y1; float x2;
阅读全文
摘要:1、c++中使用离散均匀分布可以引用这个有文件 #include <random> 2、在使用std::uniform_int_distribution类模板构造一个分布对象。 static constexpr int __MIN_CNT__ = 200; std::uniform_int_dist
阅读全文
摘要:接触到一段读写锁代码是用pthread.h实现的,我就在想如何在windows系统上使用读写锁呢。我查阅资料发现c++14就可以使用shared_mutex和mutex实现读写锁,没必要再进行封装了。 linux下使用pthread封装的读写锁 #include <pthread.h> #inclu
阅读全文
摘要:linux系统中access #include <unistd.h> int access(const char *pathname, int mode); access函数用来判断指定的文件或目录是否存在(F_OK),已存在的文件或目录是否有可读(R_OK)、可写(W_OK)、可执行(X_OK)权
阅读全文
摘要:带限定作用域的枚举型别通过enum class声明,非限定作用域的枚举型别通过enum声明。 1、非限定作用域的枚举型别可能导致枚举量泄漏到所在的作用域空间 namespace TestSpace { enum Color { red = 0, green, blue, }; auto red =
阅读全文
摘要:1. value metafunction #include <assert> template<int X> struct IntIdentity { static constexpr int my_value = X; }; int main() { static_assert(42 == In
阅读全文
摘要:容器创建时[]与``` #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
阅读全文
摘要:在项目中通常会使用第三方库,然后在使用三方库时会出现许多编译警告,可以通过下面的方式忽略 #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #e
阅读全文

浙公网安备 33010602011771号