Вот примеры.
Код: Выделить всё
#include
#include
#include
#include
//#define ACCEPT_UB
class CallCounter final {
public:
std::size_t num = constructor_calls;
CallCounter() { ++constructor_calls; }
~CallCounter() {
#ifdef ACCEPT_UB
++destructor_calls;
#endif
// useless
num = 0;
}
inline static size_t constructor_calls = 0;
inline static size_t destructor_calls = 0;
};
auto printResults(std::string_view description) {
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78667752/winking-out-with-stdmonotonic-buffer-resource-and-end-of-objects-lifetime[/url]