Effective C++ | 01 Accustom yourself to C++

C++零开销抽象实战:走读 FlashAttention-2 核心源码,看编译期特化与寄存器复用如何打破显存 在 A100 上跑原生 FlashAttention-1,Tensor Core 算力利用率常年停在 25% 到 40% 的区间;到了 FlashAttention-2,同样的 FP16 矩阵乘运算,利用率直接跃升到 50% 至 73%,在计算图没有少乘一个元素的前提下实现了 2 倍的端到端吞吐提升。 阅读详情

Effective C++ | 01 Accustom yourself to C++

Book: Effective C++ (Third Edition)

Item 01: View C++ as a federation of languages

C++ is multiparadigm programming language:

  • procedural
  • object-orientated
  • functional
  • generic
  • metaprogramming features

C++ is not a single language.

C++ is a federation of languages:

  1. C
  2. Object-Orientated C++
  3. Template C++
  4. STL

Pass by value (C)
More efficient that pass by reference for built-in (C-like) types

Pass by reference to const (Object-Oriented, Template)
Better for user-defined objects (with constructors / destructors)
Esp. true for template C++ (you don’t know type you’re dealing)

Pass by value (STL)
Better for STL because iterators and function objects are modelled on pointers in C
Iterators and function objects in STL pass by value is better

Item 02: Prefer consts, enums, and inlines to #defines

Prefer compiler to the preprocessor

#define ASPECT_RATIO 1.653
const double AspectRatio = 1.653;

The latter is better.

AspectRatio seen by compilers and entered into symbol tables

