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: |

Following this, Sebi, in an order passed in January 2022, established that the administrators of a Telegram channel having a large subscriber base enticed the subscribers to act upon recommendations that were circulated by those administrators on the channel, leading to significant price and volume impact in various scrips. Channels are not fully encrypted, end-to-end. All communications on a Telegram channel can be seen by anyone on the channel and are also visible to Telegram. Telegram may be asked by a government to hand over the communications from a channel. Telegram has a history of standing up to Russian government requests for data, but how comfortable you are relying on that history to predict future behavior is up to you. Because Telegram has this data, it may also be stolen by hackers or leaked by an internal employee. Stocks dropped on Friday afternoon, as gains made earlier in the day on hopes for diplomatic progress between Russia and Ukraine turned to losses. Technology stocks were hit particularly hard by higher bond yields. It is unclear who runs the account, although Russia's official Ministry of Foreign Affairs Twitter account promoted the Telegram channel on Saturday and claimed it was operated by "a group of experts & journalists." At its heart, Telegram is little more than a messaging app like WhatsApp or Signal. But it also offers open channels that enable a single user, or a group of users, to communicate with large numbers in a method similar to a Twitter account. This has proven to be both a blessing and a curse for Telegram and its users, since these channels can be used for both good and ill. Right now, as Wired reports, the app is a key way for Ukrainians to receive updates from the government during the invasion.
from ru


Telegram Experimental chill
FROM American