Custom Smart Pointer | C++ | Compiler Hacking

preview_player
Показать описание
Let's build a Smart Pointer! Our value type is always heap allocated, but if we had a Smart Pointer instead of a raw pointer, we could do some nifty magic and *sometimes* avoid a heap allocation, like in the case of integers.

About the Project: Natalie is a very early-stage work-in-progress Ruby implementation that compiles Ruby to an executable. It does so by transpiling Ruby to C++ and feeding it to gcc or clang to produce a binary.

#programming #compiler #smartpointer #pointer #heap
Рекомендации по теме
Комментарии
Автор

`operator Type()` is the way to define implicit conversion operators from some type to another, in this case operator bool means this function is how you convert this class to a bool (That's why you also don't need a return type :D).
You can make it explicit only by using `explicit` keyword, so `explicit operator bool()`, which will now only work with a cast.
You can even solve the val.value() thing with `operator Value **()` to make an implicit conversion to Value**

pushqrdx
Автор

Hi Tim! 6:25 Can this be a way to achieve that?
operator bool() const
{
return m_value != nullptr;
}

Автор

Oh man, I am late to find to find this channel

priyanshukumarpu
Автор

Thanks for these videos. They are really helpful.
By the way can you please make a video on your VIM setup?

gsniteesh
Автор

20:16 it magically works because you have a converting constructor from Value *

pushqrdx
Автор

if you build from vim you can automatically to jump to the errors

cunningham.s_law
join shbcf.ru