Skip to content

[pull] master from parallel101:master #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions slides/design/detected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
```cpp
struct API {
bool is_device_ready(std::string dev_name);
void play_device(std::string dev_name);
void init_device(std::string dev_name);
};

if (api->is_device_ready("CD"))
api->play_device("CD");
else
api->init_device("CD");
```

```cpp
struct Device {
virtual bool is_ready() = 0;
virtual void play() = 0;
virtual void init() = 0;
};

struct API {
Device *get_device(std::string dev_name);
};

Device *dev = api->get_device("CD");
if (dev->is_ready())
dev->play();
else
dev->init();
```
1 change: 0 additions & 1 deletion slides/move/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct IndentGuard {
IndentGuard(IndentGuard &&) = delete;

~IndentGuard() {
puts("析构函数");
indent = oldIndent;
}

Expand Down
35 changes: 35 additions & 0 deletions slides/move/main_manualres.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <cstdio>
#include <cstdlib>
#include <memory>

using namespace std;

struct Resource {
void *p;

Resource() {
puts("分配资源");
p = malloc(1);
}

Resource(Resource &&that) : p(that.p) {
that.p = nullptr; // 一定要把对方置空!
}

Resource(Resource const &) = delete;

~Resource() {
if (p) {
puts("释放资源");
free(p);
}
}
};

void func(Resource x) {
}

int main() {
auto x = Resource();
func(std::move(x));
}
16 changes: 0 additions & 16 deletions slides/move/main_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@

using namespace std;

//struct Resource {
// void *p;
//
// Resource() {
// puts("分配资源");
// p = malloc(1);
// }
//
// Resource(Resource &&) = delete;
//
// ~Resource() {
// puts("释放资源");
// free(p);
// }
//};

struct Resource {
private:
struct Self {
Expand Down
11 changes: 11 additions & 0 deletions slides/stream/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.12)

set(CMAKE_CXX_STANDARD 23)

project(main)

set(SOURCES main.cpp)

add_executable(main ${SOURCES})
target_compile_options(main PRIVATE -Wall -Wextra)
target_link_libraries(main PRIVATE criterion)
Loading