← Tags

#cpp

15 posts

Span

std::span is a class template introduced in C++ 20. As one of the most paramount features, span is essentially a non-owning view of a sequence of objects, which is contiguously distributed in memory …

Armadillo

Introduction Armadillo1 is an excellent C++ library, which provides efficient linear algebra related operations, based on a series of classes, e.g., for vectors, matrices, etc. Thanks to its friendly …

Doxygen

Introduction Doxygen is a powerful tool to document the source codes. In principle, it parses the specially formated comments from the source codes and then produces very professional documents. Up …

Professional C++

本文是阅读 Professional C++, third edition 中文版1的读书笔记. 预处理指令 预处理指令以 # 字符开始. 如 #pragma once 可以防止文件被包含多次. 头文件最常见的用途是声明在其他地方定义的函数. 宏是C遗留下来的, 类似于内联函数, 但不执行类型检测, 在调用宏时, 预处理器会自动用扩展式替换, 并不会真正地应用函数调用语义, 这一行为可能导致无法 …

Standard Template Library (STL) of C++

标准模板库(standard template library, STL)是C++标准库的子集, 其大量使用了模板. 容器 STL中的所有容器都是模板, 是泛型结构, 因此可以通过这些容器保存任意类型的数据. 除 array 和 bitset 外, 大部分STL容器的大小灵活多变, 都能自动增长或收缩, 以容纳更多或者更少的元素. STL容器是同构的, 每个容器实例只允许一种类型的元素. STL …

GNU Debugger (GDB)

GDB is the world famous GNU debugger, which is very powerful. In this article, its elementary usages can be listed as follows. b(reak) LINE_IDX: set breakpoint in line LINE_IDX. b(reak) FUN_NAME: set …

Output Object

In object oriented programming (OOP) based C++ program, we usually need to output the properties and members of one or more objects. In this case, overriding the ostream operator, <<, is a …

Singleton

Singleton plays an important role in program architecturing for its global visibility. For instance, system parameters are usually structured as a singleton. What deserves to be noticed, a singleton …

多态

简介 多态 是C++语言的一大特色。一个操作随着所传递或捆绑的对象类型的不同能够做出不同的反应,其行为模式称为多态1。而且,仅仅对于对象的指针和引用的间接访问,才会发生多态。 虚函数 在使用类的C++语言中,抽象编程需要使用 虚函数 机制。基类与派生类的同名操作,只要标记上 virtual2 ,则该操作(虚函数)便具有多态性。一旦标记基类的函数为虚函数,便有连锁反应,后面继承的类中一切同名成员函 …

Switch in C++

在C/C++语言中, switch 语句的通用格式为 switch (int_expr) { case label1: statement(s) case label2: statement(s) ... default: statement(s) } 顾名思义, int_expr 必须是一个结果为整数值的表达式。另外,每个标签都必须是整数常量表达式。最常见的标签是 int 或 char 常量( …

Multithreading in C++

背景 C++98/03不支持多线程编程, 所以必须借助第三方库或目标操作系统中的多线程API. 这使得编写跨平台的多线程程序很困难. C++11引入了标准的多线程库, 使得多线程程序跨平台更加容易. 目前的C++11标准仅针对CPU, 不支持GPU. 多线程编程的难点之一是将算法并行化, 这个过程和算法的类型高度相关. 此外, 要防止竞争条件和死锁, 并考虑缓存的一致性. 竞争条件 当多个线程要 …

Language Server Protocol (LSP)

Introduction Language server protocol (LSP) offers a uniform specification between a client and a server1. The Language Server protocol is used between a tool (the client) and a language smartness …

IT++

Introduction IT++1 is a powerful C++ library, which is widely employed in the area of communication, esp. in simulation programming and computing. It has provided a variety of useful classes, e.g. …

C++ - 标准库

本文是阅读 Professional C++, third edition 中文版1的读书笔记. C++标准库的核心是泛型容器和泛型算法. 包括标准模板库(Standard Template Library, STL). 所有标准库类和函数都在 std 名称空间中声明. 包括如下组件: 字符串 定义在头文件 <string> 中的 string 类. 正则表达式 定义在头文件 …

Thread Pool

Introduction Threadpool is a C++ thread pool written by Philipp Henkel based on boost library. It provides a variety of thread pools with easy usage. Installation As a prequisite, boost library …