===================
== lxulxu's blog ==
===================
Hello there

C++中的push_back与emplace_back

c++

1. 引言

C++标准库提供了push_backemplace_back两种向容器末尾添加元素的方法。本文将深入分析这两个函数的区别、使用场景,以及在实际应用中的性能考虑。

2. 基本概念

2.1 push_back push_back有两个重载版本:

1void push_back(const T& value);
2void push_back(T&& value);

第一个版本复制元素,第二个版本移动元素。

2.2 emplace_back emplace_back是C++11引入的变参模板函数:

1template <class... Args>
2void emplace_back(Args&&... args);

它直接在容器中构造对象,参数被完美转发给元素的构造函数。

3. 主要区别

  1. 构造方式push_back需要预先构造的对象,emplace_back在容器内构造对象。
  2. 参数传递push_back接受对象,emplace_back接受构造函数参数。
  3. 效率emplace_back可能避免不必要的临时对象创建和复 …
Read more...

Y2024Q3 影视音总结

生活

🎬MOVIES

Y2024Q2 影视音总结

生活

🎬MOVIES

C++安全指南

c++

编程习惯

  • switch中应有default
  • 不应在debug或错误信息中提供过多内容
  • 不应该在客户端代码中硬编码对称加密秘钥
1    // Bad
2    char g_aes_key[] = {...};
3    void Foo() {
4      ....
5      AES_func(g_aes_key, input_data, output_data);
6    }
1    // Good
2    char* g_aes_key;
3    void Foo() {
4      ....
5      AES_encrypt(g_aes_key, input_data, output_data);
6    }
7    void Init() {
8      g_aes_key = get_key_from_https(user_id, ...);
9    }
  • 函数不可以返回栈上的变量的地址,而应当使用堆来传递非简单类型变量,强烈建议返回 string、vector 等类型。
1    // Bad
2    char* Foo(char* …
Read more...

Y2024Q1 影视音总结

生活

🎬MOVIES

《高质量C++编程指南》笔记

c++

文件结构

头文件结构

 1//版权和版本声明
 2/*
 3* Copyright (c) 2001,上海贝尔有限公司网络应用事业部
 4* All rights reserved.
 5*
 6* 文件名称:graphics.h
 7* 文件标识:见配置管理计划书
 8* 摘   要:简要描述本文件的内容
 9*
10* 当前版本:1.1
11* 作   者:输入作者(或修改者)名字
12* 完成日期:2001年7月20日
13*
14* 取代版本:1.0
15* 原作者 :输入原作者(或修改者)名字
16* 完成日期:2001年5月10日
17*/
18
19#ifndef GRAPHICS_H // 防止 graphics.h 被重复引用
20#define GRAPHICS_H
21#include <math.h> // 引用标准库的头文件
22...
23#include “myheader.h” // 引用非标准库的头文件
24...
25void Function1(...); // 全局函数声明
26...
27class Box // 类结构声明
28{ …
Read more...

Tcl Cheat Sheet

cheat-sheet tcl
  • 基础语法
 1puts "Hello World"#输出
 2set x [expr 1 == 2 ? 1 : 2]#设置变量;三元运算符
 3[exec ls]#调用子进程
 4
 5#if
 6if { $x < 2} { ... }
 7elseif { $x == 1 } { ... }
 8
 9#while
10while { $x < 2 } {
11	incr x
12}
13
14#for
15for { set i 0 } { $i < 5 } { incr i } { ... }
16
17#switch
18switch $x {
19	1 { ... }
20	2 { ... }
21	default { ... }
22}
  • 字符串
 1set s1 "_Hello_World_"
 2set s2 "_"
 3
 4[string length $s1]
 5[string index $s1 0]
 6[string range $s1 1 end]
 7append s1 …

星球大战万代模型

万代

Yoda

Yoda

General Grievous

General Grievous

C-3PO

C-3PO

BB-8 & D-O DIORAMA SET

BB-8 & D-O DIORAMA SET

K-2SO

K-2SO

Boba Fett

Boba Fett

Darth Vader

Darth Vader

Captain Phasma

Captain Phasma

Stormtrooper

Stormtrooper

Shoretrooper

Shoretrooper

Shadow Stormtrooper

Shadow Stormtrooper

First Order Stormtrooper

First Order Stormtrooper

Kylo Ren

Kylo Ren

Mandalorian

Mandalorian

Razor Crest

Razor Crest
Previous Page 2 of 2