C++
小数据的时候 `std::vector<int>` 删除首元素比 deque 和 list 还快
链表可以当成双端队列来使用——至少在渐进时空复杂度上,它们是相同的。
但在现代化的 CPU 的支持下,std::vector
由于内存的连贯性,在小规模数据下甚至可以做到比 std::deque
更好的性能,更别提在随机访问上 std::vector
有巨大优势了。
用 C++ 写一个玩具 JSON 库
写这个解析器主要是为了看自己的 C++ 水平,毕竟 JSON 是一个同时能做到语法简单的同时考验人的编码水平的 data structure,其次是为了好玩。 好玩吗?好玩。
DIY std::optional: Using Universal References in C++
This blog was written entirely because of the item Familiarize yourself with alternatives to overloading on universal references in Effcetive Morden C++. We start with a practical problem trying to emulate std::optional
in C++14, because optional monads are a good paradigm for expressing values that may be null, rather than assuming everything is maybe null which can easily break through the type system.
写下这篇文章完全是因为看到了 Effcetive Morden C++ 中的熟悉通用引用重载的替代方法。我们从一个现实的问题开始,即在 C++14 尝试模拟 std::optional,因为 optional 是表达可能为空的值的时候一个很好的范式,而不是假定一切都可能为 null 并轻易击穿类型系统。