Dive into C++14 - [3] - Generic 'unique resource' wrapper

preview_player
Показать описание

The third tutorial in the "Dive into C++14" series covers the implementation of a generic "unique resource" class, with the same ownership semantics as `std::unique_ptr`.

---

`std::unique_ptr` is not limited to pointer-like handles - by adapting other kinds of handles to the `NullablePointer` concept, it can still be used, as shown here:

Nevertheless, for educational purposes and to understand the commonalities between resource types and handle types, we're going to implement our own `std::unique_ptr`-like generic "unique wrapper".

---

The tutorial shows the implementation of the resource class and the abstraction of the behavior of several resource types (heap-allocated pointers, OpenGL VBOs, int-based-handle APIs).

It also shows a simple implementation of "scope guards" as unique resources, to show how abstracting "uniqueness semantics" can be useful even in unexpected situations.

All the code is available on GitHub. The code segments are thoroughly commented and can be read as a tutorial even without watching the video, if you prefer it that way :)

I am now on Patreon - your direct support would mean a lot to me and would help me spend more time working on my videos and my open-source projects.

---

Links in the video:

Рекомендации по теме
Комментарии
Автор

These videos must take an immense amount of time to produce, and its awesome of you to share them with us. This is an invaluable resource for the community. Thank you!

boriskourt
Автор

Hey uh vittrio Romeo there's a bug with open hexagon 1.92 and what it is that when ever I play a level it freezes the game and keeps resetting the level and when I press the start button it starts out normal but when I die it makes me use the mouse to reset back to normal and when I exit the level it's just normal I tryed to copy the the game by downloading copy's to fix it and adding all the stuff back but when I try it again with a copy it still doesn't work so please fix this bug please!!!!

northcorn
Автор

when I used unique_resource in derived class, I got the following:

error C2694: 'B::~B(void) noexcept(<expr>)': overriding virtual function has less restrictive exception specification than base class virtual member function 'A::~A(void)'

struct A{ virtual ~A(){} };
struct B : A{
unique_resource<int, decltype(&remove)> handle;
};

could you please tell me what is the problem? if I remove virtual dtor - everything is fine

NewLaconia
visit shbcf.ru