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

After fleeing Russia, the brothers founded Telegram as a way to communicate outside the Kremlin's orbit. They now run it from Dubai, and Pavel Durov says it has more than 500 million monthly active users. Perpetrators of such fraud use various marketing techniques to attract subscribers on their social media channels. 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. Overall, extreme levels of fear in the market seems to have morphed into something more resembling concern. For example, the Cboe Volatility Index fell from its 2022 peak of 36, which it hit Monday, to around 30 on Friday, a sign of easing tensions. Meanwhile, while the price of WTI crude oil slipped from Sunday’s multiyear high $130 of barrel to $109 a pop. Markets have been expecting heavy restrictions on Russian oil, some of which the U.S. has already imposed, and that would reduce the global supply and bring about even more burdensome inflation. In February 2014, the Ukrainian people ousted pro-Russian president Viktor Yanukovych, prompting Russia to invade and annex the Crimean peninsula. By the start of April, Pavel Durov had given his notice, with TechCrunch saying at the time that the CEO had resisted pressure to suppress pages criticizing the Russian government.
from ca


Telegram Experimental chill
FROM American