Telegram Group & Telegram Channel
В C++20 завезли destroying delete operator. Его основное отличие от обычного delete -- что при удалении через destroying delete вы сначала заходите в функцию, где сами должны вызвать деструктор

struct Foo {
~Foo() {
std::cout << "In Bar::~Bar()\n";
}

void operator delete(Foo* p, std::destroying_delete_t) {
std::cout << "In Foo::operator delete(Foo*, std::destroying_delete_t)\n";
p->~Foo();
::operator delete(p);
}
};


https://gcc.godbolt.org/z/zqd8Yn7ff

Из интересного, вы теперь можете сами писать свои vtable: https://gcc.godbolt.org/z/EYMn1sd1o

struct Vehicle {
const enum Types { CAR, TRUCK } type;
Vehicle(Types t) : type(t) {}
void operator delete(Vehicle*, std::destroying_delete_t);
};
// Implement Car, Truck

void Vehicle::operator delete(Vehicle *p, std::destroying_delete_t) {
switch (p->type) {
case CAR:
static_cast<Car*>(p)->~Car();
break;
case TRUCK:
static_cast<Truck*>(p)->~Truck();
break;
}
::operator delete(p);
}


Когда вы можете писать свои vtable, вы можете классы инициализировать через memset и тд, потому что вы убираете полную инициализацию.

Например, протобуфы. Все они наследуются от MessageLite, а теперь в кодогенерации можно свою vtable написать и инициализировать все поля быстро через mem*. До этого это было undefined behavior из-за нефиксированности имплементации vtable.

https://en.cppreference.com/w/cpp/memory/new/operator_delete. Cм 27-30.



group-telegram.com/experimentalchill/264
Create:
Last Update:

В C++20 завезли destroying delete operator. Его основное отличие от обычного delete -- что при удалении через destroying delete вы сначала заходите в функцию, где сами должны вызвать деструктор

struct Foo {
~Foo() {
std::cout << "In Bar::~Bar()\n";
}

void operator delete(Foo* p, std::destroying_delete_t) {
std::cout << "In Foo::operator delete(Foo*, std::destroying_delete_t)\n";
p->~Foo();
::operator delete(p);
}
};


https://gcc.godbolt.org/z/zqd8Yn7ff

Из интересного, вы теперь можете сами писать свои vtable: https://gcc.godbolt.org/z/EYMn1sd1o

struct Vehicle {
const enum Types { CAR, TRUCK } type;
Vehicle(Types t) : type(t) {}
void operator delete(Vehicle*, std::destroying_delete_t);
};
// Implement Car, Truck

void Vehicle::operator delete(Vehicle *p, std::destroying_delete_t) {
switch (p->type) {
case CAR:
static_cast<Car*>(p)->~Car();
break;
case TRUCK:
static_cast<Truck*>(p)->~Truck();
break;
}
::operator delete(p);
}


Когда вы можете писать свои vtable, вы можете классы инициализировать через memset и тд, потому что вы убираете полную инициализацию.

Например, протобуфы. Все они наследуются от MessageLite, а теперь в кодогенерации можно свою vtable написать и инициализировать все поля быстро через mem*. До этого это было undefined behavior из-за нефиксированности имплементации vtable.

https://en.cppreference.com/w/cpp/memory/new/operator_delete. Cм 27-30.

BY Experimental chill




Share with your friend now:
group-telegram.com/experimentalchill/264

View MORE
Open in Telegram


Telegram | DID YOU KNOW?

Date: |

"Your messages about the movement of the enemy through the official chatbot … bring new trophies every day," the government agency tweeted. Telegram has gained a reputation as the “secure” communications app in the post-Soviet states, but whenever you make choices about your digital security, it’s important to start by asking yourself, “What exactly am I securing? And who am I securing it from?” These questions should inform your decisions about whether you are using the right tool or platform for your digital security needs. Telegram is certainly not the most secure messaging app on the market right now. Its security model requires users to place a great deal of trust in Telegram’s ability to protect user data. For some users, this may be good enough for now. For others, it may be wiser to move to a different platform for certain kinds of high-risk communications. But because group chats and the channel features are not end-to-end encrypted, Galperin said user privacy is potentially under threat. WhatsApp, a rival messaging platform, introduced some measures to counter disinformation when Covid-19 was first sweeping the world. Under the Sebi Act, the regulator has the power to carry out search and seizure of books, registers, documents including electronics and digital devices from any person associated with the securities market.
from jp


Telegram Experimental chill
FROM American