0%

学习 locale 和编码转换过程中的关键以及问题。

  • 不使用 locale,无法完成编码转换吗?Unicode 自身的 utf-8/16/32 的 存储方式之间的转换 也不行吗?
  • utf-8 对应 charstring;utf-16 对应 wchar_t/wstring,这种理解对吗?所以 boost::locale::conv::to_utf<char>() 就是转 utf-8(而不是 utf-16/32)?boost::locale::conv::to_utf<wchar_t>() 就是转 utf-16 (或 utf-32)?
  • 本地化策略集 locale 和程序运行有关系吗? #139
  • C++17 为什么弃用了 <codecvt>?且 尚无替换方案 吗?
  • 都有哪些本地化策略可选呢?
  • 如果统一使用 Unicode 编码(utf-8/16/32 存储方式无所谓),是否就不需要本地化策略 locale了?它是源于上世纪各个国家、地区闭门造车,独自扩展 ANSI 字符集带来的后果吧?
  • C++11 - Convert to/from UTF-8/wchar_t 里面提到的 UTF8-CPP 和 NoWide 分别是什么?

没有一致的 locale name o(╥﹏╥)o,windows 编程时怎么写

Locale names are not part of the C++ standard… 引用来源

关联问题:

  1. What is the Windows equivalent for en_US.UTF-8 locale?
  2. How to change system locale in Windows 10
阅读全文 »

减少头文件的依赖。

Pimpl Idiom

《Effective C++》 条款31:将文件间的编译依存关系降至最低

《Effective Modern C++》 Item 22: When using the Pimpl Idiom, define special member functions in
the implementation file.

在其单例模式的基础上,使用 Interface class(工厂模式)而非 Handle class(Pimpl Idiom)更合适

参考 tnie/learn_xxx 中 coro 项目。

如果想看懂 asio 如何支持 co_await 的,想更细致地用好协程,就需要了解更基础(同时也是更复杂的)内容。

第一章

微软专家 C++ coroutines: Getting started with awaitable objects 开篇的陈述,比我的倾向更具说服力:

Coroutines were added to C++20, and Lewis Baker has a nice introduction to them.

特别推荐这几篇文章,作者写了 cppcoro 库,牛人!

首推,此系列的文章作为入门。

对协程介绍时,先介绍 awaitable/awaiterpromise。学习笔记/摘抄,见 coroutine-a~c.md

阅读全文 »

来源:https://lewissbaker.github.io/2018/09/05/understanding-the-promise-type

Coroutine Concepts

The compiler applies some fairly mechanical transformations to the code that you write to turn it into a state-machine that allows it to suspend execution at particular points within the function and then later resume execution.

编译器会对您编写的代码进行一些相当机械的转换,以将其转换为状态机,使状态机可以在函数内的特定点挂起执行,然后再恢复执行。

Promise objects

The Promise object defines and controls the behaviour of the coroutine itself by implementing methods that are called at specific points during execution of the coroutine.

阅读全文 »

来源:https://lewissbaker.github.io/2017/11/17/understanding-operator-co-await

What does the Coroutines TS give us?

The facilities the C++ Coroutines TS provides in the language can be thought of as a low-level assembly-language for coroutines. These facilities can be difficult to use directly in a safe way and are mainly intended to be used by library-writers to build higher-level abstractions that application developers can work with safely.

C ++ Coroutines TS 提供的功能可以被认为是协程的一种低级汇编语言。这些功能可能很难以安全的方式直接使用,并且主要旨在供库编写人员用来构建更高级的抽象,以便应用程序开发人员可以安全地使用它们。

Compiler <-> Library interaction

Instead, it specifies a general mechanism for library code to customise the behaviour of the coroutine by implementing types that conform to a specific interface. The compiler then generates code that calls methods on instances of types provided by the library.

它为库代码指定了一种通用机制,可通过 实现符合特定接口的类型 来自定义协程的行为。然后编译器调用 这些类型的方法 = 库提供的类型的实例的方法

There are two kinds of interfaces that are defined by the coroutines TS: The Promise interface and the Awaitable interface.

阅读全文 »

来源:https://lewissbaker.github.io/2017/09/25/coroutine-theory

Coroutines

Coroutines generalise the operations of a function by separating out some of the steps performed in the Call and Return operations into three extra operations: Suspend, Resume and Destroy.

比其他文章多描述了一个 Destroy 步骤,更准确。

Note that, like the Return operation of a function, a coroutine can only be suspended from within the coroutine itself at well-defined suspend-points.

请注意,就像函数的 Return 操作一样,协程只能在定义好的暂停点处从协程自身内部暂停。

Coroutine activation frames

With coroutines there are some parts of the activation frame that need to be preserved across coroutine suspension and there are some parts that only need to be kept around while the coroutine is executing. For example, the lifetime of a variable with a scope that does not span any coroutine suspend-points can potentially be stored on the stack.

阅读全文 »

来源:https://blog.panicsoftware.com/co_awaiting-coroutines/

Awaitable

As I have mentioned in the previous posts, the suspend_always and suspend_never are types, that fulfill the Awaitable concept.

We can get the Awaitable object in two ways:

  • Direct creation of Awaitable,
  • Transformation of the object into Awaitable because of await_transform function.

co_await operator and Awaiter

The co_await operator is actually responsible for two things:

  • Forcing compiler to generate some coroutine boilerplate code
  • Creating the Awaiter object.

So first let’s have a look at how is the awaiter object is created. The co_await operator is responsible for the creation of the awaiter object. The co_await operator declaration is looked upon in the awaitable object and if it’s found this co_await operator is executed to obtain awaiter object. Otherwise, if the appropriate function is not found, then awaitable becomes the awaiter.

阅读全文 »

来源:https://blog.panicsoftware.com/your-first-coroutine/

std::future<int> foo();

这是个普通函数,还是协程?这是由其具体实现决定的。

If any of those keywords occur in the function, then it becomes a coroutine.

  • co_await
  • co_return
  • co_yield

So the operator co_await is a unary operator, which takes the Awaitable object as its argument.

Why do we need to define additional types?

So the object used to communicate with the coroutine is the object of the coroutine’s return type.

我们使用协程的返回值,和协程进行沟通。

阅读全文 »

来源:https://blog.panicsoftware.com/coroutines-introduction/

虽然协程作为重要特性,即将进入 C++ 20,但仍然有很多人吐槽。

Main complaints were regarding the hardness to understand, lots of customisation points, and possibly not optimal performance due to possibly unoptimised dynamic memory allocations

主要的抱怨是关于理解起来很难,大量的定制点以及,未优化的动态内存分配可能造成性能的损失。

谷歌的提案存在一些问题,最终被接受的协程方案来自微软。

什么是协程

The coroutines already exist in many programming languages, may it be Python or C#. Coroutines provide one more way to create asynchronous code. How this way differs from threads and why do we need a dedicated language feature for coroutines and finally how we can benefit will be explained in this section.

阅读全文 »

TODO

  1. 蓝牙网络连接,什么作用?删掉或禁用有影响吗?
  2. 如何自动切换网关
  3. 将 共享目录从台式机移到笔记本中,使用网线已经没有带宽限制了。

装机

Windows预先安装环境(英语:Microsoft Windows Preinstallation Environment),简称 Windows PE 或 WinPE,是 Microsoft Windows 的轻量版本。

关于装机的知识,通过 微PE优盘使用说明书 可以学习,虽然我们并不购买他家的优盘。以下摘录部分笔记。

阅读全文 »