Syntax Sugar in C++

Summary In this post, I will introduce some syntax sugar in C++. Content 1. Initializer List Constructor 2. Range in Container Construtor 3. Copy Constructor Details 1. Initializer List Constructor vector<int> vec({1,2,3,4,5}); unordered_map<char, int> char_counter ({{‘a’, 1}, {‘b’, 2}, {‘c’, 3}}); The syntax below is also legal. // use {} in vector vector<int> nums =…

String in C++

Summary In this post, I will introduce the string class in c++ STL. It covers useful APIs and some of my recommendations. 1. Split 2. Access 3. Comparison 4. Numeric-Conversions Details Split Thanks to this post, we present the conlusions for split first. 1. If you have access to boost, please do Solution 1. 2….

Bookmarks for C++

Summary In this post, I will show some useful websites for C++ learning. The post will be updated from time to time. URLs fluentcpp A great website focused on writing expressive C++ codes developed by Jonathan Boccara. Updated every Tuesday and Friday. Petr Zemek’s Blog A private website by Petr Zemek. Simplify C++ Another great…

Auto Type

Summary In this post, I will introduce auto, const auto, auto&, const auto&, auto&&, and const auto&&. Conclusion We provide the conclusion first. When you want a read-only access (generic or non-generic codes), use auto const &, which will give you a reference rather than a copy. When you want a read-write access in generic…

Common Mistakes in C++

Summary This post will be updated from time to time. The post contains some mistakes that I will make in work and study when coding in C++. Contents container.size() – 1 when the container is empty negative % positive ‘+’ does work in “C_String” remember to delete after new to_string(‘a’) signed integers compared to unsinged…

Auto in C++

Summary In this post, I will introduce auto and decltype in C++ 11. Why Auto In some situations, auto makes codes more readable. It will tell the compiler to deduce the type of a declared variable from the initialization expression. The details are complex. At present, we want to make codes correct, clean, and simple….

Ordered Containers

Summary In this post, I will introduce the map and priority_queue in c++ STL. Why Ordered Containers Unlike the easy version unordered_map, in map, key values are generally used to sort. Thanks to the binary search tree, map has good performance in search and erase elements $(log(n))$. Constructor The following codes are self-explained. // Example…

Intel Threading Building Blocks

Summary In this post, I will introduce how to solve a parallel computation task using Intel Threading Building Blocks. Problem In the deep learning platform, given inputs contains several thousand images, we want to analyze the data path of a certain deep learning model. The analysis part of each image is identical, for example, we…