Also 1.653 (#define) multiple times in object code
Whereas constant AspectRatio appears once

2x SPECIAL CASES

01.Defining constant pointers

Constant definitions in headers files means pointer declared const plus what pointer points to
const char* const authorName = “Scott Meyers”;

NB: string prob better than char*

const std:: authorName("Scott Meyers");

02.Class-specific constants

Limit scope of constant to class = make it a member
Ensure at most one copy of constant = make it static

// GamePlayer.h
class GamePlayer 
{
private:
	static const int NumTurns = 5;	// constant declaration
	int scores[NumTurns];
};

C++ requires definition for declaration except class-specific constants that are static of integral type
(int, char, bool)

NB: if you take address then compiler insists on definition:

// GamePlayer.cpp
const int GamePlayer::NumTurns; 	// definition	no value!

IMP
Cannot create class-specific constant using #define
#define does not respect scope: can’t be private

If (old) compiler does not allow initialization in declaration (above) then do this

// GamePlayer.h
class GamePlayer 
{
private:
	static const int NumTurns;	// constant declaration
};
// GamePlayer.cpp
const int GamePlayer::NumTurns = 5; 	// definition	no value!

However, now scores array won’t work 'cos you need the value of a class constant during compilation:
compilers insist on knowing the size of the array

Only way to forbid in-class specification of initial values for static integral class constants:

ENUM HACK

class GamePlayer
{
private:
  enum { NumTurns = 5 };        // "the enum hack" ?makes NumTurns a symbolic name for 5
  int scores[NumTurns];         // fine
};

Enum hack used a lot!
Acts more like #define than const

Why?
Take address of const——Legal
Take address of enum——Illegal
Take address of #define——Illegal

If you don’t want people get pointer or reference to integral constants then enum enforces that constraint

Also, enum hack is fundamental technique of template metaprogramming

MACROs
Macros look like functions but don’t incur overhead of function call
Arrgh : must parenthesize all arguments in the macro body!

Do not code like this:

// call f with the maximum of a and b
#define CALL_WITH_MAX(a, b) f((a) > (b) ? (a) : (b))


int a = 5, b = 0;
CALL_WITH_MAX(++a, b);          // a is incremented twice
CALL_WITH_MAX(++a, b+10);       // a is incremented once

this is right:

template<typename T>
inline void callWithMax(const T& a, const T& b)
{
	f(a > b ? a : b);
}

No need to
parenthesize parameters inside function body
evaluate parameters multiple times

callWithMax obeys scope and access rules
Can inline function private to the class

Can’t do that with Macro!

SUMMARY

  • For simple constants, prefer const or enums to #define
  • For function-like macros, prefer inline functions to #define

Item 03: Use const whenever possible

An object should not be modified ?and compilers will enforce that constraint.

Pointers
Specify whether pointer is const, data it points to is const, both or neither

char greeting[] = "Hello";
char stevepro[] = "Steve";
char* p1 = greeting;	// neither const
const char* p2 = greeting;	// DATA const
char* const p3 = greeting;	// POINTER const
const char* const p4 = greeting;	// both const

TRICK
Imagine line down the “*”
If const to left then DATA is const
If const to right then POINTER is const

const LHS = DATA (D)
const RHS = POINTER (P)

EXAMPLE

Data	p2[0] = 'X';

error C3892: ‘p2’ : you cannot assign to a variable that is const

Pointer p3 = stevepro;			

error C3892: ‘p3’ : you cannot assign to a variable that is const

If const on left of asterisk then what’s pointed to is const i.e. data
If const on right of asterisk then the pointer itself is const i.e. pointer

DATA
Both are the same

const char* p2 = greeting;

char const* p2 = greeting;
char const *p2 = greeting;

ITERATORS
STL iterators modelled on (C) pointers
Act like T* pointer

const iterator is like pointer const (T* const pointer)
i.e. what iterator points to (RHS of *) POINTER

Thus, the iterator is not allowed to point to anything else
But the DATA i.e. the thing iterator points to may be modified

Example #1

const std::vector<int>::iterator iter = vec.begin();
*iter = 10;
//++iter;	ERROR because iterator is const pointer thus cannot point to anything else!

const_iterator
If you want iterator to point to something else (be modified) but the DATA each iteration points to
Then use const_iterator (const T* pointer)

Example #2

std::vector<int>::const_iterator cIter = vec.begin();
//*cIter = 10;		// error C3892: 'cIter' : you cannot assign to a variable that is const
++cIter;

FUNCTION DECLARATION
const refer to:
return value
input parameters
member functions as a whole

GOOD Example

class Rational { … };

const Rational operator*(const Rational& lhs, const Rational& rhs);

Why should return type operator* be const?
Because it prevents this:

Rational a, b, c;

(a * b) = c		// wouldn't proactively do this

BUT

if (a * b = c)	...	// oops, meant to do comparison

One of the hallmarks of good user-defined types is that they avoid gratuitous incompatibilities with built-in types
Declaring operator* return value as const prevents this DO IT!

const save from annoying “I meant to type ‘==’ but accidentally typed ‘=’” mistakes

const Member Functions
const Member Functions identify which member functions may be invoked on const objects.

2x REASONS important

01.Interface easier to understand:
Which functions modify an object + which don’t

02.Make it possible to work with const objects

IMP: improve performance by pass objects by reference to const
Technique only viable if there are const member functions to manipulate const-qualified objects

IMPORTANT C++ feature:
Member functions differing only in constness can be overloaded

// operator[] for const objects.
const char& operator[](std::size_t position) const
{
	return text[position];
}
// operator[] for non-const objects.
char& operator[](std::size_t position)
{
	return text[position];
}
 tb[0] = 'x'; 
ctb[0] = 'x'; 		// error! - writing to const TextBlock

Error here has to do with return type of operator[]
calls to operator[] are fine
but attempt to assign to const char& arises because return type of const version of operator[]

IMPORTANT
non-const operator[] is a reference to a char - a char would not do!

If operator[] on non-const did return simple char then statements like this wouldn’t compile:

char operator[](std::size_t position);
// error C2106: '=' : left operand must be l-value

Why?
Because it never legal to modify the return value of a function that returns a built in type (char)

If it were legal, C++ return objects by value thus a COPY of tb.text[0] would be modified
NOT tb.text[0] itself - not the behavior you want

Member functions as const
2x NOTIONS

01.Physical constness (bitwise constness)
If, and only if, member function doesn’t modify any of the object data members (excluding static)
const member function isn’t allowed to modify any of the non-static data members of the object

Violations: just look for assignments to data members
A const member function isn’t allowed to modify any of the non-static data members

1.5. Many member functions don’t act very const but pass the bitwise test

e.g.
Member function that modifies what a pointer points to (data) doesn’t act const
If the pointer is in the object then the compiler doesn’t complain WTF

const CTextBlock cctb("Hello");
char* pc = &cctb[0];
*pc = 'J';		// Access violation but sometimes may be "Jello"

Problem: create const object but can modify some of its bits in the object!

02.Logical constness
A const member function might modify some of the bits in the object on which it’s invoked
But only in ways that clients cannot detect

std::size_t length() const;

NOT bitwise const as both textLength and lengthIsValid try to be modified

// error C3490: ‘textLength’ cannot be modified because it is being accessed through a const object

It should be valid for const CTextBlock objects. Compilers disagree.
They insist on bitwise constness. What to do? MUTABLE!!

class CTextBlock3
{
public:
	CTextBlock3::CTextBlock3(char* t) : pText(t), lengthIsValid(false)
	{
	}

	std::size_t length() const;

private:
	char* pText;

	mutable std::size_t textLength;
	mutable bool lengthIsValid;
};

mutable is nice solution to bitwise-constness problem

However, you may need to do similar code in const and non-const version operator[] = code duplication
Put common code into private separate member function that both version operator[] call

But may be better to implement functionality once and use it twice:
One version calls the other (cast away constness)

Have the non-const operator[] call the const version is a safe way to avoid code duplication
even though it requires a cast

// operator[] for const objects.
const char& operator[](std::size_t position) const
{
	return text[position];
}
// operator[] for non-const objects.
char& operator[](std::size_t position)
{
	return const_cast<char&>(static_cast<const TextBlock&>(*this)[position]);
}

Non-const version has 2x casts
As there’s no way to specify call to the const operator we cast *this from TextBlock& to const TextBlock&
Yes, we have to a cast to const! (Otherwise non-const calls itself recursively forever)

  1. to add const to *this (call const operator[]) static_cast<const TextBlock&>(*this)[position]
  2. remove const from const operator[]'s value const_cast<char&>(…) cast away constness

Finally, you do NOT want const version to call the non-const version as non-const may change things in object
(and const promises never to change anything)

But non-const can do whatever it wants and calling const member function imposes no risk
That’s why static_cast works on *this (there’s no const-related danger)

REMEMBER

  • Declaring something const helps compilers detect usage errors.
    const can be applied to objects at any scope, to function parameters and return types, and to member functions

  • Compilers enforce bitwise constness but you should program using conceptual constness

  • When const and non-const member functions have essentially identical implementations,
    code duplication can be avoided by having the non-const version call the const version
    04 Item04
    09-Nov-2013

Item 04: Make sure that objects are initialized before they’re used

int x;

x guaranteed to be initialized (to zero)

Point p;

p’s data members are sometimes guaranteed to be initialized (to zero)
but sometimes they’re not

Reading uninitialized values yields undefined behavior

Rules that describe object initialization are complicated
Not worth memorizing

e.g.
C part of C++ and initialization incur runtime cost then not guaranteed to take place

Explains why array (C part of C++) not guaranteed to have its contents initialized
But vector (STL part of C++) is

Solution: ALWAYS initialize your objects before you use them

Examples:

int x = 0;				// manual initialization of an int
const char* text = "A C-style string"	// manual initialization of a pointer

double d;
std::cin >> d;				// "initialization" by reading from input stream

Everything else, responsibility falls on constructors
Therefore, ensure constructors initialize everything in the object

NB: do not confuse assignment with initialization

//01. Assignments
ABEntry(const std::string& name, const std::string& address, const std::list<PhoneNumber>& phones)
{
	// these are all assignments.
	theName = name;
	theAddress = address;
	thePhones = phones;
	numTimesConsulted = 0;
}

ABEntry objects with values you expect but not the best approach

Rules of C++ stipulate that data members of an object are initialized BEFORE
the body of a constructor is entered

ABEntry data members are assigned
Initialization took place earlier when default constructor were called automatically
before entering body of ABEntry constructor

Not true for numTimesConsulted, a built-in type
No guarantee it was initialized prior to assignment

Better way to write ABEntry (non-default) constructor
Use member initialization list instead of assignments

//02. Initialization list.
ABEntry::ABEntry(const std::string& name, const std::string& address, const std::list<PhoneNumber>& phones) :
	theName(name),
	theAddress(address),
	thePhones(phones),
	numTimesConsulted(0)
{
	// the ctor body is empty.
}

Results are the same but initialization list is more efficient.
NB: theName(name) invokes copy constructor

But a single call to a copy constructor is more efficient (sometimes MUCH more efficient)
than a call to the default constructor followed by call to copy assignment operator

Built-in types there is no difference but best to initialize EVERYTHING via member initialization

Also, you can use member initialization for default-construct data members;
just specify nothing as an initialization argument

//03. Empty default-constructed values
ABEntry::ABEntry(const std::string& name, const std::string& address, const std::list<PhoneNumber>& phones) :
	theName(),
	theAddress(),
	thePhones(),
	numTimesConsulted(0)
{
}

Best advice is to do member initialization for all data members
so don’t forget any plus const and reference must be initialized; they can’t be assigned!

AND initialize in the order they’re listed in data member section
because they will be initialized in the data member order i.e.theName initialized before theAddress

LAST THING
The order of initialization of non-local static objects defined in different translation units

STATIC OBJECT
An object that exists from the time it’s constructed until the end of the program

Excludes: stack / heap based objects
Includes: global objects, namespace objects, objects declare static in classes, functions, files

Local static objects are objects declared static in functions
Non-local static objects are everything else

TRANSLATION UNIT
Source code giving rise to a single object file
A single source file plus all #include files

If non-local static object in one translation unit uses a non-local static object in
different translation unit then the object it uses could be uninitialized. Why?

The relative order of initialization of non-local static objects defined in different
translation units is undefined

FileSystem + Directory example
Initialization order is important: FileSystem tfs MUST be initialized BEFORE Directory

But there is no guarantee of this because:
The relative order of initialization of non-local static objects defined in different
translation units is undefined

Why? Because it is impossible to determine the right order of initialization

Solution
Move each non-local static object into its own function where it’s declared static
These functions return references to the objects they contain

Non-local static objects are replaced with local static objects
(Singleton design pattern)

C++ guarantees that local static objects are initialized when the object’s definition
is first encountered during a call to that function

So, if you replace direct access to non-local static objects with calls to functions
that return references to local static objects then you’re guaranteed objects will initialized

Bonus: if you never call function then you never incur const of constructing / destructing obj

class FileSystem { ... };           // as before

FileSystem& tfs()                   // this replaces the tfs object; it could be
{                                   // static in the FileSystem class
  static FileSystem fs;             // define and initialize a local static object
  return fs;                        // return a reference to it
}

class Directory { ... };            // as before

Directory::Directory( params )      // as before, except references to tfs are
{                                   // now to tfs()
  std::size_t disks = tfs().numDisks();
}

Directory& tempDir()                // this replaces the tempDir object; it
{                                   // could be static in the Directory class
  static Directory td;              // define/initialize local static object
  return td;                        // return reference to it
}

Clients of program replace tfs with tfs()
i.e. use functions returning references to objects instead of using objects themselves

IMPORTANT
These functions contain static objects and makes them problematic in multi-threaded systems
non-const static object (local or non-local) may be trouble in multi-threaded systems

Solution
Manually invoke all the reference-returning functions during the single-threaded startup
That eliminates initialization-related race conditions

To avoid using objects before they’re initialized do 3x things:

  1. manually initialize non-member objects of built-in types
  2. use member initialization lists to initialize all parts of an object
  3. design around then initialization order for non-local static objects in diff translation units

REMEMBER

  • Manually initialize objects of built-in type, because C++ only sometimes initializes them

  • In a constructor, prefer member initialization lists to assignment inside constructor body.
    List data members in initialization list in the same order they’re declared in the class

  • Avoid initialization order problems across translation units by replacing
    non-local static objects with local static objects (in functions)

《数据结构》02-线性结构1 两个有序链表序列的合并 题目 本题要求实现一个函数,将两个链表表示的递增整数序列合并为一个非递减的整数序列。 函数接口定义: List Merge( List L1, List L2 ); 其中List结构定义如下: typedef struct Node *PtrToNode; struct Node { ElementType Data; /* 存储结点数据 */ PtrToNode Next;... 阅读详情

相关推荐

Python通用编程规范-09 安全编程规范

1.9 安全编程规范 1.9.1 异常行为 1.9.1.1 禁止抑制或者忽略已检查异常 【说明】: 编码人员常常会通过一个空的或者无意义的catch块来抑制捕获的已检查异常。每一个catch块都应该确保程序只会在继续有效的情况下才会继续运行下去。因此,catch块必须要么从异常情况中恢复,要么重新抛出适合当前catch块上下文的另一个异常以允许最邻近的外层try-catch语句块来进行恢复工作。异常会打断应用原本预期的控制流程。例如,try块中位于异常发生点之后的任何表达式和语句都不会被执行。因此,异常必须

zhao12501的博客 2874

C语言条件宏定义导致的隐藏bug

同一个宏定义可能在不同的.o文件中表示不同的值,而且因为宏定义是在预编译阶段的文本替换,所以 连接时即便相同的宏定义值不同也无法发现错误。代码在运行时这个数组的实际分配长度就是10,但是在IAR仿真时,监视到的数组长度是20,这是IAR仿真功能的bug。运行代码可以看到同一个宏在不同的.c文件打印值不一样,这是因为条件宏的条件对不同c文件的可见性不一样。不同的c语言编译器在这个问题上结果是一样的。但是,IAR在仿真时会出现仿真看到的数组长度为20,但是实际长度为10的情况。

qq_40438388的博客 62

MTK平台LCD驱动开发实战:从零开始点亮你的Android屏幕

本文详细介绍了在MTK平台进行Android LCD驱动开发的完整流程。从理解LK与Kernel双核驱动框架入手,手把手讲解驱动结构体、屏幕参数配置、初始化序列编写以及PLL_CLOCK计算等核心步骤,并提供了系统集成配置与实用的调试避坑指南,帮助开发者高效点亮新屏幕。

terraform7cloud的博客 297

eventpp: 一款纯 Header-Only的高性能C++事件库

eventpp是一款纯Header-Only、零依赖的高性能C++事件库,支持C++11及以上,兼容多平台。核心组件包括CallbackList(同步信号槽)、EventDispatcher(事件分发)和EventQueue(异步队列),均提供线程安全机制与优异性能。通过模板策略可灵活配置线程安全级别,支持多生产者-多消费者模式及批量优化。虽原生不支持返回值聚合,但可通过输出参数、forEach遍历或promise/future等方案实现。适用于解耦组件、跨线程通信等场景,是Qt信号槽的轻量高效替代,尤其在

红军不怕远征难,万水千山只等闲 377

学习海康VisionMaster之BLOB分析

6):软阈值(相对):是一种动态阈值分割方法,其核心思想是 基于图像局部特性(如背景或参考区域)自适应调整阈值范围,适用于光照变化明显、背景灰度不均的场景。3:拖入位置修正功能:这个非常重要,模版匹配成功后会得到新的匹配坐标,那和创建模版时候的原点坐标会组合成一个坐标变换矩阵,通过这个矩阵,那后续的blob分析窗口则可以实现精确定位来查找目标对象。(2):设定参数:这里阈值方式是blob的核心算法,根据不同的应用场景来选择不同的阈值方式。8:高级参数:是设定blob区域的特征范围,用于筛选出来特定的区域。

yuhouxiyang的专栏 3630

药物重定位实战:如何用反向找靶技术挖掘老药新用(附Python代码示例)

本文详细介绍了药物重定位中的反向找靶技术,通过分子相似性计算、机器学习模型和结构对接等方法,挖掘已有药物的新治疗潜力。附Python代码示例,帮助读者快速实现从分子结构到潜在靶标的智能预测,显著提升药物研发效率。

weixin_28726671的博客 262

开源鸿蒙PC适配教程:把小熊猫C++(RedPanda-CPP)搬到鸿蒙桌面端

小熊猫C++(RedPanda-CPP)是一个用 C++17 和 Qt Widgets 写的轻量 C/C++ IDE,自带词法分析、预处理、补全、编译运行和 GDB 调试。本项目把它迁移到鸿蒙 PC,目标不是“能打开一个窗口”,而是让编辑、文件工作流、符号索引、补全和导航在鸿蒙桌面端真正可用。项目选择保留与 UI 解耦的上游解析器,用 ArkUI 重建外壳,这样工作量可控,解析器行为也不会和桌面版分叉。这样解析器看到的是“展开后的真实代码”,不会把。,先编译,看链接器缺什么,再只补缺失的声明和最少实现。

忆~遂愿的博客 3327

【COMSOL超材料和超表面仿真设计】

超材料和超表面的设计通常需要自定义材料属性。在COMSOL中,可以通过定义介电常数和磁导率的张量来模拟超材料的特性。对于超表面,通常需要定义表面阻抗或等效电路模型。

weixin_51101456的博客 1687

PaddleOCR与PyQt 界面综合案例

本项目基于PaddleOCR与PyQt5实现流水线标签实时识别系统,通过摄像头采集画面,结合置信度过滤(≥0.7)、正则格式筛选及三帧投票策略,有效降低单帧误识别,提升结果稳定性。系统采用模块化设计,实现“采集—识别—标注—统计”全流程可视化,界面简洁,响应实时,具备良好可扩展性,适用于工业场景中的自动化标签识别需求。

2302_80153357的博客 480

西门子S7-1200 PLC与伺服电机控制实战解析

工业自动化控制系统中,PLC(可编程逻辑控制器)与伺服电机的协同工作是实现精密运动控制的核心技术。通过PROFINET工业以太网协议,PLC可以高效地控制多台伺服电机,实现定位、同步和插补等复杂运动。在实际工程应用中,硬件组态的正确配置和运动控制算法的优化是关键挑战。本文以西门子S7-1200 PLC控制五台伺服电机的项目为例,详细介绍了从硬件组态、运动控制程序实现到HMI界面设计的全流程。特别针对多轴同步插补运动、动态速度曲线调整等特殊工艺需求,提供了实用的解决方案和调试技巧,为工业自动化领域的工程师提供

weixin_30252709的博客 499

微信小程序 - 获取当前日期时间(函数封装)

效果图 前言 摘自微信小程序demo程序中utils.js方法。 普通newDate()出来的日期时间,并不是我们想要的格式,所以要进行格式整理。 解决方案 打开utils.js文件(随意),复制以下代码: /** *获取当前时间 *@description自定义日期分钟秒数 *@param{Object}date-newData()对象 *@returnString */ functionformatTime(date){ //年月日

🏆 前端领域优质创作者 2849

把 Ghostscript 迁到鸿蒙 PC:从 Linux 命令行到 libgs + NAPI + ArkUI

Ghostscript 原本是 Linux/Unix 下的命令行程序。它没有独立 GUI,真正的核心是 PostScript/PDF 解释器、PDF writer、图像设备、字体和 Resource。本文按实际迁移顺序记录工程环境、原生库编译、NAPI 桥接、系统能力替换、应用构建和验证结果。

池央的博客 3859

3、无限维系统理论中的算子与半群:概念、定理及应用

本博文深入探讨了无限维系统理论中的两个核心概念:里茨谱算子与卢默-菲利普斯定理。文章首先介绍了里茨基的定义与性质,分析了谱、预解集及特征值在无限维系统中的特性,并详细阐述了里茨谱算子的条件及其生成C0-半群的能力,结合阻尼欧拉-伯努利梁模型展示了其应用。随后,文章介绍了卢默-菲利普斯定理及其推论,通过多个偏微分方程实例(如一阶方程、柔性梁、波动方程和扩散问题)说明如何利用该定理判断算子是否生成压缩半群。此外,还强调了状态空间选择和边界条件对系统适定性的重要影响,并总结了相关问题的解决步骤与方法。

flink9streamer的博客 150

C++课后习题训练记录Day212

现在有 Q 次询问,每次询问给定 x=xi,询问初始的 x=xi​,经过 N 次操作后 x 的具体值。注意每段代码末尾的分号是否存在 ,如不存在则需即使补充;之后 N 行,第 i 行给定一个操作类型 typei,表示运算符,以及一个正整数 fi​。之后 Q 行,第 i 行给定一个正整数 xi​,表示依次询问。对此代码进行检验,检验后无报错,运行此代码,运行结果正确。输出共 Q 行,每行包含 1 个整数,表示最终答案。在蓝桥云课中选择题库,选择题号5323并开始练习。第一行包含 2 个正整数 N,Q。

zmzb0103的博客 190

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

C++高性能日志库spdlog实战指南:从入门到异步编码实战

SpdLog是一款高性能、跨平台的C++11日志库,采用Header-Only设计,支持异步日志、多线程安全、彩色输出及文件滚动等特性。其架构基于Logger/Sink/Formatter三层模型,灵活可扩展。通过fmt风格格式化与自定义Pattern,实现高效安全的日志输出。支持多种Sink,可轻松集成至项目中,广泛应用于高性能服务开发。

程序员与背包客_CoderZ 206

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

c++ constexpr 关键字

constexpr。

拒绝AI文,努力在AI时代写出感动人心的好文章 391

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

C++ 实现 AVL 平衡二叉搜索树:插入逻辑与四种旋转全解析

AVL树是一种自平衡二叉搜索树,通过维护节点平衡因子(左右子树高度差≤1)确保插入、查找、删除操作时间复杂度稳定在O(logN)。本文详细解析了AVL树的节点结构、插入流程及四种旋转机制:右单旋(LL)、左单旋(RR)、左右双旋(LR)和右左双旋(RL)。关键在于自底向上更新平衡因子,并在失衡时通过旋转恢复平衡。代码实现中强调父指针维护与双旋时平衡因子的精准更新,适用于查询密集型场景,但频繁增删时性能不如红黑树。

2603_95129722的博客 367

C++符号冲突与内部符号优先策略详解

本文系统解析C++符号冲突的四大场景,重点阐述通过作用域优先、命名空间隔离与内部链接机制实现内部符号优先。利用局部变量屏蔽全局、匿名命名空间限制可见性、static与using声明控制访问,结合动态库符号隐藏与命名空间封装,可有效避免跨文件、跨库符号冲突,确保用户代码内部符号被优先使用,提升大型项目可维护性与可靠性。

bkspiderx的博客 382

IP5381至为芯支持3路C口140W双向快充新国标移动电源方案芯片

IP5381_G2是一款用于新国标移动电源,充电宝方案的移动电源管理SOC芯片,支持1-6节锂电池配置,集成PD3.2/QC/UFCS等主流快充协议,140W双向快充,8A充电电流,35V输入耐压。通过新国标合规认证,Flash掉电存储:电池 SN、生产时间、电压温度、故障日志;USB2.0全速和PC通信,可读日志、溯源等。提供1A+3C双向快充等多种接口组合。

2501_92525625的博客 231

C++ 实战:奶茶配料计算器——输入甜度与冰量,自动算出最优搭配方案

看似简单,背后却涉及糖浆克数、冰块克数、茶汤比例、奶基底比例、小料搭配等一系列换算。以中杯 500ml 为例,基准配方设定为:茶汤 60%、牛奶 25%、糖浆 8%、冰块 5%、小料 2%。这些比例之和为 100%,保证容量守恒。若把甜度改为「全糖」,糖浆比例翻倍,茶汤相应减少,总容量仍保持 500ml。通过这样一个小项目,可以同时练习枚举建模、比例换算、输入校验和异常处理,是 C++ 入门阶段很实用的练手案例。这里把甜度和冰量都映射到 0~100 的百分比,后续计算只需按比例缩放,逻辑统一且易于维护。

FJ39SfgYS的博客 251

C语言绘图方法:(17)球体缩放旋转

C语言有一套自己的绘图方法,很好很实用。当然那些图像处理软件和CAD绘图软件有非常强大的功能,然而对于设备的要求高,系统的开销也大。如编制小型的应用程序,需展示界面菜单按钮进度条,自己编制就能让程序体量小功能精悍。还有这些绘图方法便于读者深入理解C语言绘图技术的金点,并能激发读者在图形编程方面的创新和探索。本例是画球体,介绍几个打光的方法,供大家参考。

baidu_41801770的博客 239

LeetCode //C - 1320. Minimum Distance to Type a Word Using Two Fingers

This problem involves finding the minimum total distance to type a given word using two fingers on a keyboard layout where letters are arranged in a grid. The solution uses dynamic programming to track the positions of the two fingers after each keystroke,

Made in Code 346

【C++】xlsxcpp:零外部依赖的 Excel `.xlsx` 读写库,服务端导报表不用装 Office

关键词:C++、Excel、xlsx、QXlsx、CMake、服务端报表、无 Qt。

C++方向学习笔记 277

【Linux系统编程】信号

信号:用户或者系统,异步的给进程发送就绪方式----异步通知机制,信号属于软中断。信号的本质实际上就是一个个数字!理解:每个信号 都有一个编号和一个的宏定义名称,这些宏定义可以在signal.h中查看,识别信号是内置的,进程识别信号是内核程序员写的内置特性,所以信号的处理方法在接收到信号之前就已经准备好了,那收到信号之后什么时候处理呢?

2501_92908976的博客 190

C++笔记(面向对象)成员初始化列表

在 C++ 中,成员初始化列表在进入构造函数函数体之前,完成类成员变量的初始化。重点:初始化 ≠ 赋值。初始化是创建变量时直接给初值;赋值是变量已经存在之后,修改它的值。避免值拷贝开销,外部拿到引用可以直接修改原变量。反面坑:不要返回局部变量的引用,局部变量函数结束就销毁,引用变成野引用。

2501_91434366的博客 252

DevEco Studio静态检测编码规范:Clang-Tidy与Code Linter

DevEcoStudio内置Clang-Tidy(C/C++)与CodeLinter(ArkTS/TS)静态检测工具,实现代码规范自动化检查。Clang-Tidy支持自定义规则配置,实时或手动触发13项默认检查,涵盖内存泄漏、无限循环、数组越界等安全问题;CodeLinter支持全量/增量检查,可配置规则集(如@typescript-eslint、@performance等),并提供一键修复、屏蔽告警等功能,提升开发效率与代码质量。

梦想不只是梦与想的博客 423
上一篇: Effective C++ | 00 Introduction
下一篇: 计算机图形学 | 投影变换
UestcXiye
博客等级 码龄8年 9044粉丝 1306原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

UestcXiye

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址