@@ -421,7 +421,7 @@ <h2 id="index-_1">前言</h2>
421
421
<blockquote>
422
422
<p><img src="../img/bulb.png" height="30px" width="auto" style="margin: 0; border: none"/> 本书还在持续更新中……要追番的话,可以在 <a href="https://github.com/parallel101/cppguidebook">GitHub</a> 点一下右上角的 “Watch” 按钮,每当小彭老师提交新 commit,GitHub 会向你发送一封电子邮件,提醒你小彭老师更新了。</p>
423
423
</blockquote>
424
- <p>更新时间:2024年10月26日 15:16:22 (UTC+08:00)</p>
424
+ <p>更新时间:2024年10月26日 15:20:27 (UTC+08:00)</p>
425
425
<p><a href="https://parallel101.github.io/cppguidebook">在 GitHub Pages 浏览本书</a> | <a href="https://142857.red/book">在小彭老师自己维护的镜像上浏览本书</a></p>
426
426
<h2 id="index-_2">格式约定</h2>
427
427
<blockquote>
@@ -2915,7 +2915,7 @@ <h3 id="lambda-_3">狂想:没有函数的世界?</h3>
2915
2915
<p>不仅完全没有可读性、可维护性,甚至都没有可移植性。</p>
2916
2916
<p>除非你只写应付导师的“一次性”程序,一旦要实现复杂的业务需求,不可避免的要自己封装函数或类。网上所有鼓吹“不封装”“设计模式是面子工程”的反智言论,都是没有做过大型项目的。</p>
2917
2917
<h3 id="lambda-_4">设计模式追求的是“可改”而不是“可读”!</h3>
2918
- <p>很多设计模式教材片面强调<strong>可读性</strong>,仿佛设计模式就是为了“优雅”“高大上”“美学”?使得很多人认为,“我这个是自己的项目,不用美化给领导看”而拒绝设计模式。实际上设计模式的主要价值在于<em >方便后续修改</em>* !</p>
2918
+ <p>很多设计模式教材片面强调<strong>可读性</strong>,仿佛设计模式就是为了“优雅”“高大上”“美学”?使得很多人认为,“我这个是自己的项目,不用美化给领导看”而拒绝设计模式。实际上设计模式的主要价值在于<strong >方便后续修改</strong> !</p>
2919
2919
<blockquote>
2920
2920
<p><img src="../img/awesomeface.png" height="30px" width="auto" style="margin: 0; border: none"/> 例如 B 站以前只支持上传普通视频,现在叔叔突然提出:要支持互动视频,充电视频,视频合集,还废除了视频分 p,还要支持上传短视频,竖屏开关等……每一个叔叔的要求,都需要大量程序员修改代码,无论涉及前端还是后端。</p>
2921
2921
</blockquote>
@@ -5298,7 +5298,7 @@ <h2 id="type_rich_api-_21">—</h2>
5298
5298
auto restSize = size - start;
5299
5299
if (length > restSize) // 如果长度超过上限,则自动截断
5300
5300
length = restSize;
5301
- return Span(data + start, restSize + length);
5301
+ return Span(data + start, length);
5302
5302
}
5303
5303
};
5304
5304
</code></pre>
@@ -5467,7 +5467,7 @@ <h2 id="type_rich_api-_28">—</h2>
5467
5467
<pre><code class="language-cpp">parseInt("233").value_or(0);
5468
5468
</code></pre>
5469
5469
<p>parseInt 内部实现可能如下:</p>
5470
- <pre><code class="language-cpp">std::optional<int> parseInt(std::string_view sv ) {
5470
+ <pre><code class="language-cpp">std::optional<int> parseInt(std::string_view str ) {
5471
5471
int value;
5472
5472
auto result = std::from_chars(str.data(), str.data() + str.size(), std::ref(value));
5473
5473
if (result.ec == std::errc())
@@ -6067,9 +6067,9 @@ <h2 id="type_rich_api-_63">—</h2>
6067
6067
6068
6068
FileHandle file_open(std::filesystem::path path, OpenMode mode) {
6069
6069
#ifdef _WIN32
6070
- return std::shared_ptr<FILE>(_wfopen(path.wstring().c_str(), modeLut.at(mode)), fclose);
6070
+ return std::shared_ptr<FILE>(_wfopen(path.wstring().c_str(), modeLut.at(mode).c_str() ), fclose);
6071
6071
#else
6072
- return std::shared_ptr<FILE>(fopen(path.string().c_str(), modeLut.at(mode)), fclose);
6072
+ return std::shared_ptr<FILE>(fopen(path.string().c_str(), modeLut.at(mode).c_str() ), fclose);
6073
6073
#endif
6074
6074
}
6075
6075
@@ -6083,7 +6083,7 @@ <h2 id="type_rich_api-_63">—</h2>
6083
6083
FileResult file_read(FileHandle file, std::span<T> elements) {
6084
6084
auto n = fread(elements.data(), sizeof(T), elements.size(), file.get());
6085
6085
return {
6086
- .numElements = n == 0 ? n : std::nullopt,
6086
+ .numElements = n == 0 ? std::optional(n) : std::nullopt,
6087
6087
.errorCode = std::errc(ferror(file.get())),
6088
6088
.isEndOfFile = (bool)feof(file.get()),
6089
6089
};
0 commit comments